PlatformIO Community

Seeeduino wio terminal + atmel ice debugging

Hi everybody, i’m struggling on debugging with the configuration given in the title.

platformio.ini is :

[env:seeed_wio_terminal]
platform = atmelsam
board = seeed_wio_terminal
framework = arduino
upload_protocol = atmel-ice
debug_tool = atmel-ice
debug_init_break = tbreak loop<

the “usual” blinky project compiles and it’s correctly uploaded on the wio terminal :

Executing task: C:\Users\Max.platformio\penv\Scripts\platformio.exe debug <
Processing seeed_wio_terminal (platform: atmelsam; board: seeed_wio_terminal; framework: arduino)
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel SAM (7.1.0) > Seeeduino Wio Terminal
HARDWARE: SAMD51P19A 120MHz, 192KB RAM, 496KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES:

  • framework-arduino-samd-seeed @ 1.8.1
  • framework-cmsis @ 2.50400.181126 (5.4.0)
  • framework-cmsis-atmel @ 1.2.2
  • toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 14 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in debug mode
    Checking size .pio\build\seeed_wio_terminal\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 1.6% (used 3060 bytes from 196608 bytes)
    Flash: [ ] 3.1% (used 15876 bytes from 507904 bytes)
    ================= [SUCCESS] Took 2.69 seconds =========================

but in the debug console …

Reading symbols from c:\Users\Max\Documents\PlatformIO\Projects\atmel ice test.pio\build\seeed_wio_terminal\firmware.elf…
done.
PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = atmel-ice
PlatformIO: Initializing remote target…
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
at91samd51p19
Info : auto-selecting first available session transport “swd”. To override use 'transport select '.
Info : tcl server disabled
Info : telnet server disabled
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: FW Version = 01.00.0021
Info : CMSIS-DAP: Serial# = J42700054071
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 2000 kHz
Error: Error connecting DP: cannot read IDR
.pioinit:13: Error in sourced command file:<

Please note that wio terminal is only connected trough Atmel ice (that seems to be connected right since fw is uploaded) and the usb c port is only connected to a psu (no double connection to PC)

Here follows a picture of the current wiring.

20220613_171315

Thanks everybody for any kind of help you can provide !
Max

When adding debug_speed = 500 in the platformio.ini, it’s the same result?

Wiring looks good per How to Debug Arduino Boards using SWD Interface - Seeed Wiki, but that is also for a JLink, not a CMSIS-DAP probe.

May also need reset line connected?

Hi Max (btw my name is Massimiliano, like yours),
thanks for your response !

I’m giving a try today to both your suggestion , let you know asap

Thanks
Max

ok, a little step forward…

After adding the reset line to the wiring i’ve seen for the first time the left green led on on the atmel ice unit.

the error given on the debug console remains and (this is weird…) the “clock speed” too it’s the same (2000 khz) even if I’ve specified debug_speed = 500 as per your advice.

here’s a picture of the new wiring and the lit led
20220614_114901
TIA
Max

Can you post the current debug console log?

When you open C:\Users\Max\.platformio\packages\tool-openocd\scripts\target\atsame5x.cfg and change adapter speed 2000 to adapter speed 500, does it make any difference?

here’s the console log:

Reading symbols from c:\Users\Max\Documents\PlatformIO\Projects\atmel ice test\.pio\build\seeed_wio_terminal\firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = atmel-ice
PlatformIO: Initializing remote target...
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
at91samd51p19
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : tcl server disabled
Info : telnet server disabled
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: FW Version = 01.00.0021
Info : CMSIS-DAP: Serial# = J42700054071
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 500 kHz
Error: Error connecting DP: cannot read IDR

The hint about changing speed in atsame5x.cfg file worked, now the speed is set to 500 khz (this suggests us that the “debug_speed” parameter in platformio.ini isn’t reflected in the debugger script) but, unfortunately, the error persists…

Thanks
Max

