Difficulties to debug Seeed Wio Terminal with JLink Probe

I spent some time and had to use some tricks to get SWD Debugging with the JLink Probe working on the Seed Wio Terminal.

I finally used this platformio.ini

platform = atmelsam
board = seeed_wio_terminal
framework = arduino
upload_protocol = jlink
upload_port = jlink
debug_tool = jlink

The used Code blinks a led, writes some text on the device-display and writes to the console:

#include <Arduino.h>
#include "TFT_eSPI.h"
#include "Free_Fonts.h" //include the header file
TFT_eSPI tft;
int current_text_line = 0;
#define LCD_WIDTH 320
#define LCD_HEIGHT 240
#define LCD_FONT FreeSans9pt7b
#define LCD_LINE_HEIGHT 18

volatile int counter = 0;
volatile int counter2 = 0;
char strData[100];

void lcd_log_line(char* line) {
// clear line
tft.fillRect(0, current_text_line * LCD_LINE_HEIGHT, 320, LCD_LINE_HEIGHT, TFT_WHITE);
tft.drawString(line, 5, current_text_line * LCD_LINE_HEIGHT);

current_text_line %= ((LCD_HEIGHT-20)/LCD_LINE_HEIGHT);
if (current_text_line == 0) {

void setup() { 



  Serial.println("\r\nHello, I'm starting ");

void loop() {

  for (int i = 0; i < 5; i++)
    digitalWrite(LED_BUILTIN, HIGH);  
    digitalWrite(LED_BUILTIN, LOW); 
    sprintf(strData, "Inner Loop %u", i);   
    Serial.print("Inner Loop ");
    sprintf(strData, "   Outer Loop %u", counter);   
    Serial.print("    Outer Loop ");

When I started debugging the application crashed, seemgly because the USB-Port couldn’t be opened again.
By setting breakpoints I could find out that all went well to the ‘USBDevice.attach();’ command 'in the file arduino/main.cpp

As a preliminary solution I could get debugging working by commenting out these two ‘USBDevice’ commands.

#if defined(USE_TINYUSB)
#elif defined(USBCON)

The disadvantages were that the console output didn’t work and that delay() commands didn’t give the correct delay time.

Has anybody debugging working on the Wio Terminal without these hacks or knows an apparent cause/solution why it is not working as is?

First Edit:
Oh, I was happy too early.
Now when I worked on another application Platformio/Jlink couldn’t reach a next breakpoint when I clicked ‘Continue’ at the first temporary breakpoint. Then, when I clicked ‘Restart (Ctrl Shift F5)’ it stopped again at the first temporary breakpoint but after clicking ‘Continue’ again, it reached the first breakpoint in my setup() routine.

All these hacks are rather ugly and I would be happy to find a better solution.

Update 24.11.2020:
Now it is not longer needed to comment out anything as mentioned in the post above.
Debugging and console output now work together as well.
After Run → Start Debugging it stops on the command init(); Then click the Continue button on the command bar, then the Restart button, then again the Continue button and from now debugging works without problems.

To use the latest framework-code this line should be added to platformio.ini
platform_packages = framework-arduino-samd-seeed@GitHub - Seeed-Studio/ArduinoCore-samd

1 Like