本文共 6286 字,大约阅读时间需要 20 分钟。
openocd 可用来在在linux上运行,做应用,打开相应的调试器对应文件,然后通过调试器控制stm32对应cmsis-dap 来说 不需要驱动,只需要应用openocd调试器对应文件为open("/dev/hidraw1", O_RDWR) = 3 strace 跟踪的openocd 下载过程 在 log.openocd
安装
sudo apt-get install openocdopenocd --versionOpen On-Chip Debugger 0.9.0 (2018-01-24-01:05)Licensed under GNU GPL v2For 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 v2For bug reports, read http://openocd.org/doc/doxygen/bugs.htmlInfo : only one transport option; autoselect 'swd'adapter speed: 2000 kHzadapter_nsrst_delay: 100none separatecortex_m reset_config sysresetreqInfo : CMSIS-DAP: SWD SupportedInfo : CMSIS-DAP: JTAG SupportedInfo : CMSIS-DAP: Interface Initialised (SWD)Info : CMSIS-DAP: FW Version = 2.0.0Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1Info : CMSIS-DAP: Interface readyInfo : clock speed 2000 kHzInfo : SWD IDCODE 0x2ba01477Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints$ telnet localhost 4444Trying 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 v2For bug reports, read http://openocd.org/doc/doxygen/bugs.htmlInfo : only one transport option; autoselect 'swd'adapter speed: 2000 kHzadapter_nsrst_delay: 100none separatecortex_m reset_config sysresetreqInfo : CMSIS-DAP: SWD SupportedInfo : CMSIS-DAP: JTAG SupportedInfo : CMSIS-DAP: Interface Initialised (SWD)Info : CMSIS-DAP: FW Version = 2.0.0Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1Info : CMSIS-DAP: Interface readyInfo : clock speed 2000 kHzInfo : SWD IDCODE 0x2ba01477Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpointsInfo : accepting 'telnet' connection on tcp/4444$ telnet localhost 4444Trying 127.0.0.1...Connected to localhost.Escape character is '^]'.Open On-Chip Debugger> halttarget state: haltedtarget 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.binauto erase enableddevice id = 0x10076413flash size = 1024kbytesno flash bank found for address 0wrote 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.hexauto erase enabledwrote 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 v2For bug reports, read http://openocd.org/doc/doxygen/bugs.htmlInfo : only one transport option; autoselect 'swd'adapter speed: 2000 kHzadapter_nsrst_delay: 100none separatecortex_m reset_config sysresetreqInfo : CMSIS-DAP: SWD SupportedInfo : CMSIS-DAP: JTAG SupportedInfo : CMSIS-DAP: Interface Initialised (SWD)Info : CMSIS-DAP: FW Version = 2.0.0Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1Info : CMSIS-DAP: Interface readyInfo : clock speed 2000 kHzInfo : SWD IDCODE 0x2ba01477Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpointsInfo : accepting 'telnet' connection on tcp/4444target state: haltedtarget halted due to debug-request, current mode: Thread xPSR: 0x61000000 pc: 0x08000968 msp: 0x20000528auto erase enabledInfo : device id = 0x10076413Info : flash size = 1024kbytesWarn : no flash bank found for address 0wrote 0 bytes from file /home/pop/stm32/u-boot-2019.10-stm469/u-boot.bin in 0.009260s (0.000 KiB/s)auto erase enabledwrote 16384 bytes from file /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex in 2.756264s (5.805 KiB/s)
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 v2For bug reports, read http://openocd.org/doc/doxygen/bugs.htmlInfo : only one transport option; autoselect 'swd'adapter speed: 2000 kHzadapter_nsrst_delay: 100none separatecortex_m reset_config sysresetreqInfo : CMSIS-DAP: SWD SupportedInfo : CMSIS-DAP: JTAG SupportedInfo : CMSIS-DAP: Interface Initialised (SWD)Info : CMSIS-DAP: FW Version = 2.0.0Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1Info : CMSIS-DAP: Interface readyInfo : clock speed 2000 kHzInfo : SWD IDCODE 0x2ba01477Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpointstarget state: haltedtarget halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08000372 msp: 0x20000530auto erase enabledInfo : device id = 0x10076413Info : flash size = 1024kbyteswrote 16384 bytes from file /home/pop/stm32/stm32_template/stm32f407_template/TEST.hex in 2.814998s (5.684 KiB/s)shutdown command invoked
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// 调整下载速率到10Msudo 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)
转载地址:http://xrngi.baihongyu.com/