arduino / ArduinoCore-mbed

347 stars 202 forks source link

Pico RP2040 - How to debug with Segger J-Link? #233

Open rei-vilo opened 3 years ago

rei-vilo commented 3 years ago

How to debug an Arduino program with the Segger J-Link?

The mbed RTOS plug-in doesn't seem to be listed among the standard options for the JLinkGDBServer.

The debugger stops at the two breakpoints...

Breakpoint 1, loop () at embed1.ino:94
94      blink(myLED, 4, 333);

Breakpoint 2, blink (pin=25 '\031', times=times@entry=4 '\004', ms=ms@entry=333, level=level@entry=true) at LocalLibrary.cpp:27
27          digitalWrite(pin, (level ^ (i % 2)) ? HIGH : LOW);

...then loops endlessly. Pausing shows the error...

Program received signal SIGTRAP, Trace/breakpoint trap.
0x1000636a in mbed_die ()

...with code

0x10006364: 10 b5               push    {r4, lr}
0x10006366: 00 f0 55 f8         bl  0x10006414 <core_util_critical_section_enter>
0x1000636a: fe e7               b.n 0x1000636a <mbed_die+6>

Thank you!

facchinm commented 3 years ago

Hi @rei-vilo , unfortunately RTX5 (the rtos used as base for mbed) is not supported by many debuggers (the only official one is https://github.com/pyocd/pyOCD ). I started to port the rtos awareness to openocd some time ago but it's still a work in progress (https://github.com/facchinm/OpenOCD/tree/rtx5). The situation, as far as I know, is:

It might change in the near future since we are in touch with Segger but I can't promise anything. If you are interested in any openocd specific build I'll be glad to send you more instructions :wink:

rei-vilo commented 3 years ago

Thank you for the detailed answer and multiple pointers.

It seems rather surprising that two industry standards, ARM mbed and Segger, haven't teamed up to bring J-Link to mbedOS.

As a matter of facts, I've already asked Segger a related question at Raspberry Pi Pico RP2040 - Cortex-M HardFault Exception.

Anyway, I'll go through the different options. I have a second Pico as picoprobe and this solution seems to be supported by the cortex-debug extension on Visual Studio Code.