STM32: 使用openocd更新stm32f030F4固件

今天发现在Mac OS上使用port下载openocd软件,得到的软件版本号为0.7.0,通过它来更新STM32F030F4固件的时候,会出现如下错误信息:

$ openocd -f interface/stlink-v2.cfg -f target/stm32f0x_stlink.cfg -c init -c "reset halt" -c "flash write_image erase build/ch.bin 0x08000000 bin" -c "verify_image build/ch.bin 0x08000000 bin" -c "reset run" -c shutdown 
Open On-Chip Debugger 0.7.0 (2016-05-14-17:10)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : This adapter doesn't support configurable speed
Info : STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : Target voltage: 2.885076
Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0x080000c0 msp: 0x20000400
auto erase enabled
Info : device id = 0x10006444
Warn : Cannot identify target as a STM32 family.
Error: auto_probe failed
in procedure 'flash'

可以看到是由于openocd版本太旧,没办法确认target的身份信息,看来得更新这个应用程序才行。openocd是开源项目,可以从官网上下载最新的代码进行编译,生成我们所需要软件。

  • 下载编译openocd

1. 使用git命令下载openocd源代码

$ git clone git://git.code.sf.net/p/openocd/code openocd

2. 下载openocd子模块:jimtcl, libjaylink,  git2cl代码

$ cd openocd
$ git submodule init
$ git submodule update

3. 编译及安装

$ ./bootstrap
$ ./configure
$ make && make install

最终openocd会安装在/usr/local/bin/目录下。

  • 通过openocd更新固件

我使用的是STM32F407 discovery上的ST-Link v2, 固件存放在build/文件夹下,名为ch.bin,更新的命令如下:

$ /usr/local/bin/openocd -f interface/stlink-v2.cfg -f target/stm32f0x_stlink.cfg -c init -c "reset halt" -c "flash write_image erase build/ch.bin 0x08000000 bin" -c "verify_image build/ch.bin 0x08000000 bin" -c "reset run" -c shutdown
Open On-Chip Debugger 0.10.0-dev-00288-g060e9c3 (2016-05-14-22:52)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
WARNING: target/stm32f0x_stlink.cfg is deprecated, please switch to target/stm32f0x.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.885076
Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints
adapter speed: 1000 kHz
stm32f0x.cpu: target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0x080000c0 msp: 0x20000400
auto erase enabled
Info : device id = 0x10006444
Info : flash size = 16kbytes
stm32f0x.cpu: target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000400
wrote 7168 bytes from file build/ch.bin in 0.447679s (15.636 KiB/s)
stm32f0x.cpu: target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000400
verified 6180 bytes in 0.090467s (66.711 KiB/s)
adapter speed: 1000 kHz
shutdown command invoked

从这里可以看到这里不但执行为更新固件的操作,同时还对之前更新的固件进行完整性验证。

[2016-06-04 21:31:28]

之前没有注意到openocd推荐使用stm32f0x.cfg作为配置文件对stm32f0系列MCU进行操作,所以更新固件使用如下命令:

$ /usr/local/bin/openocd -f interface/stlink-v2.cfg -f target/stm32f0x.cfg -c init -c "reset halt" -c "flash write_image erase build/ch.bin 0x08000000 bin" -c "verify_image build/ch.bin 0x08000000 bin" -c "reset run" -c shutdown 
Open On-Chip Debugger 0.10.0-dev-00288-g060e9c3 (2016-05-14-22:52)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.893577
Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints
adapter speed: 1000 kHz
stm32f0x.cpu: target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0x080000c0 msp: 0x20000400
auto erase enabled
Info : device id = 0x10006444
Info : flash size = 16kbytes
stm32f0x.cpu: target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000400
wrote 7168 bytes from file build/ch.bin in 0.445774s (15.703 KiB/s)
stm32f0x.cpu: target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000400
verified 6276 bytes in 0.091579s (66.925 KiB/s)
adapter speed: 1000 kHz
shutdown command invoked

发表评论

电子邮件地址不会被公开。 必填项已用*标注