Debugging a teensy with Platformio vscode plugin

Update

I read in one place that the teensy 4.1 has debugging capability built in and elsewhere that 4.1 requires an extra bit of hardware. Can you clarify?

I seem to have made progress. I am using the plartformio vscode plugin successfully. I am able to build and upload. When I click on ‘debug’ I see some packages being recompiled, and something being uploaded. Buit after a moment of showing activity, the debug plug in stops and it looks like nothing is happening.

Do I have to modify my code and put in, for example, debug.start() or something like that?

Can someone shed some light on this?

Original

I have never done this before. Reading the help it seems to imply that I need an extra bit of hardware. In other words the simple usb connection from myraspberry pi to the teensy won’t be sufficient for debugging. Is that correct?

Hi @pitosalas,

I have never done this before. Reading the help it seems to imply that I need an extra bit of hardware. In other words the simple usb connection from myraspberry pi to the teensy won’t be sufficient for debugging. Is that correct?

That’s correct, it’s not possible to debug the Teensy 4.1 board even with additional hardware. Although, some developers use a GDB stub as a workaround GitHub - ftrias/TeensyDebug: GDB proxy and debugging support to Teensy 3/4

Thanks. I do wonder then why Platformio (vs code IDE) has a debug task, which does a lot of recoiling and reuploading, but in the end doesn’t do anything. You would think there would be a simple error message somewhere.

Or are those commands meant to work with the GDB proxy?

I guess here’s the high level question: do most people programming Teensy with Platformio just do print statements to debug?

Also do Arduino type debuggers give better debugging support?

Thanks!

I do wonder then why Platformio (vs code IDE) has a debug task, which does a lot of recoiling and reuploading, but in the end doesn’t do anything.

That’s probably a mistake in the board manifest, there is no easy way to debug this board.

do most people programming Teensy with Platformio just do print statements to debug?

I believe so.

Also do Arduino type debuggers give better debugging support?

I’m not sure what debuggers you mean, it’s a limitation imposed by the hardware.

Let’s say I switch from the teensy to one of the several Arduino or similar SBC. And I continue to use PlatformIO for deploying. Would the debug features be usable without additional special hardware? (The most important debug features are setting breakpoints, stepping and examing variables.) Which Arduino-family boards would you recommend?

It is not an “Arduino family” board but the ESP32-S3 has a built-in debugger.
See the great article by eduardogb: How to use JTAG built-in debugger of the ESP32-S3 in PLATFORMIO

1 Like

Very technically, the Teensy 4 is hardware-debuggable if you have extreme skills in microsoldering and an external debug probe like a J-Link:

You should use the exact platformio.ini as provided in that project.

Hi @valeros and @maxgerhardt,

Greetings!
I use PlatformIO VSCode Plugin for my Teensy 4.0 setup and was able to successfully compile and upload. Now, I am in need of the Debug option and unfortunately I couldn’t succeed with it. Below explains the scenario:

  1. Using Teensy 4.0 for SPI Master-Slave Communication and using the same examples of this library GitHub - tonton81/SPI_MSTransfer_T4.
  2. Updated the platform.ini file as provided in GitHub - ftrias/TeensyDebug: GDB proxy and debugging support to Teensy 3/4 and updated the debug_port as I am using Windows. See below:
[env:teensy40]
platform = teensy
board = teensy40
framework = arduino

; change microcontroller
board_build.mcu = imxrt1062

build_type = debug
; See https://github.com/platformio/platform-teensy/issues/65
build_unflags = -DUSB_SERIAL
build_flags = -DUSB_DUAL_SERIAL
debug_port = \\.\COM10 
debug_tool = custom
debug_load_mode = manual
debug_server = 
debug_init_cmds =
  target extended-remote $DEBUG_PORT
  $INIT_BREAK
  define pio_reset_run_target
  interrupt
  tbreak loop
  continue
  end
  define pio_restart_target
  echo Restart is undefined for now.
  end

debug_init_break =
  1. I am able to compile the Master example MASTER.ino
    (Note: Added below as well to the code).
    #include <Arduino.h>
    #include “TeensyDebug.h”
    #pragma GCC optimize (“O0”)
    After a normal upload, I do not see anything if I start the PIO Debug. I see the console opens but shouldn’t it stop if I sent a normal breakpoint in Vscode? Sorry if my understanding is wrong.

  2. Similarly, It tried the Slave code SPI_MSTransfer_SLAVE.ino. Unfortunately, it fails the compilation. If I revert the platformio.ini file it compiles successfully.

  3. FYR: I downloaded and kept the TeensyDebug-master folder from GitHub under my project lib directory.

I would really appreciate if you could guide me here for integrating this debug feature to my project . I do also have a doubt regarding the usage of this debug feature, like can I directly follow normal breakpoint setting as in VSCode or do I have to create/include some setup and other debug commands in my main.cpp?

Thanks
Anand