2.7. GDB 调试

2.7.1. 工具介绍

工具

说明

T-HeadDebugServer

运行 GDB Server

AiBurn

镜像烧写工具

AIC-JTAG

AIC 调试器

JTAG - SDMC 转接线

仅用于调试器连接 SDMC 接口使用

Eclipse

适配 Luban-Lite SDK 的 IDE

riscv64-unknown-elf-gdb.exe

调试工具,位于 $(SDK)tool/riscv64-gdb/bin/

d21x.elf

Eclipse 工程目录下生成的符号链接表

2.7.2. 准备工作

  • 安装 T-HeadDebugServer(以下简称 DebugServer)

安装包也带有 AIC-JTAG 的驱动,随下面安装过程一并安装

解压,运行 setup.exe,在弹出页面中,点击Next:

../../_images/install_11.png

在用户协议界面中点击Yes:

../../_images/install_21.png

在安装路径页面,可以自行修改:

../../_images/install_41.png

在安装内容页面,建议全选,继续点Next:

../../_images/install_51.png
../../_images/install_61.png

等待完成安装后,桌面会自动创建了一个 DebugServer 的图标:

../../_images/install_71.png
  • 将 AIC 调试器通过 USB-TypeC 连接 PC

  • 成功识别后,AIC 调试器绿灯会亮起

../../_images/run_11.png
../../_images/cklink_detected1.png

2.7.3. SDK 配置

Luban-Lite SDK 支持两种硬件接口进行调试,分别是 JTAG 和 SDMC 口。 为避免 GPIO 冲突,需要对 ddr_init.jsonxxx_defconfig 进行配置。

注意

进行配置前,需确保已经加载目标工程。

下面将针对两种接口的连接和配置分别讲解。

2.7.3.1. 使用 JTAG 口

2.7.3.1.1. 配置接口

  • 运行

scons --menuconfig
  • 关闭 I2C、 以及Touch panel

Board options  --->
    [] Using i2c3
Drivers options  --->
    Peripheral  --->
        Touch Panel Support  --->
            Gt911 touch panel options  --->
                [] Using touch panel gt911

注意

若使用 JTAG 口,另外需断开 CTP 触屏排线

../../_images/CTP_disconnected1.png

2.7.3.2. 使用 SD调试 口

2.7.3.2.1. 修改文件

打开 target/<CPU>/<board>/pack/ddr_init.json ,配置 jtag_only 和调试口引脚:

"jtag": {
    "jtag_only": "1", // 1: Boot code stop in PBP after DDR init and jtag init
    "main": {
        "jtag_id": "0",
        //"jtag_do_pin_cfg_reg": "0x187000A0", // PA8
        //"jtag_do_pin_cfg_val": "0x336",
        //"jtag_di_pin_cfg_reg": "0x187000A4", // PA9
        //"jtag_di_pin_cfg_val": "0x336",
        //"jtag_ms_pin_cfg_reg": "0x187000A8", // PA10
        //"jtag_ms_pin_cfg_val": "0x336",
        //"jtag_ck_pin_cfg_reg": "0x187000AC", // PA11
        //"jtag_ck_pin_cfg_val": "0x336",

        "jtag_do_pin_cfg_reg": "0x1870028C", // PC3
        "jtag_do_pin_cfg_val": "0x336",
        "jtag_di_pin_cfg_reg": "0x18700284", // PC1
        "jtag_di_pin_cfg_val": "0x336",
        "jtag_ms_pin_cfg_reg": "0x18700280", // PC0
        "jtag_ms_pin_cfg_val": "0x336",
        "jtag_ck_pin_cfg_reg": "0x18700294", // PC5
        "jtag_ck_pin_cfg_val": "0x336",
    },
},

2.7.3.2.2. 配置接口

  • 运行

scons --menuconfig
  • 关闭SDMC1

Board options  --->
        [] Using SDMC1

2.7.4. 连接开发板

  • 编译 SDK

  • 使用 AiBurn 烧录编译生成的镜像(参见烧录章节)

  • 开发板连接串口、AIC-JTAG、电源线

../../_images/debug_jtag1.png

图 2.49 开发板连接 JTAG 接口

../../_images/debug_SDMC1.png

