1.問題定位
ubuntu下開發(fā)GD32杏慰,通過vscode的插件cortex-debug+openocd+GD-Link調(diào)試GD32遇到問題。問題如下:
openocd -s "/opt/openocd-0.12.0-4/openocd/scripts/" -f "./openocd/gd32f470_cmsis_dap.cfg"
xPack Open On-Chip Debugger 0.12.0+dev-01685-gb9224c0c0-dirty (2024-08-02-19:50)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: unable to open CMSIS-DAP device 0x28e9:0x58f
Error: unable to find a matching CMSIS-DAP device
使用sudo命令是沒找到openocd命令,將openocd加入sudo的環(huán)境變量中阱冶。
sudo visudo
找到 secure_path 配置行混稽,在其后增加/opt/openocd-0.12.0-4/bin
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/opt/openocd-0.12.0-4/bin"
執(zhí)行openocd命令連接GD_Link調(diào)試器,用sudo權(quán)限:
sudo openocd -s "/opt/openocd-0.12.0-4/openocd/scripts/" -f "./openocd/gd32f470_cmsis_dap.cfg"
xPack Open On-Chip Debugger 0.12.0+dev-01685-gb9224c0c0-dirty (2024-08-02-19:50)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD DPIDR 0x2ba01477
Info : [gd32f4xx.cpu] Cortex-M4 r0p1 processor detected
Info : [gd32f4xx.cpu] target has 6 breakpoints, 4 watchpoints
Info : [gd32f4xx.cpu] Examination succeed
Info : [gd32f4xx.cpu] starting gdb server on 3333
Info : Listening on port 3333 for gdb connections
不用sudo權(quán)限時
openocd -s "/opt/openocd-0.12.0-4/openocd/scripts/" -f "./openocd/gd32f470_cmsis_dap.cfg"
xPack Open On-Chip Debugger 0.12.0+dev-01685-gb9224c0c0-dirty (2024-08-02-19:50)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: unable to open CMSIS-DAP device 0x28e9:0x58f
Error: unable to find a matching CMSIS-DAP device
查看cmsis-dap設(shè)備的權(quán)限岩喷,cmsis-dap是hid設(shè)備,在/dev下表現(xiàn)為hidraw*
ls -l /dev/hidraw*
crw------- 1 root root 241, 0 11月 15 18:46 /dev/hidraw0
crw------- 1 root root 241, 1 11月 15 19:33 /dev/hidraw1
確實只有root權(quán)限监憎。
2.修改設(shè)備權(quán)限
2.1創(chuàng)建 udev 規(guī)則
在 /etc/udev/rules.d/ 目錄下創(chuàng)建一個新的 udev 規(guī)則文件纱意,如 99-cmsis-dap.rules,并將以下內(nèi)容添加到該文件中鲸阔。
sudo vim /etc/udev/rules.d/99-cmsis-dap.rules
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="28e9", ATTRS{idProduct}=="058f", MODE="0666"
xendless@ubuntu22:~/ohos/openharmony-4.1-release$ lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 008: ID 28e9:058f GDMicroelectronics CMSIS-DAP
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
28e9:058f中28e9為idVendor偷霉,258f為idProduct。
2.2重載 udev 規(guī)則: 創(chuàng)建完規(guī)則后褐筛,重新加載 udev 規(guī)則:
sudo udevadm control --reload-rules
重新插拔cmsis-dap調(diào)試器类少。
ls -l /dev/hidraw*
crw------- 1 root root 241, 0 11月 15 18:46 /dev/hidraw0
crw-rw-rw- 1 root root 241, 1 11月 15 19:50 /dev/hidraw1
權(quán)限發(fā)生變化。
再次執(zhí)行openocd命令
openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /opt/openocd-0.12.0-4/openocd/scripts -f /home/xendless/.vscode-server/extensions/marus25.cortex-debug-1.12.1/support/openocd-helpers.tcl -f /home/xendless/ohos/openharmony-4.1-release/openocd/gd32f470_cmsis_dap.cfg
xPack Open On-Chip Debugger 0.12.0+dev-01685-gb9224c0c0-dirty (2024-08-02-19:50)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
DEPRECATED! use 'gdb port', not 'gdb_port'
DEPRECATED! use 'tcl port' not 'tcl_port'
CDLiveWatchSetup
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD DPIDR 0x2ba01477
Info : [gd32f4xx.cpu] Cortex-M4 r0p1 processor detected
Info : [gd32f4xx.cpu] target has 6 breakpoints, 4 watchpoints
Info : [gd32f4xx.cpu] Examination succeed
Info : [gd32f4xx.cpu] starting gdb server on 50000
Info : Listening on port 50000 for gdb connections
問題解決渔扎。
3.總結(jié)
問題出在cmsis-dap設(shè)備只有root權(quán)限硫狞,沒有用戶權(quán)限。
4.測試
之后按F5進入調(diào)試狀態(tài)晃痴。
相關(guān)的.cfg文件見git倉庫
雖然寫的有點隨意残吩,如果覺得有用,幫忙點個贊倘核,感謝泣侮!