Information about debugging?

Is there any information about debugging support somewhere?

I found some old blog posts and some stuff about SWD and JTAG probes, but nothing about what is supported or even how you’d find out. I’d like to use hardware debug for ESP32 and some of the SAM-based Arduino boards.

But I can’t work out what to buy or how to set it up. I know it’s beta but the last post about debugging was over a year ago.

@zapgadget

we are working on a first debugger tutorial using the Arduino Zero which has onboard debugging via EDBG.
The ESP32 is a whole other monster you'll need to do a lot of digging into.

We support a subset of our ARM based boards plus other ARM microcontrollers via advanced configuration settings.
Also depending on the platform you are using some debug features have to be implemented inside the platform.txt file so the 3rd party developer has to be in charge of this and specify which is the default debugger to use.
If that is not done on the platform side the debug button will not be enabled and a full custom launch configuration must be provided by the user

This feature is still in its infancy and we're working out how to make it more accessible but it not being a simple tool in itself we'll need quite some time to polish the whole debug approach.

For now it will work with

  • Arduino Zero via USB Programming port
  • Arduino MKR 1000 via Atmel ICE (10 pin Cortex-M debug header onboard)
  • Arduino MKR WiFi 1010 via Atmel ICE (6 SWD pads at the bottom require headers or wires)
  • Arduino Nano 33 IoT and Nano 33 BLE (5 SWD test-points at the bottom)

via custom configurations any of the above will be debuggable with J-Link, Black Magic Probe and other debug adapters

Thanks for this. It sounds like it will be really useful.

@ubidefeo
Can you please give me some pointers how to proceed. I have installed Arduino IDE v2b4, installed mbed board support, connected Nano 33 BLE Sense + Segger J-Link connected via bottom 5 SWD pins:

How do I need to proceed with the debug configuration launch.json ?

@xrk

there’s a custom debug config option which is not documented yet, but it’s in the pipeline.
for now add a file named “debug_custom.json” to your sketch folder and use this content

{
 "servertype": "jlink",
 "interface": "swd",
 "serverpath": "/usr/local/bin/JLinkGDBServer"
}

these parameters will override the ones automatically generated.
Of course your path to JLinkGDBServer might be different

Thank you for the reply.

I put a debug_custom.json in the same folder as my test Blink.ino with the following content:

{
 "servertype": "jlink",
 "interface": "swd",
 "serverpath": "C:\Program Files (x86)\SEGGER\JLink\JLinkGDBServer.exe"
}

