PlatformIO Community

CubeMX with FreeRTOS


OK, I’m very close, everything compiles but it doesn’t link and am not sure why.

platform = ststm32
board = nucleo_l152re
framework = stm32cube
build_flags = ${specific_inclibs.build_flags}

build_flags =

Here is the link error I get

Linking .pioenvs/nucleo_l152re/firmware.elf
.pioenvs/nucleo_l152re/src/freertos.o: In function `StartDefaultTask':
freertos.c:(.text.StartDefaultTask+0x4): undefined reference to `osDelay'
.pioenvs/nucleo_l152re/src/freertos.o: In function `MX_FREERTOS_Init':
freertos.c:(.text.MX_FREERTOS_Init+0x14): undefined reference to `osThreadCreate'
.pioenvs/nucleo_l152re/src/main.o: In function `main':
main.c:(.text.startup.main+0xe): undefined reference to `osKernelStart'
.pioenvs/nucleo_l152re/src/stm32l1xx_it.o: In function `SysTick_Handler':
stm32l1xx_it.c:(.text.SysTick_Handler+0xa): undefined reference to `osSystickHandler'
collect2: error: ld returned 1 exit status
*** [.pioenvs/nucleo_l152re/firmware.elf] Error 1

Also, the main.c file is the standard file generated by cubemx.


It doesn’t compile the FreeRTOS sources because it thinks they aren’t used. You can move the FreeRTOS foder into src/ to make it work. Or even just say lib_deps = FreeRTOS in the platformio.ini will make it compile.

Here’s a CubeMX generated + importorted FreeRTOS Blinky project for the Nucleo L152RE:


Awesome. I’m trying the lib_deps = FreeRTOS but now I am getting strange errors regarding permissions.

Compiling .pioenvs/nucleo_l152re/FrameworkHALDriver/Src/stm32l1xx_ll_spi.o
Assembler messages:
Fatal error: can't create .pioenvs/nucleo_l152re/FrameworkHALDriver/Src/stm32l1xx_ll_rtc.o: Permission denied
Compiling .pioenvs/nucleo_l152re/FrameworkHALDriver/Src/stm32l1xx_ll_tim.o
Compiling .pioenvs/nucleo_l152re/FrameworkHALDriver/Src/stm32l1xx_ll_usart.o
Assembler messages:
Fatal error: can't create .pioenvs/nucleo_l152re/FrameworkHALDriver/Src/stm32l1xx_ll_spi.o: Permission denied
Compiling .pioenvs/nucleo_l152re/FrameworkHALDriver/Src/stm32l1xx_ll_utils.o

I’ll checkout the link you provided on github.


Maybe pio run -t clean first?

Ah actually for that to work you need to have the FreeRTOS files in lib/. Unfortunately there already is a registered library named ‘FreeRTOS’ so I named by folder ‘FreeRTOS_cubemx’ and referenced that; otherwise it would try and download a library. See the new branch at


Your link to the github repo worked perfectly. I’m assuming, however, that I will not be able to do a true roundtrip from cubemx modifications, code generation and rebuild without moving files around that it generates?


For FreeRTOS, lib/FreeRTOS code itself shouldn’t change but only the FreeRTOSConfig.h. Copying files is rather quick; Set CubeMX to generate for SW4STM32, copy everything in Src to src, Inc to include. That should do it in most cases unless some new drivers under Drivers/ are added.

Least-work case is of course having the perfect CubeMX project configuration in the first place and only having to copy once :wink:


Awesome, I was not picking SW4STM32 when generating so that is great to know. Thanks again for all the great help.