# STM32_platformio **Repository Path**: orlenHJ/stm32_platformio ## Basic Information - **Project Name**: STM32_platformio - **Description**: STM32_platformio的简单尝试,/stm32f407_new_pio是已经配置好freertos的一版 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2023-10-06 - **Last Updated**: 2024-02-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PIO + STM32F4 STM32Cube FreeRTOS demo ## Description Shows how a auto-generated STM32CubeMX project can be converted to be compiled with PlatformIO ## STM32CubeMX configuration 1. Selected the **board** NUCLEO-H723ZG, initialize all peripherals in default mode 2. Activate Middleware -> FreeRTOS -> CMSIS_V2 3. Change SYS -> Timebase Source to "TIM2" (recommended since FreeRTOS uses SysTick) 4. Generate code for STM32CubeIDE, folder structure "advanced" ## PlatformIO conversion 1. Create blank PlatformIO project for NUCLEO-H723ZG 2. Copy `Core\Inc\*` from STM32Cube project to `include\*` 3. Copy `Core\Src\*` from STM32Cube project to `src\*` 4. Copy `Middlewares\Third_Party\FreeRTOS` folder into `lib` 5. Copy `STM32H723ZGTX_FLASH.ld` to the root of the PIO project 6. Adapt `platformio.ini` to the following ```ini [env:nucleo_h723zg] platform = ststm32 board = nucleo_h723zg framework = stm32cube ; select linker file generated by CubeMX board_build.ldscript = STM32H723ZGTX_FLASH.ld ; make build system use our HAL config file board_build.stm32cube.custom_config_header = yes ; force inclusion of lib/FreeRTOS lib_deps = FreeRTOS ; needed compiler flags to ; correctly build the port assembly files ; and add freertos subfolders to include path build_flags = -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Ilib/FreeRTOS/include -Ilib/FreeRTOS/CMSIS_RTOS_V2 -Ilib/FreeRTOS/portable/GCC/ARM_CM4F -Iinclude ; link FreeRTOS as objectf files, not as ; archives. otherwise weak ISR functions ; don't get linked properly! lib_archive = no ; fix for RAM size / initial SP. ; see https://community.platformio.org/t/arm-versus-thumb/23540/ ; actually **not** needed because we have selected a fixed linkerfile!! ;board_upload.maximum_ram_size = 131072 ``` Note: * This conversion process and the needed build flags are nothing new * outlined in many forum threads * automatic conversions tools like https://github.com/ussserrr/stm32pio exist that do the **exact same thing** * `board_build.stm32cube.custom_config_header` is needed, the default `stm32h7xx_hal_conf.h` supplied by PlatformIO declares a 25MHz HSE input frequency when the Nucleo board has a 8MHz one. Alternatively, add `-DHSE_VALUE=8000000UL` to the `build_flags`. * No need to copy `Core\Startup`, PlatforrmIO already has the startup file and compiles it in. * same goes for `Drivers\CMSIS` and `Drivers\STM32H7xx_HAL_Driver`