刚拿到一块nrf52840的板子,为了方便以后的开发,先搭建一个调试环境,为方便以后回忆记录一下过程。
提示:以下是本篇文章正文内容,下面案例可供参考
1.msys2命令行调用jlink工具
将jlink工具路径加入msys2的PATH,在MSYS2 UCRT64中使用下面命令。
$ echo 'export PATH="/c/Program Files/SEGGER/JLink_V794e:$PATH"' >> ~/.bashrc
$ source ~/.bashrc
这个~/.bashrc是打开MSYS2 UCRT64时要首先运行的命令。
2、开启jlink GDB Server
在MSYS2 UCRT64中使用下面命令:
$ JLinkGDBServerCL.exe -device nrf52832_xxaa -if swd -port 2331
得到下面log,应该是服务开启了。
3.用gdb-multiarch连接gdb server
新开一个MSYS2 UCRT64输入如下命令:
$ gdb-multiarch
(gdb) set architecture arm
(gdb) target remote localhost:2331
这个2331就是刚刚用jlink gdb server设置的端口号,下面是我的运行结果:
qjqadams@DESKTOP-T7T738U UCRT64 /
$ gdb-multiarch
GNU gdb (GDB) 15.2
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) set architecture arm
warning: A handler for the OS ABI "Windows" is not built into this configuration
of GDB. Attempting to continue with the default arm settings.
The target architecture is set to "arm".
(gdb) target remote localhost:2331
Remote debugging using localhost:2331
warning: A handler for the OS ABI "Windows" is not built into this configuration
of GDB. Attempting to continue with the default arm settings.
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x00029fc2 in ?? ()
(gdb) ls
Undefined command: "ls". Try "help".
(gdb) n
Cannot find bounds of current function
(gdb) n
Cannot find bounds of current function
(gdb) n
Cannot find bounds of current function
(gdb) c
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00029fc4 in ?? ()
(gdb) ir
Undefined command: "ir". Try "help".
(gdb) i r
r0 0x8000 32768
r1 0x2000 8192
r2 0x50000000 1342177280
r3 0x4e4bb7 5131191
r4 0x4000 16384
r5 0x0 0
也可以在打开gdb-multiarch的时候传入调试文件,gdb-multiarch能够自动判断出芯片架构并设置,如下:
$ gdb-multiarch.exe ./_build/nrf52840_xxaa.out
(gdb) show architecture
The target architecture is set to "auto" (currently "armv7e-m").
连接上jink gdb server,调试调试,list一下看看c代码。
(gdb) target remote localhost:2331
(gdb) list
36 counter = 100000;
37 while(counter--);
38 nrf_gpio_pin_clear(LED_1);
39 __asm__("nop");
40 counter = 100000;
41 while(counter--);
42 nrf_gpio_pin_set(LED_1);
43 __asm__("nop");
44
45 // led_map = !led_map;
(gdb)
参考
Using GDB with Nordic devices
gdb调试arm:gdb-multiarch gdbserver coredump