[Tutorial] Debugging RTL8722 with the new Arduino IDE

Disclaimer


As of this writing, the new Arduino IDE is still in beta, features and functionality may be changed or removed without warning, and is not indicative of the final release version.

Requirements


Hardware:
RTL8722 development board
SEGGER JLink debug probe (J-Link Debug Probes by SEGGER – the Embedded Experts)
Software:
Arduino IDE 2.0 beta (https://www.arduino.cc/en/software)
SEGGER JLink Software Pack (SEGGER - The Embedded Experts - Downloads - J-Link / J-Trace)

Setup


  1. Install Arduino IDE 2.0 beta. Debugging has been tested with the Arduino IDE 2.0.0-beta.8. Older versions may not work properly. Instructions on installing Arduino IDE 2.0 can be found at https://docs.arduino.cc/software/ide-v2/tutorials/getting-started/ide-v2-downloading-and-installing.

Note: Arduino IDE 2.0 can coexist with the old Arduino IDE. Any changes made to boards or libraries will affect both IDE versions.

  1. Install SEGGER JLink Software Pack. Debugging has been tested with JLink software V7.50.

For Windows users: this process assumes that the 64-bit version of JLink software is installed in the default directory of C:\Program Files\SEGGER.

  1. In the Arduino IDE 2.0 menu, in File → Preferences → Additional boards manager URLs , copy and paste the following address: https://raw.githubusercontent.com/Aurical/ambd_arduino/master/Arduino_package/package_realtek.com_amebad_early_index.json

  2. In Tools → Board → Boards Manager , find and install the board support package for Realtek Ameba RTL8722DM/RTL8722CSM. Debugging has been enabled in version 3.0.9-build20210708. Note that this will overwrite any existing installs, back-up any modified files that you want to keep.

  3. In the menu near the toolbar, select the board and COM port corresponding to your evaluation board.
    3

  4. Open the example code in File → Examples → AmebaDebug_Example → ExampleDebug.

  5. Follow the comments to add in the correct folder path into the serverArgs field of the debug_custom.json file.

  6. Connect the evaluation board and JLink debug probe to your computer. Using jumper wires, connect the debug probe to the SWD pins on the evaluation board. SWD pins on the JLink debug probe can be found at J-Link Interface Description.

    JLink Debug Probe RTL8722 Evaluation Board
    VTref 3.3V
    GND GND
    SWDIO SWDIO
    SWCLK SWCLK



SWD

Debug


Refer to https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-debugger for instructions on how to use the Arduino IDE debug interface.

  1. Before debugging, make sure to enable Sketch → Optimize for Debugging.
    4

  2. Compile and upload the sketch in the same way as before, using the USB to UART COM port. The RTL8722 does not support program download using the debug probe yet.
    5

  3. After uploading is complete, reset the board and you can start debugging by clicking on the debug icon near the upload icon. You should see program execution stop, and a yellow highlight on the first line of code in the setup function, this indicates the next line of code to be executed by the processor.

Note: The RTL8722 only has 2 hardware breakpoint registers. These will be used up when you set breakpoints. Trying to set too many breakpoints will cause debugging to fail, the output tab will show “WARNING: No more breakpoint resources left”, and you may see a red bar across the code as shown. You may need to stop debugging and reset when this happens.

Note: Using any of the single-stepping functionality (step over, step into, step out) requires that both hardware breakpoint resources are free. You should remove or disable all existing breakpoints before using them.
8

2 Likes

Hi. To help others.

This is my debugger:

Firmware: J-Link EDU Mini V1 compiled Jun 24 2021 14:29:39
Hardware: V1.00

This is my debug_custom.json

{
 "servertype": "jlink",
 "interface": "swd",
 "device": "RTL872xCS",
 "serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL.exe"
}

This is my launch.json (Generated)

{
  "version": "0.2.0",
  "configurations": [
    {
      "cwd": "${workspaceRoot}",
      "name": "Arduino",
      "request": "launch",
      "type": "cortex-debug",
      "executable": "C:\\Users\\ajsb85\\AppData\\Local\\Temp\\arduino-sketch-468C564005883B4DF820103161969518/application.axf",
      "servertype": "jlink",
      "serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL.exe",
      "armToolchainPath": "C:\\Users\\ajsb85\\AppData\\Local\\Arduino15\\packages\\realtek\\tools\\ameba_d_asdk_toolchain\\1.0.1/bin/",
      "configFiles": [
        null
      ],
      "interface": "swd",
      "device": "RTL872xCS"
    }
  ]
}


image

1 Like

Great! THanks for sharing!

I have a JLINK mini too, was wondering how to get started debugging with it just a while ago~:laughing::+1:

1 Like