From Arduino to RTOS

One thing that I learned after two weeks of struggling. If you want to use STM32 with FreeRTOS and files generated from a Cube IDE .ioc file, the way to go is baremetal (no fraemwork) rather than framework=stm32cube.

Discussion here

Example here

I am using a small shell script to update the platformio project with new files generated in the Cube IDE. There are some tweaks to do such as -I for the include files and replacing main.c and freertos.c with your own main files but much less frustration, so far, than with framework = stm32cube.

This is the script I use to update the baremetal platformio project with changes in the files generated by the cube ide project.

#!/bin/bash -x

dst="../platformio-baremetal"

rm -r $dst/lib/Core
cp -r Core $dst/lib/Core

# Patch Core related stuff
mv  $dst/lib/Core/Src/freertos.c  $dst/lib/Core/Src/freertos.c.ignored
mv  $dst/lib/Core/Src/main.c  $dst/lib/Core/Src/main.c.ignored

rm -rf $dst/src/startup
mv $dst/lib/Core/Startup $dst/src/startup

rm -r $dst/lib/Drivers
cp -r Drivers $dst/lib/Drivers

rm -r $dst/lib/Middlewares
cp -r Middlewares $dst/lib/Middlewares

rm -r $dst/lib/USB_DEVICE
cp -r USB_DEVICE $dst/lib/USB_DEVICE

cp STM32H750VBTX_FLASH.ld  $dst/STM32H750VBTX_FLASH.ld

And my platformio.ini looks like this

[env:weact_mini_h750vbtx]
platform = ststm32
board = weact_mini_h750vbtx
build_type = debug
debug_tool = stlink
upload_protocol = stlink
debug_build_flags = -O0 -ggdb3 -g3
board_build.ldscript = STM32H750VBTX_FLASH.ld
lib_archive = no
lib_deps = 
  Core
  Drivers
  Middlewares
  USB_DEVICE
build_flags =
  -mfpu=fpv4-sp-d16 
  -mfloat-abi=softfp  -Wl,-Map,${BUILD_DIR}/firmware.map
  -mthumb 
  -D debug
  -D USE_HAL_DRIVER
  -Ilib/Core/Inc
  -Ilib/Core/ThreadSafe
  -Ilib/Drivers/CMSIS/Device/ST/STM32H7xx/Include
  -Ilib/Drivers/CMSIS/Include
  -Ilib/Drivers/STM32H7xx_HAL_Driver/Inc
  -Ilib/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
  -Ilib/Middlewares/ST/STM32_USB_Device_Library/Core/Inc
  -Ilib/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
  -Ilib/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/Include
  -Ilib/Middlewares/Third_Party/FreeRTOS/Source/include
  -Ilib/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
  -Ilib/USB_DEVICE/App
  -Ilib/USB_DEVICE/Target