Adafruit Grand Central debugging with atmel-ice

Hello,
How do I set up grand central M4 with platform IO debugging with atmel ice for debugging on Windows 10?

Originally, I got it to program properly without atmel-ice in regular running without touching the platformio.ini. Now, I like to debug. Unfortunatey, after modifying the platformio.inin, it does not run and it dies not debug.

I changed the upload_protocol from : upload_protocol = sam-ba to atmel-ice

I put this in this int he platformio.ini

[env:adafruit_grandcentral_m4]
platform = atmelsam
board = adafruit_grandcentral_m4
framework = arduino
board_build.mcu = samd51p20a
debug_tool=atmel-ice
upload_protocol = atmel-ice
build_type=debug

[env:myenv]
platform = atmelsam
board = adafruit_grandcentral_m4
debug_tool = atmel-ice

I get these errors when I try to start to debug:

Processing adafruit_grandcentral_m4 (platform: atmelsam; board: adafruit_grandcentral_m4; framework: arduino)


Scanning dependencies...
No dependencies
Building in debug mode
Checking size .pio\build\adafruit_grandcentral_m4\firmware.elf

========================= [SUCCESS] Took 2.82 seconds =========================

Environment               Status    Duration
------------------------  --------  ------------
adafruit_grandcentral_m4  SUCCESS   00:00:02.820
========================= 1 succeeded in 00:00:02.820 =========================
Reading symbols from C:\Users\laptop\Documents\PlatformIO\Projects\grandcenralm4_blink\.pio\build\adafruit_grandcentral_m4\firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = atmel-ice
PlatformIO: Initializing remote target...

xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
at91samd51p20
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : tcl server disabled
Info : telnet server disabled
Error: unable to find CMSIS-DAP device
.pioinit:13: Error in sourced command file:
Remote communication error. Target disconnected.: Success.

So, have you attached this external debug probe to your Grand Central M4 board?

As the documentation states, the board does not have an on-board debugger, so you can only upload via the default upload_protocol = sam-ba USB Bootloader, and not debug.

For debugging, either a JLink or Atmel ICE is supported out of the box, though really any general SWD debugger (e.g. an STLink) can be used if the platformio.ini is configured correctly to e.g. invoke OpenOCD with the right settings (docs). In any case, you need an external debugger, and the error message

states that you have none connected.

Hello maxgerhardt,

so you can only upload via the default upload_protocol = sam-ba USB Bootloader, and not debug.

I put the upload_protocol = sam-ba ,I can upload again with the usb connector attached to the Adafruit grand central M4.

I have the blue box version of Atmel-ice I purchased 4 years ago with an Olimex ARM-JTAG-20-10, in red PCB color.

This may be a silly question, could the fact that the grand central M4 is plugged through usb conflict with the Atmel-ICE debugging signals? That was the reason I had the upload-protocol to atmel-ice earlier and I unplugged the usb cable from the grand central M4.

The error output says ‘.pioinit:13: Error in sourced command file:’

