Makefile+OpenOCD开发STM32

准备工作

平台:Windows11(Linux,MAC同理)

编译链(arm-none-eabi-gcc):Downloads | GNU Arm Embedded Toolchain Downloads -- Arm Developer

下载对应平台工具链并添加到环境变量,使用arm-none-eabi-gcc -v查看是否准备就绪

OpenOCD:Download OpenOCD for Windows (gnutoolchains.com)

生成工程

使用STM32CubeMX生成工程,生成方法

重点重点重点 :生成代码时Toolchain/IDE选择Makefile

编译

在生成工程的根目录会看到Makefile文件,在根目录打开终端并输入如下命令:

shell 复制代码
make -j12

打印空间信息即编译成功,否则日志中会报错

shell 复制代码
arm-none-eabi-size build/STM32H743.elf
   text    data     bss     dec     hex filename
  22908      24    2464   25396    6334 build/STM32H743.elf

下载

参考命令如下:

shell 复制代码
openocd.exe -f "interface/cmsis-dap.cfg" -f "target/stm32h7x.cfg" -c "program STM32H743-2740.hex" -c reset -c shutdown

配置文件在OpenOCD\share\openocd\scripts下可找到,第一个是调试器的配置文件,第二个是芯片的配置文件,可以合二为一

第三个是上一节编译出的hex文件

-c reset是下载成功后复位芯片

-c shutdown是执行完成后退出OpenOCD

成功日志如下:

C 复制代码
PS D:\OpenOCD-20231002-0.12.0\bin> .\openocd.exe -f "cmsis-dap.cfg" -f "stm32h7x.cfg" -c "program STM32H743-2740.hex" -c
 reset -c shutdown
Open On-Chip Debugger 0.12.0 (2023-10-02) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
libusb1 09e75e98b4d9ea7909e8837b7a3f00dda4589dc3
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 1 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 1800 kHz
Info : SWD DPIDR 0x6ba02477
Info : [stm32h7x.cpu0] Cortex-M7 r1p1 processor detected
Info : [stm32h7x.cpu0] target has 8 breakpoints, 4 watchpoints
Info : gdb port disabled
Info : starting gdb server for stm32h7x.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
[stm32h7x.cpu0] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080002b0 msp: 0x24000508
** Programming Started **
Info : Device: STM32H74x/75x
Info : flash size probed value 2048k
Info : STM32H7 flash has dual banks
Info : Bank (0) size is 1024 kb, base address is 0x08000000
Info : Padding image section 0 at 0x080038cc with 20 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x080038e0 .. 0x0801ffff
** Programming Finished **
shutdown command invoked
相关推荐
salipopl29 分钟前
基于STM32平台的多旋翼无人机系统设计与实现
stm32·嵌入式硬件·无人机
iCxhust8 小时前
8086/8088单板机VSCode集成自动下载功能(完善串口接收显示版)
ide·vscode·单片机·编辑器·微机原理·8088单板机·8086单板机
振南的单片机世界9 小时前
从数码管到点阵屏:动态扫描加595,3个IO驱动256个LED
stm32·单片机·嵌入式硬件
listhi5209 小时前
STC8 16通道模拟采集 + 4路串口 + 8路PWM 程序
stm32·单片机·嵌入式硬件
星夜夏空9910 小时前
STM32单片机学习(4)——嵌入式概述
stm32·单片机·学习
Deitymoon11 小时前
STM32——OLED显示字符串
单片机·嵌入式硬件
LCG元11 小时前
STM32实战:基于STM32F407的FFT频谱分析(音频信号处理)
stm32·音视频·信号处理
Graceful_scenery11 小时前
龙芯2k0300 - 走马观碑组按键驱动移植
单片机·嵌入式硬件
d111111111d11 小时前
MQTT+STM32+ESP8266网络程序分层+韦老师
笔记·stm32·单片机·嵌入式硬件·学习·php
长安第一美人11 小时前
RT-Thread 工业屏驱动开发实战:UART 串口屏协议解析 + 数据实时刷新 + 设备驱动框架完整实现
驱动开发·嵌入式硬件·rt-thread·工业控制·uart通信·串口屏驱动