STM32环境安装
一、安装工具
1、STM32CubeMX
安装
2、OpenCD
设置嵌入式开发,选择OpenOCD和CubeMX的安装路径
PS:安装路径不要出现空格!安装路径不要出现空格!安装路径不要出现空格!
3、MinGW
安装路径不能带空格
安装所有基础包
4、arm-none-eabi-gcc
解压放到相应目录
5、环境变量中添加
重启PC
6、验证环境
gcc -v
arm-none-eabi-gcc -v
二、Clion配置
添加新的MinGW-STM32
修改以上三处就可以了
三、创建工程
选择STM32CubeMX创建工程
选择对应的芯片型号,并返回工程
工程名称需与创建名称相同,IDE设置成STM32CubeIDE
cmake无报错,配置成功
四、烧写程序
选择自己适配的芯片型号文件,没有则需要自行创建
创建烧写文件stlink.cfg
# choose st-link/j-link/dap-link etc.
#adapter driver cmsis-dap
#transport select swd
source [find interface/stlink.cfg]
transport select hla_swd
source [find target/stm32f4x.cfg]
# download speed = 10MHz
adapter speed 10000
异常错误
"D:\Program Files\STMicroelectronics\STM32Cube\OpenOCD\bin\openocd.exe" -s "D:\Program Files\STMicroelectronics\STM32Cube\OpenOCD\share\openocd\scripts" -f D:\work\code\STM32F4\config\stlink.cfg -c "tcl_port disabled" -c "gdb_port disabled" -c "tcl_port disabled" -c "program \"D:/work/code/STM32F4/cmake-build-debug-mingw-stm32/STM32F4.elf\"" -c reset -c shutdown
[0m[0mOpen On-Chip Debugger 0.11.0 (2021-11-18) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
libusb1 09e75e98b4d9ea7909e8837b7a3f00dda4589dc3
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results mi
ght differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : STLINK V2J35S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.221098
Info : stm32f4x.cpu: Cortex-M4 r0p1 processor detected
Info : stm32f4x.cpu: target has 6 breakpoints, 4 watchpoints
Info : gdb port disabled
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000a44 msp: 0x20001000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
** Programming Started **
Info : device id = 0x100f6413
Info : flash size = 512 kbytes
** Programming Finished **
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
shutdown command invoked
原因:大体是说速度不匹配,怎么修改希望有大神能指导
五、调试
异常错误
Open On-Chip Debugger 0.11.0 (2021-11-18) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
libusb1 09e75e98b4d9ea7909e8837b7a3f00dda4589dc3
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Unexpected command line argument: Files\STMicroelectronics\STM32Cube\OpenOCD\sha
re\openocd\scripts
GDB Server stopped, exit code 1
原因:路径中存在空格
修改OPENOCD的安装路径
修改系统路径