PlatformIO Community

Cannot debug ledControl example of ArduinoBLE on mkr1010 with jlink plus probe

When I run ledControl example of ArduinoBLE library, is OK.
But when I debug, it stops at BLE.begin() with an exception.
Any idea about a solution?


Please file an issue at Issues · platformio/platform-atmelsam · GitHub, maybe the devs know more.

I bought the business support but I haven’t received an access yet. How do I ask for the access?
BTW the ‘stop the war’ banner is hiding the send button and I have to close the window and resume the topic to be able to press the Reply button. Not convenient.

CC @ivankravets

Indeed. Reloading the page a 3times fixes it ("Stop the war" banner makes it difficult to Reply to messages - #4 by ivankravets).

1 Like

Sorry, we will finally fix it :pray:

Do you have custom breakpoints in IDE?

No custom breakpoints

Let’s start with something simple:

  1. Could you debug the same project WITHOUT ArduinoBLE library?
  2. If “yes”, stop debugging, and open PlatformIO Core CLI and type:
pio debug --interface=gdb pio debug --interface gdb -x .pioinit

Where does it stop now?

The crash is somewhere related to the USB serial problem. I find a workaround:

  • first start the debugger. It will stop with an exception
  • now restart the debug (CTL+SHIFT+F5). Everything OK, Serial monitor is talking!
1 Like

Ah indeed, actually that was noticed 2 years ago too: Problems starting debug session with jlink on feather M0 - #6 by RoSchmi

But noone ever found the cause.

Removing the bootloader in the topic above helped though.

1 Like

Interestingly, the official Arduino guide does not include any steps with removing the bootloader. Could someone try Arduino IDE 2.0 and their simple example? Do you experience the same problems?

It seems like a board-related issue, not J-Link or PlatformIO.

I try on Arduino 2.0 rc6 with a simple loop. USB connection is OK if I put my breakpoint after the 1 sec delay. With platformio, it do not work with the same breakpoint.
If I put the breakpoint before the 1 sec delay, Arduino 2.0 loose USB connection also.
Looks like USB connection is reseted after debug start, then it needs some time to set up wit the target running. If a bkp is met before, the USB is not finalized in time and Window threw ‘USB not recorgnized’

Did you also disable the initial breakpoint in PlatformIO? See Debugging options — PlatformIO latest documentation

So, you can remove all breakpoints in IDE and set just the initial breakpoint to the loop:

debug_init_break = tbreak loop

Yes, I try but USB gives also the error. I also add a 5 sec delay but this doesn’t help.

Same problem is happening with ozone debugger from Segger. Segger support proposes a solution that is working. See

"Should your setup be that you have a bootloader in ROM that needs to be executed first simply leave the functions AfterTargetDownload() and AfterTargetReset() empty (but not commented out!). This will override Ozone’s default and nothing will be executed so the ROM bootloader can run without interference and jump to the application space where per default Ozone will then stop at main "

Is it possible to do the same with platformIO? (“PIO Debug with bootloader init” in launch.json)

1 Like

Where are these functions implemented? It looks like docs about how to use Segger’s DLL.

Which steps/operations should be performed in this case? Is it possible to configure Ozon using “init” commands? See default commands for JLink

Yes, it is a script *.jdebug called by the debugger Segger Ozone. It sets the vector table,SP, PC from application elf file. I want to be set to the bootloader vector table, SP, PC have a proper HW initialization.
In Ozone, the functions AfterTargetDownload() and AfterTargetReset() shall be empty to do this.

I mean with VCS and debug_server jlink.Similar to the above script, VSC should have a script given to jlink debugger when started.

You already declared custom debug_server in the platformio.ini. So, use -jlinkscriptfile option as described in J-Link GDB Server - SEGGER Wiki

platform = atmelsam
board = mkrwifi1010
framework = arduino
debug_tool = jlink
debug_server =
  C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL
  path/to file/demo.JLinkScript

Does this work for you?