openocd (一)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/u011011827/article/details/102643360
  • 简介
openocd 可用来在在linux上运行,做应用,打开相应的调试器对应文件,然后通过调试器控制stm32
对应cmsis-dap 来说 不需要驱动,只需要应用openocd

调试器对应文件为
open("/dev/hidraw1", O_RDWR)            = 3 

strace 跟踪的openocd 下载过程 在 log.openocd 

  • log 地址

  • 安装

sudo apt-get install openocd
openocd --version
Open On-Chip Debugger 0.9.0 (2018-01-24-01:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
$sudo openocd -f /usr/share/openocd/scripts/interface/cmsis-dap.cfg -f /usr/share/openocd/scripts/target/stm32f4x.cfg 
Open On-Chip Debugger 0.9.0 (2018-01-24-01:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 2.0.0
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD IDCODE 0x2ba01477
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints


$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> 




$ sudo openocd -f /usr/share/openocd/scripts/interface/cmsis-dap.cfg -f /usr/share/openocd/scripts/target/stm32f4x.cfg 
Open On-Chip Debugger 0.9.0 (2018-01-24-01:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 2.0.0
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD IDCODE 0x2ba01477
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'telnet' connection on tcp/4444





$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x61000000 pc: 0x08000968 msp: 0x20000528
> flash write_image erase /home/pop/stm32/u-boot-2019.10-stm469/u-boot.bin
auto erase enabled
device id = 0x10076413
flash size = 1024kbytes
no flash bank found for address 0
wrote 0 bytes from file /home/pop/stm32/u-boot-2019.10-stm469/u-boot.bin in 0.009260s (0.000 KiB/s)
> flash write_image erase /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex
auto erase enabled
wrote 16384 bytes from file /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex in 2.756264s (5.805 KiB/s)
> reset
> 

$ sudo openocd -f /usr/share/openocd/scripts/interface/cmsis-dap.cfg -f /usr/share/openocd/scripts/target/stm32f4x.cfg 
Open On-Chip Debugger 0.9.0 (2018-01-24-01:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 2.0.0
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD IDCODE 0x2ba01477
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'telnet' connection on tcp/4444
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x61000000 pc: 0x08000968 msp: 0x20000528
auto erase enabled
Info : device id = 0x10076413
Info : flash size = 1024kbytes
Warn : no flash bank found for address 0
wrote 0 bytes from file /home/pop/stm32/u-boot-2019.10-stm469/u-boot.bin in 0.009260s (0.000 KiB/s)
auto erase enabled
wrote 16384 bytes from file /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex in 2.756264s (5.805 KiB/s)

  • openocd通过cmsis-dap下载hex文件到stm32f407(非CS架构)
sudo openocd \
	-f interface/cmsis-dap.cfg \
	-f target/stm32f4x.cfg  \
	-c init  \
	-c halt \
	-c "flash write_image erase /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex" \
	-c reset \
	-c shutdown

-f interface/cmsis-dap.cfg 调试器为cmsis-dap
-f target/stm32f4x.cfg 		目标芯片为 stm32f4系列
-c init  不可少
-c halt  halt住核心
-c "flash write_image erase /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex" 下载hex文件到mcu
-c reset 让mcu reset
-c shutdown 退出openocd // 关闭服务器.
----------------------------------log
$ sudo openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg  -c init -c halt -c "flash write_image erase /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex" -c reset -c shutdown   
Open On-Chip Debugger 0.9.0 (2018-01-24-01:05)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 2.0.0
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD IDCODE 0x2ba01477
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000372 msp: 0x20000530
auto erase enabled
Info : device id = 0x10076413
Info : flash size = 1024kbytes
wrote 16384 bytes from file /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex in 2.814998s (5.684 KiB/s)
shutdown command invoked
  • bin文件
sudo openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg  -c init -c halt -c "program /home/pop/stm32f407_in_linux/stm32f407_template/build/target.bin 0x8000000" -c reset -c shutdown

// 调整下载速率到10M
sudo openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg  -c init -c "adapter_khz 100000" -c halt -c "program ./target.bin 0x8000000" -c reset -c shutdown
//wrote 393216 bytes from file ./u-boot.bin in 48.444981s (7.927 KiB/s)

猜你喜欢

转载自blog.csdn.net/u011011827/article/details/102643360