一、简介
单片机开发普遍用的是Keil,由于Keil的编辑器比较复古(Keil很多坑前人基本已经踩过,调试方便,编辑器老旧),现在打算试一下vscode + platformio + stm32cube开发单片机。
开发环境:vscode + platformio + stm32cube
验证开发板:正点原子探索者(STM32F407ZG)
二、步骤
图 1.0 打开vscode 选择platformio IDE
图 1.1 创建工程
图 1.2 创建好工程,添加配置和移值文件
update_link_flags.py 需要添加FPU配置
# Custom settings, as referred to as "extra_script" in platformio.ini
#
# See http://docs.platformio.org/en/latest/projectconf.html#extra-script
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Append(
LINKFLAGS=[
"-mthumb",
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16",
"-mcpu=cortex-m4"
]
)
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
[env:black_f407zg]
platform = ststm32
board = black_f407zg
framework = stm32cube
upload_protocol = stlink ; 使用stlink烧写代码
debug_tool = stlink ; 使用stlink进行在线调试
build_flags =
-Wl,-u,_printf_float ;支持输出小数
-mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16
-Wl,-Map,output.map ;输出map
-O0 ;编译优先级(0,1,2,3)
-Isrc
-Isrc/led
; 使用自己的stm32f4xx_hal_conf.h
board_build.stm32cube.custom_config_header = yes
board_build.ldscript = STM32F407ZGTx_FLASH.ld
board_build.stm32cube.startup_file = startup_stm32f407xx.s
; board_upload.offset_address = 0x08000000
build_type = release
extra_scripts = update_link_flags.py
图 1.3 编译程序