PIO debugger works like a charm using BlackMagic Probe first time only

Hello!

I’m using VS Code + PIO. And target is a arduino zero clone (Atmel SAMD21G18A).
Simple project, like this one:

#include <Arduino.h>

void setup() {
}

int i = 0;

void loop() {
    ++i;
    delay(1000);
}

Correctly builds and launch debugger. Everything is fine. I can step, I can setup breakpoints, I can watch variables.

And after that, second build and run gets the following error:

Reading symbols from c:\Projects\PlatformIO\test1\.pioenvs\zeroUSB\firmware.elf...
done.
PlatformIO Unified Debugger > http://bit.ly/pio-debug
PlatformIO: Initializing remote target...
Target voltage: 3.3V
Available Targets:
No. Att Driver
1 Atmel SAMD21G18A (rev D)
Temporary breakpoint 1 at 0x220a: file C:\users\alexey\.platformio\packages\framework-arduinosam\cores\samd\main.cpp, line 35.
Loading section .text, size 0x3008 lma 0x2000
Loading section .ramfunc, size 0x60 lma 0x5008
Loading section .data, size 0x100 lma 0x5068
Start address 0x2148, load size 12648
Transfer rate: 17 KB/sec, 843 bytes/write.
.pioinit:23: Error in sourced command file:
Cannot access memory at address 0x20008008
.pioinit:23: Error in sourced command file:
Cannot access memory at address 0x20008008

And that’s it. It never runs after that.
But! If I change target to another SAMD21G, and create another project, first run will be ok.

1 Like

Hi I’m trying to connect the BlackMagic probe to a SAMD21J18A Autonomo/Sodaq over SWD (not JTAG). I don’t seem to have any luck in getting the basics connecting even the first time. I wonder what are your .ini settings. On Win10 the BlackMagic is configuring as COM8 and COM9. This is what I’m using

[env:sodaq_autonomo]
board = sodaq_autonomo
platform = atmelsam
debug_tool = blackmagic
debug_port = COM8
framework = arduino

and terminal output is showing …
Linking .pioenvs\sodaq_autonomo\firmware.elf
Checking size .pioenvs\sodaq_autonomo\firmware.elf
Building .pioenvs\sodaq_autonomo\firmware.bin
Memory Usage → Redirecting...
DATA: [== ] 21.6% (used 7088 bytes from 32768 bytes)
PROGRAM: [==== ] 35.3% (used 92408 bytes from 262144 bytes)
Configuring upload protocol…
AVAILABLE: atmel-ice, blackmagic, jlink, sam-ba
CURRENT: upload_protocol = sam-ba
Looking for upload port…
Auto-detected: COM9
Forcing reset using 1200bps open/close on port COM9
Waiting for the new upload port…
Uploading .pioenvs\sodaq_autonomo\firmware.bin
No device found on COM9

That’s what I am using:
[env:zeroUSB]
platform = atmelsam
board = zeroUSB
framework = arduino
upload_protocol = blackmagic
upload_port = \\.\COM21
debug_tool = blackmagic
debug_port = \\.\COM21

I have BlackMagic on ports COM21 and COM22

Wonderful thanks - excellent I was missing the upload_protocol.
Something has programmed in now.

Checking size .pioenvs\sodaq_autonomo\firmware.elf
Building .pioenvs\sodaq_autonomo\firmware.bin
Memory Usage → Redirecting...
DATA: [== ] 21.6% (used 7088 bytes from 32768 bytes)
PROGRAM: [==== ] 35.3% (used 92408 bytes from 262144 bytes)
Configuring upload protocol…
AVAILABLE: atmel-ice, blackmagic, jlink, sam-ba
CURRENT: upload_protocol = blackmagic
Looking for BlackMagic port…
Use manually specified: COM8
Uploading .pioenvs\sodaq_autonomo\firmware.bin
Target voltage: 3.3V
Available Targets:
No. Att Driver
1 Atmel SAMD21J18A (rev D)
0x0000b134 in WDT_Handler ()
Loading section .text, size 0x166f0 lma 0x2000
Loading section .ARM.exidx, size 0x8 lma 0x186f0
Loading section .data, size 0x200 lma 0x186f8
Start address 0xb14c, load size 92408
Transfer rate: 19 KB/sec, 962 bytes/write.
Section .text, range 0x2000 – 0x186f0: matched.
Section .ARM.exidx, range 0x186f0 – 0x186f8: matched.
Section .data, range 0x186f8 – 0x188f8: matched.
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
=========================================================== [SUCCESS]

Now i’m seeing some of the same - fragile operation with BlackMagicProbe BMP21 ver 1.6
It downloads and on a clean boot system will run. But on subsequent attempts
so with it running and trying to load an update I get
Archiving .pioenvssodaq_autonomolibFrameworkArduino.a
Linking .pioenvssodaq_autonomoirmware.elf
Checking size .pioenvssodaq_autonomoirmware.elf
Building .pioenvssodaq_autonomoirmware.bin
Memory Usage → Redirecting...
DATA: [= ] 9.2% (used 3028 bytes from 32768 bytes)
PROGRAM: [= ] 6.0% (used 15692 bytes from 262144 bytes)
[SUCCESS] Took 17.57 seconds
Reading symbols from c:\Users\neilxx\Documents\Arduino\env03\ModularSensors\a\atlAuto.pioenvs\sodaq_autonomo\firmware.elf…
done.
PlatformIO Unified Debugger > Redirecting...
PlatformIO: Initializing remote target…
Target voltage: 3.3V
Available Targets:
No. Att Driver
1 Atmel SAMD21J18A (rev D)
Temporary breakpoint 1 at 0x43e2: file C:\Users\neilh77.platformio\packages\framework-arduinosam\cores\sodaq\main.cpp, line 35.
Loading section .text, size 0x3c34 lma 0x2000
Loading section .ramfunc, size 0x60 lma 0x5c34
Loading section .ARM.exidx, size 0x8 lma 0x5c94
Loading section .data, size 0x110 lma 0x5c9c
Start address 0x4320, load size 15788
Transfer rate: 19 KB/sec, 830 bytes/write.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to debug_init_break = tbreak main
Note: automatically using hardware breakpoints for read-only addresses.
Cannot execute this command while the target is running.
Cannot execute this command while the target is running.