STM32使用CMSIS-DAP下载zephyr生成文件

4 篇文章 0 订阅
2 篇文章 0 订阅

前几天刚装配好zephyr的环境,因为手头没有现成的开发板,所以就去淘宝买了一块开发板,我的要求是:最好带一块屏幕,不论是oled还是lcd,有按键,足够小,这样我在zephyr上面才能够使劲折腾。
然后我就找到了一块合适的板子:魔女开发板,有屏幕,有按键,关键是,上面自带了下载器,不需要我额外去买jlink或者stlink了。
在我打下west flash命令之后,果断报错:

-- west flash: using runner openocd
-- runners.openocd: Flashing file: /home/shuiyihang/zephyrproject/zephyr/build/zephyr/zephyr.hex
Open On-Chip Debugger 0.10.0+dev-01508-gf79c90268-dirty (2021-02-16-17:45)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 1000 kHz
Error: open failed


FATAL ERROR: command exited with status 1: /home/shuiyihang/zephyr-sdk-0.12.3/sysroots/x86_64-pokysdk-linux/usr/bin/openocd -s /home/shuiyihang/zephyrproject/zephyr/boards/arm/stm32f103_mini/support -s /home/shuiyihang/zephyr-sdk-0.12.3/sysroots/x86_64-pokysdk-linux/usr/share/openocd/scripts -f /home/shuiyihang/zephyrproject/zephyr/boards/arm/stm32f103_mini/support/openocd.cfg -c init -c targets -c 'reset halt' -c 'flash write_image erase /home/shuiyihang/zephyrproject/zephyr/build/zephyr/zephyr.hex' -c 'reset halt' -c 'verify_image /home/shuiyihang/zephyrproject/zephyr/build/zephyr/zephyr.hex' -c 'reset run' -c shutdown

这是什么鬼,我怎么知道怎么搞,遇到问题不要慌,去官网上看看,好家伙,英文看的脑壳痛,也找不到问题之所在。
那就算了,就用串口下载好了,呜呜呜,我只是想试试zephyr罢了,也不麻烦,直接把flymcu的文件路径改为虚拟机共享文件夹下路径就好了,但是我每次下载都要把boot0置1,为了让他运行还要把boot0再搞回去,我受不了。既然已经验证最起码可以运行zephyr的闪灯程序,那么我就要更进一步!!
然后就开始百度,CMSIS-DAP怎么不安装keil之类给stm32烧程序,咦,openocd!!
等下这家伙有点眼熟,转眼一看,卧槽,这不是报错的地方吗,好家伙逃不了了是吧。。。
我直接再虚拟机的根目录里使用openocd -V发现没有安装openocd,那么看来就是zephyr使用的openocd是自己自带但不全局使用的了,好的就按照指示,全局安装openocd,然后找到了这篇文章:
https://zhuanlan.zhihu.com/p/32675926
不行我又出错了,我并没有等到出现而是一直在报错:

adapter speed: 1000 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 = �ȶ���V3
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x1ba01477
Info : SWD DPIDR 0x1ba01477
Error: Failed to read memory at 0xe000ed04
Polling target stm32f1x.cpu failed, trying to reexamine
Info : SWD DPIDR 0x1ba01477
Info : SWD DPIDR 0x1ba01477
Error: Failed to read memory at 0xe000ed04
Examination failed, GDB will be halted. Polling again in 100ms
Polling target stm32f1x.cpu failed, trying to reexamine
Info : SWD DPIDR 0x1ba01477
Info : SWD DPIDR 0x1ba01477

这是怎么回事呢,我想来没办法,就尝试又把boot0给置1了,这一下子竟然好了,但是这是不正常的呀,正常情况应该是boot0为0正常下载,我想可能是上一次串口下载造成的后遗症??
好了,现在可以通过openocd直接给单片机刷程序,但是,但是,但是,都是用的openocd,那么按道理来说!!,我的zephyr里直接使用west flash绝对应该是可以的,那么问题出在了哪呢??
我想到了使用openocd时候,配置了参数interface和transport,那么在zephyr某个文件里绝对应该也有这些参数,然后就让我找到了,openocd.cfg这个文件,好家伙那就改吧:

source [find interface/cmsis-dap.cfg]
transport select swd

总因该好了吧,再次插入板子,把板子连到虚拟机里,再次west flash 好家伙还是不行??
但是情况好多了,现在是提示等待算法超时

Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = �ȶ���V3
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x1ba01477
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* stm32f1x.cpu       cortex_m   little stm32f1x.cpu       unknown

target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08001470 msp: 0x200007b0
Info : device id = 0x10036414
Info : flash size = 512kbytes
Error: timeout waiting for algorithm, a target reset is recommended
Error: flash write failed at address 0x8000000
Error: error writing to flash at address 0x08000000 at offset 0x00000000
auto erase enabled
FATAL ERROR: command exited with status 1: /home/shuiyihang/zephyr-sdk-0.12.3/sysroots/x86_64-pokysdk-linux/usr/bin/openocd -s /home/shuiyihang/zephyrproject/zephyr/boards/arm/stm32f103_mini/support -s /home/shuiyihang/zephyr-sdk-0.12.3/sysroots/x86_64-pokysdk-linux/usr/share/openocd/scripts -f /home/shuiyihang/zephyrproject/zephyr/boards/arm/stm32f103_mini/support/openocd.cfg -c init -c targets -c 'reset halt' -c 'flash write_image erase /home/shuiyihang/zephyrproject/zephyr/build/zephyr/zephyr.hex' -c 'reset halt' -c 'verify_image /home/shuiyihang/zephyrproject/zephyr/build/zephyr/zephyr.hex' -c 'reset run' -c shutdown

那还怎么搞??
没办法了,但应该只是差一点,突然想到直接命令行时,人家可没有那么啰嗦,直接上面两行就好了,所以openocd.cfg这个文件下一堆东西你是干嘛的,算了全部注释掉吧,然后就成这样了:

source [find interface/cmsis-dap.cfg]
# stlink.cfg
transport select swd

source [find target/stm32f1x.cfg]

# reset_config srst_only

# $_TARGETNAME configure -event gdb-attach {
#         echo "Debugger attaching: halting execution"
#         reset halt
#         gdb_breakpoint_override hard
# }

# $_TARGETNAME configure -event gdb-detach {
#         echo "Debugger detaching: resuming execution"
#         resume
# }
```````

再试一下,天啊,终于好了,可以成功刷程序了,只需要west flash!!

Open On-Chip Debugger 0.10.0+dev-01508-gf79c90268-dirty (2021-02-16-17:45)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = �ȶ���V3
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x1ba01477
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* stm32f1x.cpu       cortex_m   little stm32f1x.cpu       unknown

target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800146c msp: 0x200007b0
Info : device id = 0x10036414
Info : flash size = 512kbytes
auto erase enabled
wrote 14336 bytes from file /home/shuiyihang/zephyrproject/zephyr/build/zephyr/zephyr.hex in 1.302360s (10.750 KiB/s)

target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08001470 msp: 0x200007b0
verified 13844 bytes in 0.326014s (41.469 KiB/s)

shutdown command invoked

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值