Help: STM32F407IGT6 Compilation Error with FreeRTOS by CubeMX

Help: STM32F407IGT6 Compilation Error with FreeRTOS

I use CubeMX to generate project code. When not using FreeRTOS, the project compiles normally. However, when using FreeRTOS, the project fails to compile regardless of the operation.

Normal Compilation (Without FreeRTOS, Not Using PlatformIO’s HAL Library)

[platformio]
src_dir = ./

[env:genericSTM32F407IGT6]
platform = ststm32
board = genericSTM32F407IGT6
; framework = stm32cube

build_flags =
    -IInc
    -IDrivers/STM32F4xx_HAL_Driver/Inc
    -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy
    -IDrivers/CMSIS/Device/ST/STM32F4xx/Include
    -IDrivers/CMSIS/Include

Attempt After Adding FreeRTOS

Solution 1: Using Libraries Generated by CubeMX

[platformio]
src_dir = ./

[env:genericSTM32F407IGT6]
platform = ststm32
board = genericSTM32F407IGT6
; framework = stm32cube

build_flags =
    -IInc
    -IDrivers/STM32F4xx_HAL_Driver/Inc
    -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy
    -IDrivers/CMSIS/Device/ST/STM32F4xx/Include
    -IDrivers/CMSIS/Include

Error Message:

C:\Users\lemac\AppData\Local\Temp\ccVTkapf.s: Assembler messages:
C:\Users\lemac\AppData\Local\Temp\ccVTkapf.s:330: Error: selected processor does not support `vstmdbeq r0!,{s16-s31}' in Thumb mode
C:\Users\lemac\AppData\Local\Temp\ccVTkapf.s:332: Error: instruction not allowed in IT block -- `stmdb r0!,{r4-r11,r14}'
C:\Users\lemac\AppData\Local\Temp\ccVTkapf.s:352: Error: selected processor does not support `vldmiaeq r0!,{s16-s31}' in Thumb mode
C:\Users\lemac\AppData\Local\Temp\ccVTkapf.s:354: Error: instruction not allowed in IT block -- `msr psp,r0'
*** [.pio\build\genericSTM32F407IGT6\src\Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F\port.o] Error 1

Consulting GPT yielded no results.

Solution 2: Using PlatformIO’s Built-in Libraries

Library Path:

C:\Users\lemac\.platformio\packages\framework-stm32cubef4\Middlewares\Third_Party\FreeRTOS\Source

Configuration:

[platformio]
src_dir = ./

[env:genericSTM32F407IGT6]
platform = ststm32
board = genericSTM32F407IGT6
framework = stm32cube

build_flags =
    -I Inc
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/include
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/portable
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/portable/Tasking/ARM_CM4F

build_src_filter = +<C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2> +</>

Error Message:

Linking .pio\build\genericSTM32F407IGT6\firmware.elf
arm-none-eabi-gcc: error: C:/Users/lemac/OneDrive/Documents/PlatformIO/Projects/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.o: No such file or directory
*** [.pio\build\genericSTM32F407IGT6\firmware.elf] Error 1
======================================= [FAILED] Took 2.72 seconds

Configuration:

[platformio]
src_dir = ./

[env:genericSTM32F407IGT6]
platform = ststm32
board = genericSTM32F407IGT6
framework = stm32cube

build_flags =
    -I Inc
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/include
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/portable
    -I C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/portable/Tasking/ARM_CM4F

; build_src_filter = +<C:/Users/lemac/.platformio/packages/framework-stm32cubef4/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2> +</>
Linking .pio\build\genericSTM32F407IGT6\firmware.elf
.pio/build/genericSTM32F407IGT6/src/Src/freertos.o: In function `StartDefaultTask':
freertos.c:(.text.StartDefaultTask+0x4): undefined reference to `osDelay'
.pio/build/genericSTM32F407IGT6/src/Src/freertos.o: In function `MX_FREERTOS_Init':
freertos.c:(.text.MX_FREERTOS_Init+0x8): undefined reference to `osThreadNew'
.pio/build/genericSTM32F407IGT6/src/Src/main.o: In function `main':
main.c:(.text.startup.main+0x22): undefined reference to `osKernelInitialize'
main.c:(.text.startup.main+0x2a): undefined reference to `osKernelStart'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\genericSTM32F407IGT6\firmware.elf] Error 1
======================================= [FAILED] Took 4.30 seconds

Folder Structure:

That just means the compiler flag for the floating point unit is not correctly configured.

See

Thank you! However, it appears another issue has arisen. I apologize for the inconvenience!

c:/users/lemac/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2.exe: error: ld returned 1 exit status

_sbrk is the function that allocates new memory for the heap, aka the malloc() function. You also need to link against newlib-nano if you want a default implementation.

You should add into the python script hardfloat.py at the end

env.Append(LINKFLAGS=["--specs=nosys.specs", "--specs=nano.specs"])

Or implement the function in code yourself for complete control, as part of the syscalls:

Oh! It worked! Thank you so much! Your ability to swiftly identify the problem is truly impressive. You are amazing! I aspire to be as skilled a technologist as you someday.
By the way, after successfully compiling the project, I moved the Middlewares back to their original path, and the project compiled without any issues.

1 Like