I tried forward slashes for the path, also double forward slashes and as above backslashes (as you can take from abobe, I'm on Windows not Linux).

With all three trials though, whenever I press in Arduino IDE 2.0.0-beta.4 green play button in Debug, it just opens empty new launch.json file and nothing further happens.

Do you have any further tips?

@xrk

I don't know how to reach your JLink dbg server, but maybe this article can help you out, there's a full configuration but the part you really need is the path style.

"serverpath": "C:/Program Files (x86)/SEGGER/JLink_V687b/JLinkGDBServerCL.exe",

also first make sure that

  • you have installed the Segger JLink tools for your OS
  • you have uploaded the firmware to your board
  • you have started the debug using the debug button in the menu bar (next to compile/upload)

if there's an error you should get the debug panel to output telling you what the problem is

Thank you for the feedback.

  1. Segger J-Link is working fine. I can open J-Flash and enter nRF52840_xxAA as chip type and successfully connect to chip. Also read out the memory and so on.

  1. In your last post I take that a single forward slash should be used (so changed to that) and also that the command line version of the GDB server should be used (the one with *CL.exe at the end), so changed also to that.
  2. I see that Arduino IDE 2b4 is a 64-bit application, as it is installed under C:\Program Files, whereas Segger J-Link tools are installed under C:\Program Files (x86). I guess, C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe is thus correct (I am using v6.98, it is now installing into C:\Program Files (x86)\SEGGER\JLink\ and not as in your example into a folder with a version number).
  3. After these changes when hitting in Arduino IDE v2b4 now Verify, it for the first time complained that I need to install "Arduino Mbed OS Nano Boards by Arduino". I had "Arduino mbed-enabled Boards by Arduino" installed. Both include Nano 33 BLE in their supported boards. Which is now correct?
    Anyhow, the installer fails, as it runs as Admin, but tries to install into local user profile, where Admin by default also has no access.
    Logged in as admin (Windows is domain connected), as admin I was able to install the "Arduino Mbed OS Nano Boards by Arduino" into local user (=admin) profile.
    But now under Admin it again wants also the other board package as well. And it says, it is deprecated:

Nevertheless I am installing it then as well under admin account.

So I try there the Blink.ino program, where I put it on desktop. I again create a debug_custom.json in the same folder with following content:

{
 "servertype": "jlink",
 "interface": "swd",
 "serverpath": "C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe"
}

No change, still only empty launch.json is opened.

Any further ideas I could test?

Also for my understanding - if I use the debug_custom.json, then I should not need the launch.json at all, correct? Or should there be some content in launch.json as well?

1 Like

you being forced to run as admin shouldn't happen, I'll ask one of my colleagues to see if he can make something up about it.

I think I know what happens there.
We have to make some changes to the platform.txt of the mbed core to enable debug, otherwise the button in the menu above won't be enabled and that's what triggers the creation of a launch.json file.

If you can wait I can ask my colleague to submit a PR to enable it, otherwise if you're comfortable trying to add it yourself editing the platform.txt file (at least to test that it works) I can give you some directions.

It's useful to look at the platform.txt file from the SAMD core and pick from there the parts commented as EXPERIMENTAL

on line 18 you will need

# EXPERIMENTAL feature: optimization flags
#  - this is alpha and may be subject to change without notice
compiler.optimization_flags=-Os
compiler.optimization_flags.release=-Os
compiler.optimization_flags.debug=-Og -g3

and on line 182 you can try and add the following (don't worry if they have things which are unused, they'll be overwritten anyway by parameters in debug_custom

debug.executable={build.path}/{build.project_name}.elf
debug.toolchain=gcc
debug.toolchain.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
debug.toolchain.prefix=arm-none-eabi-
debug.server=openocd
debug.server.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}/bin/openocd
debug.server.openocd.scripts_dir={runtime.tools.openocd-0.10.0-arduino7.path}/share/openocd/scripts/
debug.server.openocd.script={runtime.platform.path}/variants/{build.variant}/{build.openocdscript}

restart the IDE to get the changes reloaded.
at that point the debug button at the top should be active

let me know how it goes, I don't have what I need handy here at home so I can't try :slight_smile:

one more thing:
if it works don't forget to enable "Sketch > optimize for debugging"

xrk:
4. After these changes when hitting in Arduino IDE v2b4 now Verify, it for the first time complained that I need to install "Arduino Mbed OS Nano Boards by Arduino". I had "Arduino mbed-enabled Boards by Arduino" installed. Both include Nano 33 BLE in their supported boards. Which is now correct?

This is the result of the 2.0.0 release that just happened a matter of hours ago. In this release, the Arduino mbed-enabled Boards platform was split into four separate platforms:

  • Nano
  • Portenta
  • RP2040
  • Edge

The idea is to make installation and compilation faster by cutting the previously very large platform down into only what is needed for a specific group of boards.

More information here:

So the installation prompt is normal and expected and completely coincidental to the debug configuration efforts you've been making.

Thank you both for your replies!

I looked for platform.txt and can find them under user profile under
AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\2.0.0
and
AppData\Local\Arduino15\packages\arduino\hardware\mbed\2.0.0

(as I wrote, I had to install both packages, no matter which one of them I choose, the IDE requested me to install the other one as well).

So I added the lines of your post to both, just in case (I also attach them for verification. To distinguish them, I appended "_nano" to the platform.txt of mbed_nano folder in the attachment).

I enabled (already previously) from Sketch menu Optimize for debugging.

The Debug button (right of "New" button) is now not grayed out anymore and I could press it. I needed to adjust Firewall and then got the info that Device Indicator is needed for Segger J-Link:

So added: "device": "nRF52840_xxAA", to debug_custom.json:

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

And this did the trick. I can pause and continue the code, put a breakpoint and do stepping.
This is great. Thank you both for your excellent help!

Update: modified the code a bit to try a variable watch. I noticed that I cannot stop and upload the modified sketch, without detaching the USB port of Nano and J-Link and reconnecting (just closing the IDE v2b4 and relaunching was not enough).
Also I just added int i and i++ into the loop and added i to watch. It says it's optimized out, thus I guess for debugging, it might be better to have optimizations off.

I tried:
compiler.optimization_flags.debug=-Og -g0
and
compiler.optimization_flags.debug=-O0 -g0
but these did not help yet (i in watch window is still not available).
Do you have tips how to turn all optimizations off for debugging so that also such simple variables remain watchable?

platform.txt (9.59 KB)

platform_nano.txt (9.6 KB)

regarding optimising variables out:
if you don't use it somewhere it will be removed by the compiler, I have tried this myself.
changing optimisation parameters doesn't seem to prevent this from happening.
I guess more work is required on this topic, but we'll get there.
The debugger is still highly experimental for us, and we learn and fix every day :slight_smile:

1 Like

hi Xrf,

May I know which J-Link model are you using ?

I am using Arduino IDE 2.0 beta5, managed to connect and debug Seeeduino Xiao with SAMD21G18 using Segger J-Link V8, the entire debugging process is documented under the video link HERE. The only think I don't understand is, the device is disconnected when the debug button is pressed.

Later, I failed to connect the Raspberry Pi Pico where there is no "Raspberry Pi Pico" listed under J-Link GDB Server table, there is no Pico device:

I simply used one of the Raspberry PI "RP2040_M0_0" it resulted connection error:

image

I noticed the above MULTI-DROP error required J-Link EDU V10 like below, are you using the one below ?

image

Any suggestion is greatly appreciated.

I used J-Link EDU Mini and tried only with Arduino Nano 33 BLE Sense. Have no experience with other combinations under Arduino IDE 2b4.

I see you are using Arduino IDE 2b5 and also very new Segger Tools v7. I used IDE 2b4 and Segger v6.98 for my tests.

xrk, thanks for the feedback.

To share some info, I noticed the J-Link EDU Mini does not supports Multi-Drop feature as it is required for RP2040 M0+ MCU like the Raspberry Pi Pico.

image

and the Segger J-Link product had so many hardware version for one product like the Segger J-Link EDU, take a look at HERE or below:

Therefore, be very careful if in the future to purchase a new Segger J-Link product.

It is a good hint that one should look at the feature table and compare it with the debugger at hand to see if the feature is enabled on the debugger at hand at all!

If buying directly from Segger or authorized distributor, I’d guess you always get the latest product. I welcome that Segger improves the hardware to accommodate new features and new chips/models as these get developed by the chip manufacturers. And there is not much Segger can do to support newer features on older models, if the hardware does not have the capability.

By looking at the compatibility table and your photo of debugger, your J-Link EDU with v10 should support SWD multi-drop. If it does not, why not post in Segger Forum to get help. You typically get a (professional) answer quickly there.

If all fails, Segger has a 50% trade-in program to swap hardware (also same model against newer model).

I just placed order at Digikey today for Segger J-Link EDU with specifically mentioned under the customer's note that it must be hardware version 10 or above otherwise just cancel the order.

Yes, you are right that Digikey is one Segger authorized distributor and the trade-in program is limited item age below 10 years.

Actually I am still new to J-Link thingie and was using a clone J-Link V8 to play around at first, until I encountered the issues with Raspberry Pi Pico, I decided to get a genuine Segger J-Link EDU :o)

I also ordered genuine Arduino Zero, is on its way now. I just want to experience the the actual behaviour of Arduino IDE 2.0 beta live debugger so I know the correct respond of it when touching other MCUs like SAMD21G18 M0, RP2040 M0+.

Thanks again.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.