Global Sources
EE Times-India
Stay in touch with EE Times India
EE Times-India > Interface

Guide to Cortex MCU Software Interface Standard (Part 2)

Posted: 06 Mar 2015     Print Version  Bookmark and Share

Keywords:Cortex-M  processor  microcontrollers  embedded systems  motor control 

To read Part 1 of this series, click here.

System Code
The reset handler calls the SystemInit() function, which is located in the CMSIS system device.c file. This code is delivered by the silicon manufacturer and it provides all the necessary code to configure the microcontroller out of reset. Typically this includes setting up the internal phase-locked loops, configuring the microcontroller clock tree and internal bus structure, enabling the external bus if required, and switching on any peripherals held in low-power mode.

The configuration of the initializing functions is controlled by a set of #defines located at the start of the module. This allows you to customise the basic configuration of the microcontroller system peripherals. Since the SystemInit() function is run when the microcontroller leaves reset the microcontroller and the Cortex-M processor will be in a running state when the program reaches main. In the past, this initializing code was something you would have had to write for yourself or crib from example code. The SystemInit() function does save you a lot of time and effort.

The SystemInit() function also sets the CMSIS global variable SystemCoreClock to the CPU frequency. This variable can then be used by the application code as a reference value when configuring the microcontroller peripherals. In addition to the SystemInit() function the CMSIS system file contains an additional function to update the SystemCoreClock variable if the CPU clock frequency is changed on the fly.

The function SystemCoreClockUpdate() is a void function that must be called if the CPU clock frequency is changed. This function is tailored to each microcontroller and will evaluate the clock tree registers to calculate the new CPU operating frequency and change the SystemCoreClock variable accordingly. Once the SystemInit() function has run and we reach the application code we will need to access the CMSIS core functions. This framework is added to the application modules through the microcontroller-specific header file.

Device Header File
The header file first defines all of the microcontroller special function registers in a CMSIS standard format. A typedef structure is defined for each group of special function registers on the supported microcontroller. In the code below, a general GPIO typedef is declared for the group of GPIO reregisters. This is a standard typedef but we are using the IO qualifiers to designate the type of access granted to a given register.

__IOuint32_t MODER;
   /*!< GPIOportmoderegister, Addressoffset:0x00 */
__IOuint32_t OTYPER;
   /*!< GPIOportoutput typeregister, Addressoffset:0x04*/
__IOuint32_t OSPEEDR;
   /*!< GPIOportoutput speedregister, Addressoffset:0x08*/
   /*!< GPIOportpull-up/pull-downregister, Addressoffset:0x0C*/
__IOuint32_t IDR;
   /*!< GPIOportinput dataregister, Addressoffset:0x10*/
__IOuint32_t ODR;
   /*!< GPIOportoutput dataregister, Addressoffset:0x14*/
   /*!< GPIOportbitset/resetlowregister, Addressoffset:0x18*/
__IO uint16_tBSRRH;
   /*!< GPIO port bit set/reset high register, Addressoffset: 0x1A */
   /*!< GPIOportconfigurationlockregister, Addressoffset:0x1C*/
__IO uint32_t AFR[2];
   /*!< GPIO alternate function registers, Addressoffset:0x24-0x28 */

1 • 2 • 3 • 4 • 5 Next Page Last Page

Comment on "Guide to Cortex MCU Software Interfa..."
*  You can enter [0] more charecters.
*Verify code:


Visit Asia Webinars to learn about the latest in technology and get practical design tips.


Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

Back to Top