Search code examples
cheader-filesstm32cmsistruestudio

How to include the CMSIS-DSP headers in Atollic TrueStudio


I am trying to implement the use of DSP in the STM32 F411RE board, but I cannot seem to include the necessary files without invoking numerous errors.

Background

I have previously had CMSIS and CMSIS-DSP working in Keil uVision, but given the code limit of 32k that puts me over the evaluation limit rather quickly. As such I have been attempting to include CMSIS-DSP into Atollic TrueStudio but this seemingly is difficult to accomplish: there is limited documentation available on the CMSIS-DSP to begin with and even less so for implementation in Atollic TrueStudio.

Some related resources can be found in the Atollic TrueStudio User Guide as well as StackOverflow topic #1 and StackOverflow topic #2 . Most other related topics I could find just refer to the use of Keil uVision or the User Guide without much further help.

Atollic TrueStudio does incorporate a in-built package manager where the base CMSIS is available for download, but it does not provide this option for the CMSIS-DSP pack.

Attempted solution

I have attempted to manually download the corresponding CMSIS package (STM32Cube_FW_F4_V1.24.0) and place the corresponding DSP package into the project file structure. This then permits the use of the DSP functions such as #include arm_math.h or arm_rfft_fast_instance_f32 S; which can also be invoked with the use of the autocomplete functionality and as such are thus recognized by the IDE.

However, this process also invokes many errors as the included functions fail to recognize their header dependencies (such as the #include arm_math.h). I find it confusing that the main.c is able to recognize the #include arm_math.h command yet the functions included are not, but I nevertheless try to fix this by adding the CMSIS DSP to the included directories (found at 'Build properties --> C/C++ Build --> Settings --> Tool Settings --> C Compiler --> Directories`). However, this does also not remedy the issue at hand.

Code results

The function cannot find the header

Function cannot find the header

However the main can find the exact same header

Main.c can find the header however

And the header is included in the build options -> directories

Build options, includes the DSP header

Just verified that it is also included in the 'path and symbols', which it should do automagically AFAIK once you include it in the build options:

Path and symbols

Update

Since my OP I have made some progress, mostly via messing around with the includes, symbols and linker. I have now managed to defeat the original error (though unfortunately I have no idea how), but I have now incurred a large amount of additional errors for the startup_stm32 files.

These all appear to be bad instruction errors referring to the template files included in CMSIS (CMSIS / Device / ST / STM32F4xx / Source / Templates / ARM / ...), which somehow cannot interpret the various commands listed in these templates.

Example errors: bad instruction __heap_base


Solution

  • I have since figured out the issue for my project: including the CMSIS folder as available from the Github repo means that a lot of templates are present throughout the entire folder structure. When attempting to build / compile whilst these templates are still present it causes a lot of issues with invalidated types and re-defining errors.

    Most of these templates are in a logical location, but some are buried quite deep down and may thus be difficult to find. I will try to make a video soon describing the process of adding CMSIS (DSP) from the github repo to your project in TrueStudio.

    In the meantime, the following steps should make CMSIS and CMSIS-DSP work in your STM32 TrueStudio ProjecT:

    1. Ensure that all templates (folders) are removed from the CMSIS folder. This may require some searching and experimenting: the particularly noxious ones are hidden in ../STM32Cube_FW_xx_Vx.xx/Drivers/CMSIS/Device/ST/STM32xxxx/Source/{Templates} whilst there are also other sets at ../STM32Cube_FW_xx_Vx.xx/Drivers/CMSIS/DSP/{Examples} and ../STM32Cube_FW_xx_Vx.xx/Drivers/CMSIS/DSP/{Projects} that I had removed for my project to compile / build succesfully.

    2. Include all the folders that are named include in the folders. AFAIK you cannot just include the main ../Drivers folder, as includes do not appear to also include the underlying structure and it also seems to include errors for my project. Best to just include the folders manually: you can so so by right-clicking on the intended folder to include, click the option near the bottom "Add/Remove include path" and tick both boxes for release and debug before pressing 'OK' to include this folder. Repeat for the other 'include' folders.

    3. Fish up the RTE_Components.h file located at ../STM32Cube_FW_xx_Vx/STM32xxxx-Nucleo\Templates\MDK-ARM\RTE. There are also files with this name (RTE_Components.h) available in the NN (Neural Networks) CMSIS-pack folder, do not touch those. Copy this file to any location that you have previously included (placed mine in ../Drivers/CMSIS/Include), and open it up in your IDE of choice. Add the line #define CMSIS_device_header " DEVICE_NAME.h " before any of the other statements and replace device name with your STM32 board name. For example, my RTE_Components.h file looks like

      /*
       * Auto generated Run-Time-Environment Component Configuration File
       *      *** Do not modify ! ***
       * Project: 'Project' 
       * Target:  'STM32F410Tx_Nucleo' 
       */
      #define CMSIS_device_header "stm32f4xx.h" // define  own board header, eg stm32f4xx.h or stm32f7xx.h
      #ifndef RTE_COMPONENTS_H
      #define RTE_COMPONENTS_H
      #endif /* RTE_COMPONENTS_H */
      

      Make sure that the device name for the CMSIS_device_header corresponds to the header .h file located in ../Drivers/CMSIS/Device/ST/DEVICE_NAME/Include/DEVICE_NAME.h

    4. Add the required symbols (right-click your project, go to properties, C/C++ General, Paths and Symbols; then go to the #Symbols tab) to define the FPU and your Cortex Core type. For me I need to add __FPU_PRESENT (either with no value or value '1') and because I have the Cortex M4 chip on the STM32F411RE I add ARM_MATH_CM4. This means that my list of Symbols looks like:

      • __FPU_PRESENT
      • __packed with value __attribute__((__packed__))
      • __weak with value __attribute__((weak)) -ARM_MATH_CM4
      • STM32F411xE
      • USE_HAL_DRIVER though this depends if you want to use the HAL or not
    5. Again make sure that the necessary includes are well defined, as not including only 1 directory can lead to a large amount of errors. These can be found by going to project properties (right-click your project, option at the bottom), going to the C/C++ Build, Settings, then the Tool Settings tab, C Compiler dropdown and to the Directories option.

    For my project I have the following include path's inside the project properties:

    ../Inc                                           (should be by default)
    ../Drivers/CMSIS/Device/ST/STM32F4xx/Include     (should be by default) 
    ../Drivers/STM32F4xx_HAL_Driver/Inc              (should be by default)
    ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy       (should be by default)
    ../Drivers/CMSIS/Include                         (should be by default)
    
    "${workspace_loc:/${ProjName}/Drivers/Device/ST/STM32F4xx/Include}"
    "${workspace_loc:/${ProjName}/Drivers/CMSIS/Core/Include}" 
    "${workspace_loc:/${ProjName}/Drivers/CMSIS/Core_A/Include}"
    "${workspace_loc:/${ProjName}/Drivers/CMSIS/DSP/Include}"
    

    Hopefully this helps and works for you too!