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 OpenOCD: Bug Reporting
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)
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
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?
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…
Additionally connect the VTARGET / VREF pin from the JTAG connector to a 3.3V pin on the target
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
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.
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.
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.
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?