PlatformIO Community

[MBED 6.6.0] Upload/Debug issues with J-LINK or ST-LINK

The solution has been merged, please update your ststm32 platform:
pio platform update ststm32

Old message:

Hi Everyone,

Quick info about debugging while using MBED OS 6.6.0 framework with PlatformIO.

You may run into this kind of error while using a J-LINK probe:

PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
Setting breakpoint @ address 0x080079D8, Size = 2, BPHandle = 0x0001
Starting target CPU...
ERROR: Cannot read register 15 (R15) while CPU is running
Reading all registers
ERROR: Cannot read register 0 (R0) while CPU is running
ERROR: Cannot read register 1 (R1) while CPU is running
ERROR: Cannot read register 2 (R2) while CPU is running
.......
ERROR: Cannot read register 60 (FPS27) while CPU is running
ERROR: Cannot read register 61 (FPS28) while CPU is runnWARNING: Failed to read memory @ address 0xDEADBEEE
Signal: SIGTRAP (Trace/breakpoint trap)
Reading 64 bytes @ address 0xDEADBEC0
WARNING: Failed to read memory @ address 0xDEADBEC0
WARNING: Failed to read memory @ address 0xDEADBEEE
Reading 64 bytes @ address 0xDEADBAC0
WARNING: Failed to read memory @ address 0xDEADBAC0
WARNING: Failed to read memory @ address 0xDEADBAEE
WARNING: Failed to read memory @ address 0xDEADBEEE

Program received signal SIGTRAP, Trace/breakpoint trap.
0xdeadbeee in ?? ()

Or this kind of error while using ST-LINK probe:

Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32l4x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 300ms
Info : Previous state query failed, trying to reconnect
target not halted
target stm32l4x.cpu was not halted when resume was requested
Previous state query failed, trying to reconnect
jtag status contains invalid mode value - communication failure
Error: jtag status contains invalid mode value - communication failure
Polling target stm32l4x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 700ms
Warn : keep_alive() was not invoked in the 1000 ms timelimit. GDB alive packet not sent! (18439 ms). Workaround: increase "set remotetimeout" in GDB
Warn : target not halted
Info : target stm32l4x.cpu was not halted when resume was requested
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Previous state query failed, trying to reconnect
jtag status contains invalid mode value - communication failure
Signal: 0 (Signal 0)
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Warn : target stm32l4x.cpu is not halted (gdb fileio)
Polling target stm32l4x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 1500ms

Long story short: it seems that a feature introduce in MBED 6.6.0 (gpio full reset at init) break SWD connection of theses probes while debugging. At least I think so, but maybe I am wrong. And maybe other probes are affected as well.

If you absolutely need to debug right now with PIO and MBED 6.6.0, and don’t want to rollback to MBED 6.2.0 PIO package, you can temporarily fix the problem by edit theses two files in your PIO mbed framework folder, since the fix has not been merged yet on MBED official repository:

  • Replace .platformio\packages\framework-mbed\targets\TARGET_STM\mbed_overrides.c by this one.
  • Replace .platformio\packages\framework-mbed\targets\targets.json by this one.

This will disable the feature. You may need to do a PIO CLEAN command after editing these files, before building again. And you may need to keep RESET button pushed on you boards before flashing your program again.

Another solution would be to edit mbed_app.json file and add this, but for some reason it didn’t work on my side either.

Original post on MBED forum here.

PS: Keep in mind this is a temporary solution, to get debugging working with PIO mbed package 6.60600.201227. When MBED and PIO will do the update, everything should work like before.

1 Like

Thanks for the info, it boggles my mind how that reset-all-gpio-on-startup PR got approved without thinking about that o_o.

Yup, and this is the kind of thing that can pass all building tests without problems ^^ I don’t know if it is possible to simulate a debugging connection while testing Mbed framework builds, that could be great to detect this kind of issue (but maybe too much complex to develop, and too much different probes on the market).

I didn’t try with a classic JTAG connection, maybe it works in this case. Anyway PR author rapidly found the problem, and that is great. I hope it will be merged soon, it drives me crazy for a few days after not being able to debug a simple nucleo.

PR has been merged, and @valeros just update the PIO package.

If you encounter this issue, please update ststm32 PIO platform:
pio platform update ststm32