图 2.50 开发板连接 SDMC 接口

  • 在调试串口终端中,按住 Ctrl + C,同时重启开发板,串口打印如下:

Pre-Boot Program ... (2023-08-08 11:29:35 13a563f)
No DDR info
Going to init DDR2. freq: 504MHz
DDR2 initialized
120186 134875 162258
PBP done

tinySPL [Built on Aug 21 2023 17:12:58]
Boot device = 5(BD_SPINAND)
nand read speed: 1346320 byte, 76998 us -> 17075 KB/s
aic@tinySPL #
aic@tinySPL #
  • 运行 DebugServer,首次运行会有安全警告,点击“允许访问”

../../_images/run_01.png
  • 配置 DebugServer,Setting -> Target Setting

../../_images/run_21.png
  • 配置 DebugServer 的端口号

../../_images/debug_server3.png
  • 启动仿真器连接,显示本地 IP 及已配置的端口(3333),则表示连接成功:

../../_images/connected1.png
  • 连接成功后,即可通过 IDE 或命令行进行调试

2.7.5. 调试

2.7.5.1. Windows 下使用 Eclipse 调试

采用 Eclipse 配合 GDB 的调试方案,方便用户上手

注意

使用 Eclipse 调试前,需先按照 1.4 Eclipse 章节,完成 Eclipse 工程导入及编译

  • 配置 Debug Configurations - Main

../../_images/eclipse_gdb_config1.png
  • 配置 Debug Configurations - Debugger

../../_images/eclipse_gdb_config21.png
  • Eclipse 进入 Debug 模式

../../_images/eclipse_into_debug_mode1.png
  • Eclipse 调试常用快捷键

    1. F5:单步进入,进入函数内部

    2. F6:下一行代码,逐行执行

    3. F7:返回值调用处的下一行代码

    4. F8:继续运行,跳过当前中断点

    5. F11:调试并启动程序

2.7.5.2. Linux 下使用 GDB 调试

注意

在 Linux 下调试前,需确保与 DebugServer 所在的 Windows 系统可以 ping 通。

  • 在 SDK 根目录编写 jtag-debug.sh 脚本:

$cat jtag-debug.sh

target remote 172.16.31.141:3333    #此处 IP 为 DebugServer 运行 PC的 IP,端口为 DebugServer 配置的端口

load ./output/d13x_demo88-nor_rt-thread_helloworld/images/d13x.elf  # 对应项目的 elf文件
file ./output/d13x_demo88-nor_rt-thread_helloworld/images/d13x.elf
  • 在 SDK 根目录下运行 GDB :

$ ./toolchain/bin/riscv64-unknown-elf-gdb -x ./jtag-debug.sh
GNU gdb (Xuantie-900 elf newlib gcc Toolchain V2.6.1 B-20220906) 10.0.50.20200724-git
Copyright (C) 2020 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 "--host=x86_64-pc-linux-gnu --target=riscv64-unknown-elf".
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".
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x0000000000106b3a in ?? ()
Loading section .text, size 0xa4780 lma 0x40000100
        sectio--Type <RET> for more, q to quit, c to continue without paging--
--Type <RET> for more, q to quit, c to continue without paging--
        section progress:  41.5%, total progress:   inf%
        section progress:  46.2%, total progress:   inf%
        section progress:  50.4%, total progress:   inf%
        section progress:  53.9%, total progress:   inf%
        section progress:  63.3%, total--Type <RET> for more, q to quit, c to continue without paging--
        section progress:  93.5%, total progress:   inf%--Type <RET> for more, q to quit, c to continue without paging--
        section progress: 100.0%, total progress:   inf%
Loading section .rodata, size 0x843b8 lma 0x400a4880
        section progress:  27.7%, total progress:   i--Type <RET> for more, q to quit, c to continue without paging--
        sect--Type <RET> for more, q to quit, c to continue without paging--
        section progress: 100.0%, total progress:   inf%
Loading section .data, size 0x32e0 lma 0x40128c40
--Type <RET> for more, q to quit, c to continue without paging--
        section progress: 100.0%, total progress:   inf%
Start address 0x0000000040000100, load size 1228312
Transfer rate: 107 KB/sec, 3988 bytes/write.

显示以上信息,表示已经进入 GDB 调试模式。