I get a dialog box that pops up that says
Failed to launch GDB.pioinit13: error in sourced command file. Remote communication error. Target disconnected.: Success.(from interpreter-exec console 'source.pioinit")

With a button that says Open lanch.json.
I open it and it has this:

Blockquote
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
// PIO Unified Debugger
//
// Documentation: Redirecting...
// Configuration: Redirecting...
{
“version”: “0.2.0”,
“configurations”: [
{
“type”: “platformio-debug”,
“request”: “launch”,
“name”: “PIO Debug”,
“executable”: “C:/Users/laptop/Documents/PlatformIO/Projects/grandcentralm4_blink_atmel_ice/.pio/build/adafruit_grandcentral_m4/firmware.elf”,
“projectEnvName”: “adafruit_grandcentral_m4”,
“toolchainBinDir”: “C:/Users/laptop/.platformio/packages/toolchain-gccarmnoneeabi/bin”,
“svdPath”: “C:/Users/laptop/.platformio/platforms/atmelsam/misc/svd/ATSAMD51P20A.svd”,
“preLaunchTask”: {
“type”: “PlatformIO”,
“task”: “Pre-Debug”
},
“internalConsoleOptions”: “openOnSessionStart”
},
{
“type”: “platformio-debug”,
“request”: “launch”,
“name”: “PIO Debug (skip Pre-Debug)”,
“executable”: “C:/Users/laptop/Documents/PlatformIO/Projects/grandcentralm4_blink_atmel_ice/.pio/build/adafruit_grandcentral_m4/firmware.elf”,
“projectEnvName”: “adafruit_grandcentral_m4”,
“toolchainBinDir”: “C:/Users/laptop/.platformio/packages/toolchain-gccarmnoneeabi/bin”,
“svdPath”: “C:/Users/laptop/.platformio/platforms/atmelsam/misc/svd/ATSAMD51P20A.svd”,
“internalConsoleOptions”: “openOnSessionStart”
}
]
}

Can I somehow debug the atmel-ice independently in Arduino or AtmelStudio 7, or some other technique?

I am capable of plugging the high density debug cable both ways in the olimex adaptor. Either way does not work. I have prioritised debugging in what pin one is supposed to be.

Can you try to use https://zadig.akeo.ie/ to change the drivers for the Atmel ICE device to a libusb type driver? It may just be that the drivers you currently have to the Atmel ICE are just for Atmel Studio.

Then try upload_protocol = atmel-ice again (or debug)

After replugging the device or restarting the computer, the usual drivers will be loaded again, so don’t worry.

The usual drivers will be loaded again, so don’t worry.

I am a bit scared using the zadig. I have several projects I must complete.

I have an Olimex ARM-USB-OCD-H. Could I do anything with that?

I just found that I have an Adafruit 2094 Cortex SWD 20 pin to 10 pin adaptor which has the polarixing shroud.

Yes absolutely. If you’ve connected the debugger to the 10 pin debug port (or directly just wire up SWDIO+SWCLK+GND+RESET), you should first test whether you can normally connect to the target chip.

For that, open a new terminal / cmd.exe and cd into C:\Users\<user>\.platformio\packages\tool-openocd. Then execute

bin\openocd.exe -s scripts -f interface\ftdi\olimex-arm-usb-ocd-h.cfg -c "set CHIPNAME at91samd51p20" -f target\atsame5x.cfg

and post output.

If OpenOCD cannot find the debugger device, you must use Zadig to load libusb/WinUSB drivers for it.

BTW, Zadig is also the standard procedure when using FTDI based adapters with e.g. the ESP32, https://medium.com/@manuel.bl/low-cost-esp32-in-circuit-debugging-dbbee39e508b.

If OpenOCD can recognize and connect to the target chip, we can integrate it in PlatformIO by using the appropriate configuration directives.

I took a second computer to do my work. I installed Zadig. I tried both the Olimex and Atmel-Ice tool. They both gave me similar response:
bin\openocd.exe -s scripts -f interface\ftdi\olimex-arm-usb-ocd-h.cfg -c “set CHIPNAME at91samd51p20” -f target\atsame5x.cfg

bin\openocd.exe -s scripts -f interface\jlink.cfg -c “set CHIPNAME at91samd51p20” -f target\atsame5x.cfg

Blockquote
:\Users\laptop.platformio\packages\tool-openocd>bin\openocd.exe -s scripts -f interface\jlink.cfg -c “set CHIPNAME at91samd51p20” -f target\atsame5x.cfg
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
at91samd51p20
Info : auto-selecting first available session transport “jtag”. To override use ‘transport select ’.
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : J-Link ARM V8 compiled Aug 26 2015 15:08:21
Info : Hardware version: 8.00
Info : VTarget = 3.313 V
Info : clock speed 2000 kHz
Error: JTAG scan chain interrogation failed: all zeroes
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway…
Error: at91samd51p20.cpu: IR capture error; saw 0x00 not 0x01
Warn : Bypassing JTAG setup events due to errors
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response
Error: Invalid ACK (0) in DAP response

Is the target board powered separately over USB? This says to me that the board is either not powered or the SWD pins (or GND) is not wired properly.

Have you double-checked the pinmapping from the debug adapter to the board? (schematics of board an SWD pins)

Oh actually for the JLink that’s a special case. It is doing JTAG now but is supposed to use SWD. Can you try adding -c "transport select swd" after (or before) the -f interface\jlink.cfg part of the command? If swd does not work, try hla_swd.

Thanks for your many responses today.
I checked the schematics of the grand central M4 and olimex cable adaptor. They look compatible.

I ran this:

bin\openocd.exe -s scripts -f interface\jlink.cfg -c “transport select swd” -c “set CHIPNAME at91samd51p20” -f target\atsame5x.cfg

It seems to be executing something as a server in my windows command prompt. So what do I do to the settings in VSCode platformIO?

C:\Users\laptop\.platformio\packages\tool-openocd>bin\openocd.exe -s scripts  -f interface\jlink.cfg -c "transport select swd" -c "set CHIPNAME at91samd51p20" -f target\atsame5x.cfg
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
swd
at91samd51p20
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : J-Link ARM V8 compiled Aug 26 2015 15:08:21
Info : Hardware version: 8.00
Info : VTarget = 3.313 V
Info : clock speed 2000 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91samd51p20.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : at91samd51p20.cpu: external reset detected
Info : Listening on port 3333 for gdb connections

Oh yes this is perfect, this proves that the OpenOCD command is correct for connecting to the chip. You can close that program again with Ctrl+C.

Now you can add this to your platformio.ini

debug_tool = custom
debug_server =
  $PROJECT_PACKAGES_DIR/tool-openocd/bin/openocd.exe
  -s
  $PROJECT_PACKAGES_DIR/tool-openocd/scripts
  -f 
  interface\jlink.cfg
  -c
  "transport select swd"
  -c
  "set CHIPNAME at91samd51p20"
  -f
  target\atsame5x.cfg

and then check if debugging works (Run → Start Debugging in VSCode)

With JLink and SAMD(51/21) chips there might be some quirks though where you have to restart the debugging, due to… either the bootloader, USB initialization or MCU restart: JLink ‘Stopping in Setup()' - #11 by maxgerhardt and related Problems starting debug session with jlink on feather M0 - #11 by prototypicalpro

In any case if the debug_server directives work, debugging should at least stop one time at some breakpoint regardless.

Oh actually, if you do use a JLink after all, that’s pre-built into PlatformIO (Atmel-ICE too).

Just add debug_tool = jlink (optionally upload_protocol = jlink too) and then you don’t need the manual OpenOCD command declaration. Only if you use another adapter besides those too (Olimex ARM-USB-OCD-H e.g.), you need this to be able to specify your adapter.

I don’t own a jlink. The Atmel-ICE is based on jlink.
When you gave me the command line to run, you gave it for the openocd tool. I improvised by looking around in the folders. I did not find atmel-ice. That is why I tried with jlink.

I have a third PC now. This is my platformio.ini:

Blockquote
[env:adafruit_grandcentral_m4]
platform = atmelsam
board = adafruit_grandcentral_m4
framework = arduino
board_build.mcu = samd51p20a
debug_tool = custom
debug_server =
$PROJECT_PACKAGES_DIR/tool-openocd/bin/openocd.exe
-s
$PROJECT_PACKAGES_DIR/tool-openocd/scripts
-f
interface\jlink.cfg
-c
“transport select swd”
-c
“set CHIPNAME at91samd51p20”
-f
target\atsame5x.cfg
upload_protocol = sam-ba
build_type=debug

When I start the debug, the icons for pause, step over, restart, stop show up and it does not highlight the pause icon as it would for the Arduino M0 pro that debugs perfectly without an atmel-ice. Do I have to take the bootloader out?

Atmel-ICE adapter is mapped to the CMSIS-DAP adapter (cmsis-dap.cfg) as seen in code per

Hm might need to. Can you set upload_protocol = jlink (if you’re still using the JLink) and see if a normal firmware upload goes through over that?

First, I would need to restore the previous normal operation of my Arduino M0 Pro in a seperate project that used to debug and run. Now, it only does the run. I have a project where I am using this M0 Pro that I have a deadline later this week.

After using Zadig on this 3d computer, I can’t get the Arduino M0 Pro to debug anymore. It says

Debug console:

could not start debugger process > Error:spawn platform ENOENT

Visual Studio Code little message box:

Failed to launch GDB: Error: write EPIPE.

With the M0 Pro plugged in, in Zadig I see
EDBG Data Gateway (Interface 3) driver: winUSB v43.0.0.0
EDBG CMSIS-DAP (interface 0) HidUSB (v10.0.18362.175)
EDBG VIrtual COM Port (interface 1) usbser (v1.1.1.0)

Thanks so much,
Frank

I like to add I did try rebooting, deleting and reinstalling the Device Manger driver in Windows 10 for the M0 Pro.

What does OpenOCD say when you execute

bin\openocd.exe -s scripts -f interface\cmsis-dap.cfg -c "transport select swd" -c "set CHIPNAME at91samd21g18" -f target\at91samdXX.cfg

it produces:

Blockquote
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
swd
at91samd21g18
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 03.25.01B6
Info : CMSIS-DAP: Serial# = FFFFFFFFFFFFFFFFFFFF
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 400 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for at91samd21g18.cpu on 3333
Info : Listening on port 3333 for gdb connections

That looks all good then for connecing to the chip. You may want to try the same debug_tool and debug_server directives tricks from above (with adapted command), but otherwise my suggestions would just be to replugging the USB or trying a new simple blinky project (which should be the only project in the VSCode workspace)

Hello,
I made a lot of progress since our last communication. Outside of platformio using the command prompt, I got the openocd running with Zadig WinUSB driver with arm-none-eabi-gdb and an Atmel sam ice with the Grand Central Express M4. What I can’t get to work is the platformio GUI environment. The icons for pause step over restart appear and it does not continue.
I think the commands in the platformio.ini are not being run properly. Question: How do I see the response to those commands? I see compilation messages in the window but nothing at all for openocd starting up.

I list all the steps that I got by command prompt. In plaformIo, I used sam-ba to upload a blinky with a global variable called coutner

I started the openocd server with:

Blockquote
C:\users\USERNAME.platformio\packages\tool-openocd>bin\openocd.exe -s scripts -f interface\jlink.cfg -c “transport select swd” -c “set CHIPNAME at91samd51p20” -f target\atsame5x.cfg

I confirm that the openocd 3333 port is open on my Windows 10 machine is working with:

Blockquote
netstat -a |find “3333”

Next, I put in my path the arm-none-eabi-gdb.
I go to my platform io folder with the firmware.elf executable at

Blockquote
C:\Users\USERNAME\Documents\platformIO\Projects\gcm4_blinky.pio\build\adafruit_grandcentral_m4\

I run
arm-none-eabi-gdb firmware.elf
Inside the gdb prompt, I type

Blockquote
target remote:3333

I am able to run these commands

Blockquote
monitor reset halt
break loop
continue
print counter

So everything is working command line. I close all the command line programs and I try to get the platform IO gui to work. It is not happening yet. How do I see the results of my custom commands I put in the platformio.ini?

This is what I have i so far:

[env:adafruit_grandcentral_m4]
platform = atmelsam
board = adafruit_grandcentral_m4
framework = arduino
debug_tool = custom
board_build.mcu = samd51p20a
upload_protocol = sam-ba
build_type = debug
debug_init_break = tbreak setup

debug_server =
  $PROJECT_PACKAGES_DIR/tool-openocd/bin/openocd.exe
  -s
  -f
  $PROJECT_PACKAGES_DIR/tool-openocd/scripts/interface/jlink.cfg
  -c
  "transport select swd"
  -c
  "set CHIPNAME at91samd51p20"
  -f
  $PROJECT_PACKAGES_DIR/tool-openocd/scripts/target/atsame5x.cfg

I tried to see if the port 3333 is open, but it is not there.

netstat -a |find “3333”

I think that the openocd command is either not run at all or has an error.
Thanks,
Frank

It looks like I finally got it to work. I searched other posts in the forum and just wrote my debugging command line without using the $ variable. That made the openocd messages appear in a different color relative to the compilation messages.

Here is my platformio.ini:

[env:adafruit_grandcentral_m4]
platform = atmelsam
board = adafruit_grandcentral_m4
framework = arduino
debug_tool = custom
board_build.mcu = samd51p20a
upload_protocol = sam-ba
build_type = debug
debug_init_break = tbreak setup

debug_server =
  /users/laptop/.platformio/packages/tool-openocd/bin/openocd.exe
  -s 
  scripts 
  -f 
  /users/laptop/.platformio/packages/tool-openocd/scripts/interface/jlink.cfg
  -c "transport select swd"
  -c "set CHIPNAME at91samd51p20"
  -f 
  /users/laptop/.platformio/packages/tool-openocd/scripts/target/atsame5x.cfg

I still have a question about the syntax. I saw somebody put a backslash at the end of each line. Is it optional?