环境:
PlatformIO 6.1.15
STM32CubeMX 6.11.1
stm32f103vct6芯片
platformio.ini为
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
src_dir = ./
[env:genericSTM32F103VC]
platform = ststm32
board = genericSTM32F103VC
; framework = stm32cube
build_flags =
-D STM32F103xE
-ICore/Inc
-IDrivers/CMSIS/Include
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include
-IDrivers/STM32F1xx_HAL_Driver/Inc
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy
build_src_filter = +<Core/Src/> +<startup_stm32f103xe.s> +<Drivers/>
board_build.ldscript = ./STM32F103VCTx_FLASH.ld
upload_protocol=cmsis-dap
debug_tool = cmsis-dap
extra_scripts =post:extra_script.py
stm32f407zgt6芯片
platformio.ini为
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
src_dir = ./
[env:black_f407zg]
platform = ststm32
board = black_f407zg
; framework = stm32cube
build_flags =
-D STM32F407xG
-ICore/Inc
-IDrivers/CMSIS/Include
-IDrivers/CMSIS/Device/ST/STM32F4xx/Include
-IDrivers/STM32F4xx_HAL_Driver/Inc
-IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy
build_src_filter = +<Core/Src/> +<startup_stm32f407xx.s> +<Drivers/>
board_build.ldscript = ./STM32F407ZGTx_FLASH.ld
upload_protocol = cmsis-dap
debug_tool = cmsis-dap
extra_scripts =post:extra_script.py
添加生成HEX的脚本,与platformio.ini同目录
extra_script.py
Import("env")
env.AddPostAction(
"$BUILD_DIR/${PROGNAME}.elf",
env.VerboseAction(" ".join([
"$OBJCOPY", "-O", "ihex", "-R", ".eeprom",
"$BUILD_DIR/${PROGNAME}.elf", "$BUILD_DIR/${PROGNAME}.hex"
]), "Building $BUILD_DIR/${PROGNAME}.hex")
)