sobota 13. února 2021

STM32 CubeIDE and CMSIS bare metal project - upgrade 2021

 Upgraded my previous post - extended to more ST microcontrollers

  • Tested on STM32 CubeIDE 1.5.3
  • Targets
    • STM32F411RE (Nucleo64)
    • STM32F103RB (own board, same as Nucleo64)
    • STM32F429ZI (Nucleo144)
    • STM32WB55xx (P-Nucleo)
    • or any supported STM32 ...
Steps

  • Install and run STM32 CubeIDE
  • Create new project – select STM32 Project (from menu File or right-click in Project Explorer
    • Or from link in "new workspace"
  • In MCU/MPU selector type "shortcut" or search in List
    • “f411” and select STM32F411RE
    • "f103rb" and select STM32F103RBTx (that one with Nucleo in list)
    • "wb55" and select STM32WB55CGUx (line with P-Nucleo and VQFN68)
    • "f429zi" and select STM32F429ZITx (package LQFP144)
    • etc.
  • Enter Project Name and select radio-button Empty in Targeted Project Type
  • CubeIDE creates default file-structure “empty” project
    • Differences may be in filename "startup_stm32xxx.s" and "STM32xxx.ld"
  • Simplify files structure – remove file …RAM.ld (if there is any), move file startup….s to Src folder and remove Startup folder
  • Create a ”New Source Folder” named “CMSIS” in the project tree – at the same level as Src folder
  • Find a place, where is Repository of CubeIDE – see menu Window/Preferences item STM32Cube/FirmwareUpdater
  • Search the directory from preferences dialog and there must be at least one folder
    • STM32Cube_FW_F1_Vx.xx.x for F103
    • STM32Cube_FW_F4_Vx.xx.x for F411 and F429
    • STM32Cube_FW_WB_Vx.xx.x for WB55
    • etc.
  • If it’s not there, you've never created a “Fx Cube” project and you have to do it at least once or simpler alternative – menu Help / Manage embedded software packages and install last repo for requested STM32 family - see my base post
  • Now copy files (drag-drop etc.) from repository folder STM32Cube_FW_Fx_Vx.xx.x (select last installed version) to project - into our CMSIS folder:
    • Drivers\CMSIS\Include\cmsis_compiler.h
    • Drivers\CMSIS\Include\cmsis_gcc.h
    • Drivers\CMSIS\Include\cmsis_version.h
    • header with "core" data - it depends on core - CortexM3 or M4 (or maybe CM0, CM7, ...)
      • Drivers\CMSIS\Include\core_cm4.h ... for STM32F411, F429 (F4x)
      • Drivers\CMSIS\Include\core_cm4.h ... for STM32WB55 (WBx, WLx, ...)
      • Drivers\CMSIS\Include\core_cm3.h ... for STM32F103 (F1x)
    • Drivers\CMSIS\Include\mpu_armv7.h
    • common header for family
      • Drivers\CMSIS\Device\ST\STM32F4xx\Include\stmf4xx.h ... F411, F429
      • Drivers\CMSIS\Device\ST\STM32WBxx\Include\stm32wbxx.h ... WB55
      • Drivers\CMSIS\Device\ST\STM32F1xx\Include\stmf1xx.h ... F103
    • specific file for concrete microcontroller type
      • Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f411xe.h ... F411RE
      • Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f429xx.h ... F429ZI
      • Drivers\CMSIS\Device\ST\STM32WBxx\Include\stm32wb55xx.h ... WB55xx
      • Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f103xb.h ... F103RB
    • common code headers for family
      • Drivers\CMSIS\Device\ST\STM32F4xx\Include\system_stm32f4xx.h ... F4x
      • Drivers\CMSIS\Device\ST\STM32WBxx\Include\system_stm32wbxx.h ... WBx
      • Drivers\CMSIS\Device\ST\STM32F1xx\Include\system_stm32f1xx.h ... F1x
    • common code (functions) for family
      • Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c
      • Drivers\CMSIS\Device\ST\STM32WBxx\Source\Templates\system_stm32wbxx.c
      • Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c
  • Folder tree looks like this:
    • For F411
    • For F429
    • For WB55
  • OK, files are located in their folders, now we must be update “project settings”
    • Right click on project and last menu-item “Properties” or menu Project or …
    • Item C/C++ General / Path and Symbols / tab Includes … add path to CMSIS folder – there are our new header files (and check “For all configurations”)
  • Next, if wee created CMSIS folder as “Source folder”, item in tab Source location is filled
    • If not, add CMSIS folder to “Source folders”
  • Add primary include to beginning of main.c file - differs on microcontroller family
    • #include <stm32f4xx.h>    // F411 and F429
    • #include <stm32wbxx.h>  // WB55
    • #include <stm32f1xx.h>    // F103
  • ... and you will receive error (not just one) after compilation (e.g. Build):
    • “Please select first the target STM32F4xx device used in your application (in stm32f4xx.h file)”
    • ... or F1xx or WBxx
  • OK, we know what we use - copy specific symbol from header file:
    • F411 ... STM32F411xE from line 154 in file stm32f4xx.h 
    • F429 ... STM32F429xx from line 140 in file stm32f4xx.h 
    • WB55 ... STM32WB55xx from line 88 in file stm32wbxx.h
    • F103 ... STM32F103xB from line 130 in file stm32f1xx.h
  • ... and add to symbols in project
    • Project/Properties C/C++ Build/Settings – tab Tool Settings – item MCU GCC Compiler/Preprocesor
    • Add our symbol
    • Remove ambiguous symbol STM32F411RETx (or STM32F429ZITx or ...)
  • Now program can be compiled with only one warning about FPU, but “FPU things” solves function SystemInit in source file system_stm32...xx.c, so we can remove preprocessor lines from the file main.c
  • Try simple LED blinking code and it works !!