STM32F4xx - Cerberus Helper Classes

Hi All,

I have converted the file: ‘stm32f4xx.h’ to C# as a helper class. Its too big to run in Application so portions may be used separately.

See Codeshare for full code: https://www.ghielectronics.com/community/codeshare/entry/919 ← Updated…

Just a small snippet: as this is a huge file!!!

Very simple to use:


GPIO.GPIOA.MODER_Register.SetBits(3 << 8);

    
    /// <summary>
    /// General-purpose I/Os (GPIO) - See: P.265
    /// </summary>
    public sealed class GPIO
    {
        #region Private's...

        private UInt32 _MODER = 0x00;
        private UInt32 _OTYPER = 0x04;
        private UInt32 _OSPEEDR = 0x08;
        private UInt32 _PUPDR = 0x0C;
        private UInt32 _IDR = 0x10;
        private UInt32 _ODR = 0x14;
        private UInt32 _BSRRL = 0x18;
        private UInt32 _BSRRH = 0x1A;
        private UInt32 _LCKR = 0x1C;

        // Alternate Function Number 
        private UInt32[] AFR = new UInt32[] { 0x12, 0x12, 0x22, 0x22, 0x22, 0, 0, 0x32, 0x32, 0x32, 0x32, 0x92, 0x92, 0x92 }; // AF1/2/3/9}

        #endregion

        #region Properties...

        /// <summary>
        /// GPIO port mode register, Address offset: 0x00
        /// </summary>
        public UInt32 MODER { get { return _MODER; } set { _MODER = value; } }

        /// <summary>
        /// GPIO port output type register, Address offset: 0x04
        /// </summary>
        public UInt32 OTYPER { get { return _OTYPER; } set { _OTYPER = value; } }

        /// <summary>
        /// GPIO port output speed register, Address offset: 0x08
        /// </summary>
        public UInt32 OSPEEDR { get { return _OSPEEDR; } set { _OSPEEDR = value; } }

        /// <summary>
        /// GPIO port pull-up/pull-down register, Address offset: 0x0C
        /// </summary>
        public UInt32 PUPDR { get { return _PUPDR; } set { _PUPDR = value; } }

        /// <summary>
        /// GPIO port input data register, Address offset: 0x10 
        /// </summary>
        public UInt32 IDR { get { return _IDR; } set { _IDR = value; } }

        /// <summary>
        /// GPIO port output data register, Address offset: 0x14
        /// </summary>
        public UInt32 ODR { get { return _ODR; } set { _ODR = value; } }

        /// <summary>
        /// GPIO port bit set/reset low register, Address offset: 0x18
        /// </summary>
        public UInt32 BSRRL { get { return _BSRRL; } set { _BSRRL = value; } }

        /// <summary>
        /// GPIO port bit set/reset high register, Address offset: 0x1A
        /// </summary>
        public UInt32 BSRRH { get { return _BSRRH; } set { _BSRRH = value; } }

        /// <summary>
        /// GPIO port configuration lock register, Address offset: 0x1C
        /// </summary>
        public UInt32 LCKR { get { return _LCKR; } set { _LCKR = value; } }

        /// <summary>
        /// GPIO alternate function registers, Address offset: 0x20-0x24
        /// </summary>
        // public UInt32 AFR { get { return _AFR; } set { _AFR = value; } }    

        #endregion

        #region Registers...

        /// <summary>
        /// GPIO port mode register, Address offset: 0x00
        /// </summary>
        public Register MODER_Register;

        /// <summary>
        /// GPIO port output type register, Address offset: 0x04
        /// </summary>
        public Register OTYPER_Register;

        /// <summary>
        /// GPIO port output speed register, Address offset: 0x08
        /// </summary>
        public Register OSPEEDR_Register;

        /// <summary>
        /// GPIO port pull-up/pull-down register, Address offset: 0x0C
        /// </summary>
        public Register PUPDR_Register;

        /// <summary>
        /// GPIO port input data register, Address offset: 0x10 
        /// </summary>
        public Register IDR_Register;

        /// <summary>
        /// GPIO port output data register, Address offset: 0x14
        /// </summary>
        public Register ODR_Register;

        /// <summary>
        /// GPIO port bit set/reset low register, Address offset: 0x18
        /// </summary>
        public Register BSRRL_Register;

        /// <summary>
        /// GPIO port bit set/reset high register, Address offset: 0x1A
        /// </summary>
        public Register BSRRH_Register;

        /// <summary>
        /// GPIO port configuration lock register, Address offset: 0x1C
        /// </summary>
        public Register LCKR_Register;

        /// <summary>
        /// GPIO alternate function registers, Address offset: 0x20-0x24
        /// </summary>
        // public Register AFR[2];    

        #endregion

        /// <summary>
        /// GPIOA. Class Type for defining the GPIOA Register Types...
        /// </summary>
        public static GPIO GPIOA = new GPIO(STM32F4xx.GPIOA_BASE);

        /// <summary>
        /// GPIOB. Class Type for defining the GPIOB Register Types...
        /// </summary>
        public static GPIO GPIOB = new GPIO(STM32F4xx.GPIOB_BASE);

        public GPIO(UInt32 GPIOx_BASE)
        {
            MODER_Register = new Register(GPIOx_BASE + MODER);
            OTYPER_Register = new Register(GPIOx_BASE + OTYPER);
            OSPEEDR_Register = new Register(GPIOx_BASE + OSPEEDR);
            PUPDR_Register = new Register(GPIOx_BASE + PUPDR);
            IDR_Register = new Register(GPIOx_BASE + IDR);
            ODR_Register = new Register(GPIOx_BASE + ODR);
            BSRRL_Register = new Register(GPIOx_BASE + BSRRL);
            BSRRH_Register = new Register(GPIOx_BASE + BSRRH);
            LCKR_Register = new Register(GPIOx_BASE + LCKR);
        }
    } // END of Class...

See Codeshare for full code: https://www.ghielectronics.com/community/codeshare/entry/919 ← Updated…

All the best

Chris

4 Likes

It is indeed huge :slight_smile: Consider splitting to smaller files — my Firefox dies trying to open that Codeshare entry!..

Yeah I had similar problems… Mind you, 886Kb isn’t that much…

New codeshare link: https://www.ghielectronics.com/community/codeshare/entry/919

All the best

Chris

That’s good, sorry, thought it was a site issue and not so much a size issue.

Glad you can get to it now.

All the best

Chris

I have made some revisions to the Code and updated a few minor items.

See: https://www.ghielectronics.com/community/codeshare/entry/919

Changes:
[ul]I2c and USART completed Class Code.
Added GPIOC, D, E, F, G, H and I.[/ul]

I am in the process of using this file in my Windows application and sending the Address’s and bit procedures through serial interface so I will post application soon.

All the best

Chris