Arduino UNO R4 WiFi Debugging

It appears that debugging support was recently added to the Arduino IDE 2 and the Arduino R4 Boards package for the UNO R4 WiFi board, however, I get the following error when trying to enable debugging within the IDE.

embedded:startup.tcl:26: Error: Can't find interface/{programmer.protocol}.cfg in procedure 'script' at file "embedded:startup.tcl", line 26

Furthermore, I understand that a separate hardware debugger is not required with the UNO R4 WiFi as that capability is provided by the on-board ESP32-S3 module.

Am I missing something or is the debugging not yet supported for this board?

Hi @woolsey.

Select Tools > Programmer > ARM CMSIS-DAP compatible from the Arduino IDE menus and then try again. This time the debugger should start up and work as expected.

The cause for the error was that you didn't have anything selected from this Tools > Programmer menu. The menu was traditionally used to configure the IDE for use with an ISP programmer. Prior to Arduino IDE 2.3.0, by default a board was configured for a specific debug probe and the procedure required to configure it for any other debug probe was quite complex. It is now possible for boards platform authors to offer configurations for a variety of different debug probes, which the user can pick from by selecting the probe they have from the Tools > Programmer menu.

That is correct!

It is supported.

Thank you for the prompt reply.

I set the programmer and I seem to be getting a little further along now, but am still getting some errors and a lot of strange behavior.

"OpenOCD: GDB Server Quit Unexpectedly. See gdb-server output for more details." where the gdb-server output shows the original error I posted.

"Unable to parse SVD file /Users/woolsey/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.1.0/svd/R7FA4M1AB.svd: Error: SVD error: Invalid 'derivedFrom' "P100PFS" for register "P30%sPFS""

Sometimes the debug session seems to run and I land at a breakpoint and sometimes it seems nothing happens. Sometimes the code stops at a breakpoint sometimes it stops on the line after the breakpoint. If the session does seem to work, sometimes stepping through the code works sometimes it doesn't. The Continue, Step Over, Step Into, Step Out operations don't seem to function as expected. For example, trying to step over a digitalWrite() call will drop me into a tusb_fifo.c file.

I am getting a lot of strange results and nothing seems to be reproducible.

This bug is being tracked by the Arduino IDE developers here:

A fix is already in progress:

From my simple experiments using the debugger with my UNO R4 WiFi board, the bug doesn't appear to have any effect on the basic functionality of the debugger so my advice is to simply close the notification when it appears and carry on.

Did you select Sketch > Optimize for Debugging from the Arduino IDE menus before you uploaded your sketch to the board? Normally we configure the compiler to aggressively optimize the program in order to make it run on the board more efficiently (in terms of clock cycles and/or memory usage). But that aggressive optimization can cause the generated binary program to differ so significantly from the source code that the debugger is not able to produce usable results. So when debugging we dial down the optimization level. This is the function of the Sketch > Optimize for Debugging menu item in Arduino IDE.

I did try the Optimize for Debugging option, but it did not seem to make much of a difference. It does seem to stop at the actual breakpoints now when using the Continue button, but it does not appear to step through the code properly when using the stepping buttons.

I really appreciate your assistance, but perhaps I should just wait until a the issues you mentioned are fixed and try again at a later time.

It's great to see there is now debugging support for the Uno R4 WIFI. Does anyone know if this is supported in VS Code? I have looked for tutorials in general and all seem to be very out of date, so would appreciate any guidance on how to debug the project I have with it.

Do you use Arduino by Microsoft or PlatformIO?
I don't have experience with the Microsoft version, but for PlatformIO you can update R7FA4M1AB.svd located somewhere in your PlatformIO install directory. (Sorry, I forgot the exact location.)

I'm using the Microsoft extension. Is there much advantage to the platformIO extension in general? I assume you can have either one or the other active, but not both, is that the case?

I'm sorry but I only tried PlatformIO a little when the original Arduino IDE editor was poor, but now I'm a user of the genuine Arduino IDE, so I can't say for sure which is better, Microsoft or PlatformIO.

Is there anyone who knows more about this?

I could switch to the v2 Arduino IDE. Do you know if when debugging can you attach to the board when it's running and switch to single step to see where the program counter is? My use case is i have an application that has wifi, mqtt, SPI and a bunch of other stuff, and after a few days it hangs. So I want to attach to the board when it has hung and find where in the code and call stack it's happening... So I don't mind which IDE I use as long as I can do something like that...

Your question is getting a bit off-topic from the original questioner, so I would recommend starting a new thread, where you'll likely get a better answer.

What are the steps to get debugging working on the UNO R4 WiFi?

I selected the ARM CMSS-DAP compatible in the Programmers menu, but when clicking the debug button, I get the error

OpenOCD: GDB Server Quit Unexpectedly. See gdb-server output for more details.

However, the gdb-server output doesn't show any error:

[2024-09-26T21:33:37.580Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session connected. You can switch to "DEBUG CONSOLE" to see GDB interactions.
"C:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\openocd\\0.11.0-arduino2/bin/openocd" -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s "s:\\Arduino\\tacho1" -f "C:/Users/Peter/AppData/Local/Programs/arduino-ide/resources/app/plugins/cortex-debug/extension/support/openocd-helpers.tcl" -f interface/cmsis-dap.cfg -f "C:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.2.1/debugger/select_swd.cfg" -f "C:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.2.1/debugger/R7FA4M1AB.cfg"
Open On-Chip Debugger 0.11.0+dev-gab95bac57-dirty (2021-05-11-10:45)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
CDRTOSConfigure
swd
adapter speed: 1000 kHz

Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
[2024-09-26T21:33:37.658Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...

version info (very latest)

Version: 2.3.3
Date: 2024-09-25T09:41:18.242Z
CLI Version: 1.0.4

Copyright ยฉ 2024 Arduino SA

Try the followings:

  1. Activate Optimize for Debugging in Sketch on IDE menu.
  2. Re-compile and upload.
  3. Close all the gdb-server console if you have opened. If you already start gdb-server, push Stop button on Debug window (top left in IDE).
  4. Try Start Debugging.

Then I get:

Open On-Chip Debugger 0.11.0+dev-gab95bac57-dirty (2021-05-11-10:57)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
CDRTOSConfigure
swd
adapter speed: 1000 kHz

Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Serial# = 123456789101112
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x5ba02477
Info : ra4m1.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for ra4m1.cpu on 50000
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
target halted due to debug-request, current mode: Thread 
xPSR: 0x81000000 pc: 0x00004278 msp: 0x20007ec8
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00001f34 msp: 0x20003990
force hard breakpoints

Mine is same as yours.

Thanks for the info!

Unfortunately, nothing seems to work. I updated the firmware, rebooted, ...

I decided to run the openocd command using Visual Studio, and it crashes with

Exception thrown at 0x00657CFF in openocd.exe: 0xC0000005: Access violation reading location 0x4F34702A.

Running with the -d flag on the command line, the last thing that is printed is

Debug: 221 596 command.c:311 register_command(): registering 'test_mem_access'...

So it seems something in on my Windows 11 PC is incompatible with openocd.exe

I will see if I can make a debug build to report a bug.

It seems that using the latest version of openocd.exe fixed the problem.

https://github.com/xpack-dev-tools/openocd-xpack/releases

I was able to set breakpoints and debug.

1 Like