ELF文件转二进制或十六进制
arm-none-eabi-objcopy -O binary myapp.elf myapp.bin arm-none-eabi-objcopy -O ihex myapp.elf myapp.hex
ST-Link命令
查看所有 ST-LINK 设备
st-info --probe
🔹 查看芯片 Flash 信息
st-info --flash
🔹 查看芯片 RAM 信息
st-info --sram
🔹 查看芯片类型(如 STM32F103C8)
st-info --chipid
2. Flash 相关:st-flash
用于烧录、读取、擦除。
擦除整个 Flas
st-flash erase
(等价于全片擦除)
烧录 .bin 文件
st-flash write build/MyProject.bin 0x08000000
烧录 .hex 文件
st-flash --format ihex write build/MyProject.hex
读取 Flash 到文件
st-flash read flash_dump.bin 0x08000000 0x10000
(从 0x08000000 开始读 64KB)
指定频率烧录(修复通信不稳定)
st-flash --connect-under-reset --frequency 4000 write build/app.bin 0x08000000
3. GDB 调试:st-util
开启 GDB server → 用 arm-none-eabi-gdb 连接。
启动 GDB Server
st-util
默认监听:
localhost:4242
启动后你可以用:
arm-none-eabi-gdb your.elf
(gdb) target extended-remote localhost:4242
(gdb) monitor reset halt
修改 GDB server 端口
st-util -p 3333
4. Trace:st-trace
用于 SWO 端口跟踪(F1 不支持),适合 F4、F7、H7 系列。
启动 SWO Trace
st-trace --freq=2000000
5. 常见组合命令
最常用:直接烧录并自动复位
st-flash write build/app.bin 0x08000000
调试步骤(GDB)
st-util
另一个终端:
arm-none-eabi-gdb app.elf
(gdb) target extended-remote :4242
(gdb) monitor reset halt
(gdb) load
(gdb) continue