开发环境:ubuntu22.04 + stm32CubeMX + gcc-arm-none-eabi,烧录工具:openOCD
1,安装 openOCD,打开一个终端并输入指令:$ sudo apt install openocd
2,检查 openOCD 的版本号,同样地,也能知道该软件是否安装成功,在终端中输入:$ openocd --version,会看到下面类型的输出打印:
Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
3,准备固件烧录工具:拿到一个烧录器:JLink,一块 stm32f4 开发板,附带它们之间的连接线,把它们都上电并连接起来
4,按照第四篇(4,配置开发环境 - 编译工程示例_开发环境示例_cutelily2014的博客-CSDN博客) 博客的第 8 步,我已经得到了编译输出的固件,该固件位于工程示例软件包 test0 里面,打开 test0 文件夹,里面有这几个子文件:"build" / "Core" / "STM32F405RGTx_FLASH.ld" / "Drivers" / "startup_stm32f405xx.s" / "test0.ioc"
5,进入到子文件 "build" ,在这个文件夹下面创建一个小文件,用于配置 openOCD 运行参数,文件名为 openocd.cfg,在文件中写入以下内容:
source [find interface/jlink.cfg]
transport select jtag
source [find target/stm32f4x.cfg]
reset_config none
6,这时候看到,在子文件 "build" 下面,既有了openOCD 运行所需的 openocd.cfg;也有了编译出来的固件 test0.hex。接下来,第一件事是让 openOCD 软件去识别出来 JLink,打开一个终端并输入指令:$ openocd,会看到下面的连接信息:
test0/build$ openocd
Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
none separate
cortex_m reset_config sysresetreq
none separate
Info : No device selected, using first device.
Info : J-Link ARM V8 compiled Nov 28 2014 13:44:46
Info : Hardware version: 8.00
Info : VTarget = 3.274 V
Info : clock speed 2000 kHz
Info : JTAG tap: stm32f4x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : JTAG tap: stm32f4x.bs tap/device found: 0x06413041 (mfg: 0x020 (STMicroelectronics), part: 0x6413, ver: 0x0)
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
7,在上一步的基础上,重新打开一个新的终端并输入指令:$ telnet localhost 4444,会出现下面类型的输入界面:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
>
在这个向右的尖号后面,依次执行这几个指令:
> reset halt
> flash erase_sector 0 0 last
> flash write_image test0.hex
> reset
那么这一部完整的流程是这个样子:
lily@lily:~/Documents/Project_ST/test0/build$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reset halt
adapter speed: 2000 kHz
JTAG tap: stm32f4x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
JTAG tap: stm32f4x.bs tap/device found: 0x06413041 (mfg: 0x020 (STMicroelectronics), part: 0x6413, ver: 0x0)
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08001070 msp: 0x20020000
> flash erase_sector 0 0 last
device id = 0x10076413
flash size = 1024kbytes
erased sectors 0 through 11 on flash bank 0 in 16.584469s
> flash write_image test0.hex
wrote 4448 bytes from file test0.hex in 0.371708s (11.686 KiB/s)
> reset
adapter speed: 2000 kHz
JTAG tap: stm32f4x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
JTAG tap: stm32f4x.bs tap/device found: 0x06413041 (mfg: 0x020 (STMicroelectronics), part: 0x6413, ver: 0x0)
8,此时我的板子已经能按照设想的效果运行,表明自己写的软件已经正确地运行起来。目前只是做了一个点灯实验,能看到小灯闪烁,但这个事情花了一天的时间。