Okay I have a few remaining things:

  1. Additionally connect the VTARGET / VREF pin from the JTAG connector to a 3.3V pin on the target
  2. If the board has a reset button, try holding it down before OpenOCD starts, and then shortly after or before tries to conenct to the chip, release it again
  3. Instead of the default reset config, try other rest configurations like reset_config srst_only, reset_config none separate, or the ones listed in STM32 + VS Code + mbed upload issue: Error: libusb_open() failed with LIBUSB_ERROR_ACCESS Error: open failed - #12 by maxgerhardt
  4. Make sure the wiring is correct between Atmel ICE and the target board. This should be given by the used cables and adapters, but it’s better t be sure. The pinout on the Atmel-ICE’s SAM connector can be seen here, with the small arrow on the SAM side indicating pin 1.

If none of these solve the problem, please open an issue in Issues · platformio/platform-atmelsam · GitHub.

Well, HUGE step here, now the debugger starts and what did the trick was…

1. Additionally connect the VTARGET / VREF pin from the JTAG connector to a 3.3V pin on the target

I also tried the suggested values for reset_config param but they seem not affect debugger behaviour.
I’m not able yet to debug, because my breakpoints are ignored but the debugger stops inside the core library (cortex_handlers.c) , but i probably have to understand more about openocd.

I enclose the picture of the winning wiring and a couple of screenshot explaining actual behaviour.

In the meantime, a big THANKS to Max Gerhardt

Wiring
20220614_140416

The breakpoint I wish to use…
20220614_140629

Where it actually stops
20220614_140728

The code is so trivial that it gets optimized away with the default debug optimization level (-Og), and so no breakpoint is possible there. If you want to debug code like this, you need to add debug_build_flags as

; don't optimize at all so that the most trivial, redudant code can be debugged
debug_build_flags = -O0 -ggdb3 -g3

to the platformio.ini.

That is actually correct. The default debug_init_break value is tbreak main, so it will break at the main() entry piont of the firmware, which lies in the Arduino core code. Your code / breakpoint has not been hit there, so you just need to press the “Play” button in the upper debugger taskbar to let the chip keep going. You could change that by halting in setup() first, using

debug_init_break = break setup

in the platformio.ini, or,

debug_init_break =

to not break at all initially and only use your breakpoints.

I left everything as in the pictures and modified platformio.ini as:

[env:seeed_wio_terminal]
platform = atmelsam
board = seeed_wio_terminal
framework = arduino
upload_protocol = atmel-ice
debug_tool = atmel-ice
debug_speed = 500
; don't optimize at all so that the most trivial, redudant code can be debugged
debug_build_flags = -O0 -ggdb3 -g3
debug_init_break =

Now the debugger stops on core at:

extern int main(void);
/* This is called on processor reset to initialize the device and call main() */
void Reset_Handler(void)
{
  uint32_t *pSrc, *pDest;
.
.
.

If I use debug_init_break = break setup it correctly stops on setup BUT
in both cases (continuing running the program) my breakpoint are ignored

I also tried to let the code less trivial by inserting a for cycle but no luck, it keeps running despite breakpoints.

I’m quite sure we’re near to the solution
MZ

In this case, after pressing “Play” after the setup() breakpiont has been here, can you press “Pause” again and see where the code is? (Screenshot is best). Do you see that loop() is called in the call stack?

no, I can’t see loop() in the call stack after pausing

pause

It’s waiting for a USB serial connection to be established, because you wrote while(!Serial); in setup().

(You could see that by clicking on the “setup@…” line in the Call Stack too).

Can you remove that line in setup(), or use an external terminal program like HTerm - der-hammer to open the serial connection?

How could I have made this mistake ? I apologize, i was so concentrated on atmel ice that I haven’t seen the obvious…

Anyway :
itworks

Thanks SO much Max, problem solved brilliantly !!!

I think lots of people there outside (wio terminal users) will enjoy this solution.

Regards
Max