Creating a CMSIS project

 

Maybe you have grown weary of learning a new IDE every time you buy a new ARM microcontroller board. It gets tiresome and breaks your thought process when you are forced to learn a new IDE every time you buy a new robot toy. You possibly feel like you can't get new projects at consulting gigs because you don't know enough IDE's. CMSIS is great. It is embedded device platform independent.

In this write-up I'll attempt to demystify setting up a CMSIS project.

Here is a nice picture of the basic CMSIS file structure from Keil's website. What you see is that CMSIS-CORE and the silicon vendor will jointly provide you with four device specific files. Your program will provide an application file, and additionally CMSIS-CORE will provide two more standard files.

CMSIS

Above are the important files you'll need for your project. Include a linker (LD) file, and a Makefile to the project and you'll be almost done.

Below is an example of an STMicroelectronics project that I've been analyzing. Note that in this project there is no make file and no linker script. We'll discuss this more later.

L452-LED

├── Drivers
│   ├── CMSIS
│   │   ├── Device
│   │   │   └── ST
│   │   │       └── STM32L4xx
│   │   │           ├── Include
│   │   │           │   ├── stm32l452xx.h
│   │   │           │   ├── stm32l4xx.h
│   │   │           │   └── system_stm32l4xx.h
│   │   │           └── Source
│   │   │               └── Templates
│   │   └── Include
│   │       ├── arm_common_tables.h
│   │       ├── arm_const_structs.h
│   │       ├── arm_math.h
│   │       ├── cmsis_armcc.h
│   │       ├── cmsis_armcc_V6.h
│   │       ├── cmsis_gcc.h
│   │       ├── core_cm0.h
│   │       ├── core_cm0plus.h
│   │       ├── core_cm3.h
│   │       ├── core_cm4.h
│   │       ├── core_cm7.h
│   │       ├── core_cmFunc.h
│   │       ├── core_cmInstr.h
│   │       ├── core_cmSimd.h
│   │       ├── core_sc000.h
│   │       └── core_sc300.h
│   └── STM32L4xx_HAL_Driver
│       ├── Inc
│       │   ├── Legacy
│       │   │   └── stm32_hal_legacy.h
│       │   ├── stm32l4xx_hal_cortex.h
│       │   ├── stm32l4xx_hal_def.h
│       │   ├── stm32l4xx_hal_dma_ex.h
│       │   ├── stm32l4xx_hal_dma.h
│       │   ├── stm32l4xx_hal_flash_ex.h
│       │   ├── stm32l4xx_hal_flash.h
│       │   ├── stm32l4xx_hal_flash_ramfunc.h
│       │   ├── stm32l4xx_hal_gpio_ex.h
│       │   ├── stm32l4xx_hal_gpio.h
│       │   ├── stm32l4xx_hal.h
│       │   ├── stm32l4xx_hal_i2c_ex.h
│       │   ├── stm32l4xx_hal_i2c.h
│       │   ├── stm32l4xx_hal_pwr_ex.h
│       │   ├── stm32l4xx_hal_pwr.h
│       │   ├── stm32l4xx_hal_rcc_ex.h
│       │   ├── stm32l4xx_hal_rcc.h
│       │   ├── stm32l4xx_hal_tim_ex.h
│       │   └── stm32l4xx_hal_tim.h
│       └── Src
│           ├── stm32l4xx_hal.c
│           ├── stm32l4xx_hal_cortex.c
│           ├── stm32l4xx_hal_dma.c
│           ├── stm32l4xx_hal_dma_ex.c
│           ├── stm32l4xx_hal_flash.c
│           ├── stm32l4xx_hal_flash_ex.c
│           ├── stm32l4xx_hal_flash_ramfunc.c
│           ├── stm32l4xx_hal_gpio.c
│           ├── stm32l4xx_hal_i2c.c
│           ├── stm32l4xx_hal_i2c_ex.c
│           ├── stm32l4xx_hal_pwr.c
│           ├── stm32l4xx_hal_pwr_ex.c
│           ├── stm32l4xx_hal_rcc.c
│           ├── stm32l4xx_hal_rcc_ex.c
│           ├── stm32l4xx_hal_tim.c
│           └── stm32l4xx_hal_tim_ex.c
├── Inc
│   ├── main.h
│   ├── stm32l4xx_hal_conf.h
│   └── stm32l4xx_it.h
├── L452-LED.ioc
├── L452-LED Run.cfg
├── L452-LED.xml
├── Src
│   ├── main.c
│   ├── stm32l4xx_hal_msp.c
│   ├── stm32l4xx_it.c
│   └── system_stm32l4xx.c
├── startup
│   └── startup_stm32l452xx.s
├── STM32L452RETx_FLASH.ld
└── syscalls.c

From this long list I see a couple files that are needed.

L452-LED

├── Src
│   ├── main.c
│   └── system_stm32l4xx.c

├── startup
│   └── startup_stm32l452xx.s

│   │   └── Include
│   │       ├── arm_common_tables.h
│   │       ├── arm_const_structs.h
│   │       ├── arm_math.h
│   │       ├── cmsis_armcc.h
│   │       ├── cmsis_armcc_V6.h
│   │       ├── cmsis_gcc.h
│   │       ├── core_cm4.h
│   │       ├── core_cmFunc.h
│   │       ├── core_cmInstr.h
│   │       ├── core_cmSimd.h
│   │       ├── core_sc000.h
│   │       └── core_sc300.h
 

L452-LED

├── Drivers
│   ├── CMSIS
│   │   ├── Device
│   │   │   └── ST
│   │   │       └── STM32L4xx
│   │   │           ├── Include
│   │   │           │   ├── stm32l452xx.h
│   │   │           │   ├── stm32l4xx.h
│   │   │           │   └── system_stm32l4xx.h
 

I've deleted some files from the first list that are not be needed but included regardless by the STMicroelectronics software. What is desired here is a folder containing only necessary code. This consist of the files mentioned at the top of this post and additionally a makefile, a linker file and also only containing the necessary files.