- 簡介
openocd 可用來在在linux上運行,做應用,打開相應的調試器對應文件,然後通過調試器控制stm32
對應cmsis-dap 來說 不需要驅動,只需要應用openocd
調試器對應文件爲
open("/dev/hidraw1", O_RDWR) = 3
strace 跟蹤的openocd 下載過程 在 log.openocd
-
安裝
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
- openocd通過cmsis-dap下載hex文件到stm32f407(CS架構)
- openocd下載不同後綴名文件
$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)