Support for CMSIS

Note: Version 4 (and later) of the Code Red IDE provides additional CMSIS related support. For more details please see the following FAQs:

Background on CMSIS

CMSIS, the Cortex Microcontroller Software Interface Standard - as defined by ARM, defines for a Cortex-M Microcontroller System:

By using CMSIS compliant software components, the user can more easily re-use template code. CMSIS is intended to enable the combination of software components from multiple middleware vendors.

Note that CMSIS is focussed on Cortex-M based MCUs. It does not support ARM7 or ARM9 based MCUs. More information on CMSIS plus the full CMSIS releases can be found at:

Code Red CMSIS Library Projects

Within the examples subdirectory of your Code Red tools installation, for Cortex-M based MCU's, you will find CMSIS library projects. Each of these CMSIS library projects contain the CMSIS header files and source code for a specific MCU family.

You can also download the latest versions of these library projects from:

These CMSIS library projects will have a name in the form "CMSIS<version>_<MCUfamily>". For example the CMSIS 1.30 library projects for the NXP LPC17xx and LPC13xx MCU families are "CMSISv1p30_LPC17xx" and "CMSISv1p30_LPC13xx". Each of the libraries contains the CMSIS sources appropriate for that MCU family, plus the CMSIS documentation.

Note that these libraries do NOT provide actual driver code for the peripherals on the MCU. Peripheral drivers will be provided through example code or peripheral driver libraries, typically provided by the MCU vendor. Some example code and driver libraries do have the word CMSIS in their titles though, which sometimes causes confusion. This simply refers to the fact that the code has been written to use the CMSIS way of accessing the peripherals. Typically this has been done because earler versions of the code used pre-CMSIS header files (this particularly applies to NXP's LPC17xx).

A summary of the source files within the library is as follows...

ARM supplied files

core_cm3.c / core_cm3.h or core_cm0.c / core_cm0.h

These file contain the names, definitions, and helper functions to access the core registers, and core peripherals of the Cortex-Mx CPU, like functions for setting up the NVIC (Nested Vector Interrupt controller), Systick timer etc. These files are common for any Cortex-M3 or Cortex-M0 based MCU and are documented in the ARM supplied CMSIS documentation.

Device specific, silicon vendor supplied files

<mcu>.h, for example LPC17xx.h

This file contains the data structures, register memory addresses, and defines for a specific MCU family - such as the LPC17xx. Definitions for peripherals like UART, GPIO, TIMERS, etc are all in here, but for detailed information on these peripherals you will typically need to refer to the MCU user manual.

system_<mcu>.h / system_<mcu>.c, for example system_LPC17xx.h / system_LPC17xx.c

These files contain the prototypes/implementations for the SystemInit() and SystemCoreClockUpdate(). CMSIS requires these two functions to be provided by the silicon vendor, as on chip peripherals (Clock setup, PLL setup, etc) will differ from MCU to MCU. For the actual details of the MCU setup, you should read the code supplied in these files in conjunction with the MCU user manual. Note that the SystemInit() is then called from the startup code generated by the Code Red IDE project wizard (when CMSIS support is requested by the user from within the wizard).

Project Wizard Support

The Code Red IDE project wizard provides built in support for creating projects that make use of these CMSIS library projects. After giving your new project a name, where built-in support for CMSIS is available, the next screen will prompt you to select whether the project you are creating should use the built in CMSIS support, and if so which CMSIS library you wish to use.

Generally in Code Red IDE version 3.x the only selection possible is CMSIS 1.30 for the MCU family you are using. In Code Red IDE version 4.x, CMSIS 1.3 and 2.0 are available for most MCU families (though those MCU families which have only recently been added into the Code RED IDE may only be available as CMSIS 2.0).

After making your CMSIS choices, the rest of the project wizard then allows you create startup files, select the build configurations to be created, and finally select the actual target MCU.

What does the Project Wizard actually do?

When you choose to create a CMSIS-based project, the wizard will make a number of modifications to (all build configurations of) the project that it creates:

  1. It will define the symbol __USE_CMSIS. This existence of the symbol is checked by Code Red's standard MCU startup code to determine whether to call the CMSIS system initialization function. You can also use it in your own sources to determine whether other CMSIS functionality can be used.

  2. It will create include paths for your project to a CMSIS library project specific for the MCU family you are using.
  3. It will also add the appropriate CMSIS library to the project's link step, allowing appropriate CMSIS library code to be linked in to your application executable.

The appropriate CMSIS library project must exist in the workspace your new project is being created in. The CMSIS library project may already exist in the workspace if you have imported appropriate example projects. But if not, you can import the appropriate library project into your workspace using the "Import Example project(s)" entry of the IDE's Quickstart Panel, and selecting the appropriately named CMSIS zip example file.

Note that when you create a new CMSIS using project, if the appropriate CMSIS library does not exist in the workspace, you will get an error message and the project will not be created. Simply import the appropriate CMSIS project from the examples directory and try again. [Note that older versions of the IDE would give a project dependency warning as the wizard creates your project, informing you that your project will not build. However once you have imported the appropriate CMSIS library project, your own project would then build correctly.]

Manually linking to the CMSIS library project

If you create a new project without enabling CMSIS support in the new project wizard, then you can manually create all the necessary links to the appropriate CMSIS library project. Details of how to do this can be found in the FAQ Using library projects from your own projects.

You will also need to define the symbol __USE_CMSIS in project properties. Normally you should set this symbol to the name of the CMSIS library being used. Thus if you are linking with the CMSIS 1.30 CMSIS library you would add __USE_CMSIS=CMSISv1p30_LPC17xx in the symbols pane of project properties. The existence of this symbol is checked by Code Red's standard MCU startup code to determine whether to call the CMSIS system initialization function. You can also use it in your own sources to determine whether other CMSIS functionality can be used.

Using CMSIS functionality

One thing that CMSIS provides is a set of headers defining the peripheral set of the MCU family that you are using. For example, the following code taken from an LPC1768 example enables the A/D converter

    #include "LPC17xx.h"

    // PCADC / PCAD
    #define ADC_POWERON (1 << 12)

    #define PCLK_ADC 24
    #define PCLK_ADC_MASK (3 << 24)

    // AD0.0 - P0.23, PINSEL1 [15:14] = 01
    #define SELECT_ADC0 (0x1<<14)
    // Turn on power to ADC block

    // Turn on ADC peripheral clock
    LPC_SC->PCLKSEL0 |=  (3 << PCLK_ADC);

    // Set P0.23 to AD0.0 in PINSEL1

It also provides access to functionality contained within the Cortex-M processor core. For example, the below code snippet enables the SysTick timer built into the Cortex-M3 used by the LPC17xx and LPC13xx.

    // Setup SysTick Timer to interrupt at 1 msec intervals
    if (SysTick_Config(SystemCoreClock / 1000)) {
       while (1);  // Capture error

For more information and example code, please see the examples provided with the tools suite, together with the CMSIS documentation contained within the CMSIS library projects (in Code Red IDE v3.x) or within the product documentation to be found via Help -> Help Contents -> Code Red Product Documentation -> CMSIS (in Code Red IDE v4.0 and later).

Support4CMSIS (last edited 2013-03-10 10:45:35 by CrSupportAb)