Introduction

This chapter describes the three debugging modes supported by the development board.

  • GDB Debug

    • Run on the host directly and communicate with the target device via GDB Server.

    • Support using the .axf file to set breakpoints at the corresponding source code locations.

  • Jlink Debug

    • Support halting the CPU and obtaining the current CPU status directly.

    • Allow direct access to the target device’s memory.

  • Ozone Debug

    • Provide graphical user interface debugging operations.

Hardware Connection

Refer to the following diagram to connect JLink’s SWCLK and SWDIO to the SoC’s SWD CLK and SWD DATA, then connect JLink to the PC.

../../rst_rtos/0_gdb_debug/figures/connecting_jlink_to_swd.svg

Wiring diagram of connecting JLink to SWD

Note

The JLink version must be v9 or higher.

GDB Debug

GDB Software Connect and Configure

  1. Download and install the latest GDB Server from SEGGER official website

  2. Edit the corresponding xxx_jlinkGDBSever.bat to adjust the path of JLinkGDBServer.exe

Connect JLinkGDBSever

Double-click {SDK}\amebadplus_gcc_project\utils\jlink_script\cm4_jlinkGDBSever.bat. As shown below, confirm successful connection between KM4 and JLinkGDBSever:

../../rst_rtos/0_gdb_debug/figures/dplus_windows_km4_jlink_gdb_server_connection.png

Caution

  • Keep this window open for subsequent operations

GDB Download Image

We recommend using Realtek’s Image Tool software for firmware download. For more information, please refer to Image Tool.

If you must use JLinkGDBSever to download the firmware, please follow the instructions below:

  1. Compile the image (refer to Building Code) and connect JLink

  2. Enter the build.py -gdb command to start the download. The firmware will be downloaded to Flash, and take RTL8721Dx as an example, as shown below:

    Breakpoint 1, Gdb_Floader_Program_Start () at .amebadplus_gcc_project/project_km4/asdk/flashloader/rtl_flash_download.c:36
    36      in .amebadplus_gcc_project/project_km4/asdk/flashloader/rtl_flash_download.c
    flash_write FileName:3
    flash_write FileSize:0
    Loopnumber = 0
    TailSize = 0
    global variables
    FlashDatSrc:3000a754
    FlashBlockWriteSize:800
    Flash write start...
    
    Breakpoint 2, Gdb_Floader_Program_End () at .amebadplus_gcc_project/project_km4/asdk/flashloader/rtl_flash_download.c:45
    45      in .amebadplus_gcc_project/project_km4/asdk/flashloader/rtl_flash_download.c
    dump for check
    
  3. Confirm the firmware

select verify download before downloading. During the firmware download, there will be a verified OK log prompt.

../../rst_rtos/0_gdb_debug/figures/windows_verify_download.png
  1. After the download is complete, press the Reset button to see the device boot with the new firmware.

Debug Mode Entry Process

  1. Build Image and Connect JLinkGDBSever

  2. Execute Debug Commands

    1. Navigate to SDK root directory

    2. Run build.py -debug to enter GDB mode, take RTL8721Dx as an example, as shown below:

    GDB CMD :  cd E:\sdk0508\amebadplus_gcc_project\project_km4/asdk && C:/rtk-toolchain/asdk-10.3.1-4365/mingw32/newlib/bin/arm-none-eabi-gdb.exe -x E:\sdk0508\amebadplus_gcc_project\project_km4/asdk\gnu_utility/gnu_script\rtl_gdb_debug.txt
    GNU gdb (Realtek ASDK-10.3.1 Build 4365) 12.1.90.20221114-git
    Copyright (C) 2022 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-w64-mingw32 --target=arm-none-eabi".
    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.
    0x3000a304 in ?? ()
    Notification of completion for asynchronous execution commands is off.
    (gdb)
    

GDB Debugger Guide

GNU Debugger enables runtime state inspection and error tracing (Reference: Debug Mode Entry Process)

Complete documentation: GDB User Manual

Functional command reference

Function Module

Command

Operation Guide

Breakpoint Management

break (b)

Set execution pause points

Data Watchpoints

watch

Monitor variable changes (watch/rwatch/awatch)

Breakpoint List

info

Display active breakpoints/watchpoints

Breakpoint Removal

delete (d)

Remove specified breakpoint

Execution Resume

continue (c)

Continue program execution

Step Into

step (s)

Enter function execution

Step Over

next (n)

Execute current line and jump to next

Debug Session Exit

quit (q)

Terminate debugging session

Call Trace

backtrace (bt)

Display function call stack

Source Code View

list (l)

Display contextual code

Data Inspection

print (p)

Output variable/expression values

Note

  • Recommended watch scope <20 bytes.

Ozone Debug

Ozone Software Installation

Download and install the latest version of JLink and Ozone from the official SEGGER website.

Ozone Project Configuration

Create, save, and run projects.

Connect JLink and launch Ozone to create a new project by following steps:

  1. Enter the main interface and create a new project, as shown below:

../../rst_rtos/0_gdb_debug/figures/ozone_creat_project.png
  1. Select the target device and svd file, as shown below:

../../rst_rtos/0_gdb_debug/figures/ozone_choice_device.png
  1. Configure connection settings: choose the interface and confirm the JLink device, as shown below:

    ../../rst_rtos/0_gdb_debug/figures/ozone_conection_setting.png
  2. Select the debug file, as shown below:

../../rst_rtos/0_gdb_debug/figures/ozone_choose_debugged_program.png
  1. Set initialization options

    • Initialization settings: Set Initial PC and Stack Pointer to Do not set.

    • Select the corresponding JLinkScript file from the amebaxxxx_gcc_project/utils/jlink_script directory, as shown below:

../../rst_rtos/0_gdb_debug/figures/ozone_inital_setting.png
  1. Handle Plugin installation warning

    • Install: Click Apply to install automatically. The installation result will be shown in the Console window.

    • Do not install: Click Continue to proceed without installing.

../../rst_rtos/0_gdb_debug/figures/ozone_plugin_diagnostics.png
  1. Project created successfully

Ozone Debug Features

In this section, commonly used debug features are introduced. Click View to see the debug functions supported by Ozone.

  1. Adding Breakpoints

    • Code breakpoint: In the C file opened in the File Scope area, click the gray dot to the left of the code line to add a breakpoint.

    • Data breakpoint: In the Break & TracePoints window, right-click on a blank area and use the drop-down menu to add a breakpoint by variable name or address. Alternatively, right-click a variable name in the global or local variable window and select the option to add it as a breakpoint.

  2. Removing Breakpoints

    • Code breakpoint: Click the red dot to the left of the code line. When it changes to a gray dot, the breakpoint is removed.

    • In the Break & TracePoints window: Right-click on a blank area and use the drop-down menu to remove a breakpoint.

    • Enable/disable: In the Break & TracePoints window, click to the left of the breakpoint to enable or disable it.

  3. Viewing Breakpoints

    • When the program reaches a breakpoint, it will pause and the corresponding line of code will be highlighted in green, as shown below:

    ../../rst_rtos/0_gdb_debug/figures/ozone_breakpoints_setting.png

    Caution

    • The number of breakpoints that can be set is limited. If exceed this limit, the following error message will appear SetBreakpoint: JLINK API call failed.

Ozone Command Set

The Ozone debugger supports checking program status and tracing errors during execution. To view all available commands, enter help in the Console window.

Official documentation reference: Ozone User Manual