Full support for Teensy 4.0: build, test, debug with PlatformIO!

We are pleased to announce the next release v4.4.0 of Teensy development platform.

teensy40_pinout1

What’s New

See Release Notes for details.

Documentation

See Teensy — PlatformIO latest documentation

Examples

See project examples platform-teensy/examples at develop · platformio/platform-teensy · GitHub

Update

  • PlatformIO IDE – please navigate to PIO Home > Platforms > Updates
  • PlatformIO Core – please run a next CLI command $ pio update

Regards,
The PlatformIO Team

3 Likes

Right, now I’m worried… how did you know my Teensy 4s arrived yesterday? :laughing: :laughing: Great work Ivan [edit: and Valeros!] … look forward to being able to spin them up using PlatformIO! :slight_smile:

Happy coding with PlatformIO! :hugs:

P.S: All kudos to @valeros :+1:

1 Like

There is a bad link, “mbed-rtos” in the docs.
https://docs.platformio.org/en/latest/platforms/teensy.html
https://docs.platformio.org/en/latest/platforms/teensy.html#examples

Is there no rtos for this device, seems silly to have this kind of speed without a rtos.

The mbed-rtos example was removed back in October 2018, but mbed still appears to be supported and all the other examples are present, so perhaps it’s just a matter of looking at the other examples provided with mbed?

I’ve done a PR to remove that link: mbed-rtos example no longer exists for Teensy by pfeerick · Pull Request #75 · platformio/platformio-docs · GitHub

Thanks, it has been just fixed!

Hello
Has anyone successfully debugged teensy 4.0 with breakpoints?

Yeah someone did that in Teensy 4.1 Uploading with JLink - #18 by sp33, you just need to have god-like microsoldering skills to get to the JTAG signals.

And without JLink? I tested this : GitHub - ftrias/TeensyDebug: GDB proxy and debugging support to Teensy 3/4 but isn’t work…

It works just fine with PlatformIO.

platformio.ini

[env:teensy40]
platform = teensy
board = teensy40
framework = arduino
build_type = debug
lib_deps = 
    https://github.com/ftrias/TeensyDebug/archive/refs/heads/master.zip
; activate Dual USB just as README says
build_flags =
    -D USB_DUAL_SERIAL

src\main.cpp

#include <Arduino.h>
#include "TeensyDebug.h"
#pragma GCC optimize ("O0")

int mark = 0;

void test_function() {
  mark++;
}

void setup() {
  // Use the first serial port as you usually would
  Serial.begin(19200);

  // Debugger will use second USB Serial; this line is not need if using menu option
  debug.begin(SerialUSB1);

  // debug.begin(Serial1);   // or use physical serial port

  halt();                    // stop on startup; if not, Teensy keeps running and you
                             // have to set a breakpoint or use Ctrl-C.
}

void loop() {
  test_function();
  Serial.println(mark);
  delay(1000);
}

.vscode/launch.json

// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
//
// PIO Unified Debugger
//
// Documentation: https://docs.platformio.org/page/plus/debugging.html
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug",
            "executable": "C:/Users/Max/Documents/PlatformIO/Projects/teensy-gdb-stub/.pio/build/teensy40/firmware.elf",
            "projectEnvName": "teensy40",
            "toolchainBinDir": "C:/Users/Max/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "preLaunchTask": {
                "type": "PlatformIO",
                "task": "Pre-Debug"
            }
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (skip Pre-Debug)",
            "executable": "C:/Users/Max/Documents/PlatformIO/Projects/teensy-gdb-stub/.pio/build/teensy40/firmware.elf",
            "projectEnvName": "teensy40",
            "toolchainBinDir": "C:/Users/Max/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin",
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "name": "Launch",
            "type": "cppdbg",
            "request": "launch",
            "miDebuggerPath": "C:/Users/Max/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin/arm-none-eabi-gdb.exe",
            "miDebuggerArgs": "--baud=115200",
            "MIMode": "gdb",
            "targetArchitecture": "arm",
            "program": "C:/Users/Max/Documents/PlatformIO/Projects/teensy-gdb-stub/.pio/build/teensy40/firmware.elf",
            "launchCompleteCommand": "None",
            "filterStderr": false,
            "filterStdout": false,
            "externalConsole": false,
            "cwd": "${workspaceRoot}",
            "setupCommands": [
              {"text": "set target-async off"},
              {"text": "target extended-remote \\\\.\\COM9"},   
              ]
        }
    ]
}

You have to adapt the all the paths for your local machine though.

I also got it working with just platformio.ini modifications and no .vscode/launch.json modifications.

[env:teensy40]
platform = teensy
board = teensy40
framework = arduino
build_type = debug
lib_deps = 
    https://github.com/ftrias/TeensyDebug/archive/refs/heads/master.zip
; activate Dual USB just as README says
build_flags =
    -D USB_DUAL_SERIAL
debug_port = \\.\COM9
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 =

So with this you can upload once normally and then use the normal “PIO Debug” debug configuration.

And again it works like before.

How to set the port in linux? I uploaded the script with your configuration and I correctly see both serial ports (/dev/ttyACM0 and /dev/ttyACM1). I changed platform.ini adding the port as follows:

debug_port = /dev/ttyACM1

With this configuration, after uploading the script to the board and running PIO Debug, the program keeps executing but the breakpoint is not triggered. What am I doing wrong?

There seems to be an issue with building using dual serial, as described in https://github.com/platformio/platform-teensy/issues/65. You may need to add this to the platform.ini that @maxgerhardt suggests.

build_unflags = -DUSB_SERIAL

Hi
Was anyone able to get “TeensyDebug.h” to work together with the Teensy Audio Library “Audio.h”?

I’ve been using this amazing library (TeensyDebug) on PlatformIO for some time, but I’ve been stuck for a few days trying to get this to work.
I am working on a Teensy 4.1, but it shouldn’t make a big difference, or at least I hope not :slight_smile:

Running Platformio 4.15/16, Teensyduino/TeensyLoader 1.56


I have narrowed down the problem to this simple piece of code:

src\main.cpp

#include "Arduino.h"
#include "TeensyDebug.h"
#include "Audio.h"
#pragma GCC optimize ("O0")

int mark = 0;

AudioOutputI2S  audioOut;

void test_function() {
  mark++;
}

void setup() {
  Serial.begin(19200);

  debug.begin(SerialUSB1);

  halt_cpu();

  AudioMemory(4);
}

void loop() {
  test_function();
}

The program compiles fine and it attemps to load the .hex on the Teensy, but for some reason this causes the Teensy to go into a bad state where the two COM ports are never opened. It seems bricked at this point.
The only way to go out of this state is to load a “working” program and then press the pushbutton on the Teensy.

For example, if I start with the Teensy running a “working” program, and then attempt to load this code, I can literally see the two COM ports vanish in my “Device Manager”.

Just adding some additional information on what I’ve tried:

  • If I comment out line AudioOutputI2S audioOut; then program loads correctly and can be debugged
  • If I comment out line AudioMemory(4); then again program loads correctly and can be debugged
  • I’ve managed to make the same exact code work on VisualMicro in Visual Studio, but I had to change the optimization level from recommended "No Project + Library Optimization" to "No Project Optimization" - I think that corresponds to changing from -O0 to -Og for libraries.

For completeness, here is my platformio.ini file:

platform = teensy
board = teensy41
framework = arduino

lib_deps = Audio@^1.3

build_type = debug
build_unflags = -DUSB_SERIAL
build_flags =
    -D USB_DUAL_SERIAL
debug_port = \\.\COM8
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 =

@ftrias This problem looks similar to this other post I’ve found: https://issueantenna.com/repo/ftrias/TeensyDebug/issues/12

Any help or similar experience is greatly appreciated! :slight_smile:

1 Like

I’m looking into a similar issue but with a different library.

I then started a new project without the debugger code to investigate and the same issue is there, so nothing to do with the debugger code.

If you add the following

build_unflags = -Og 
build_flags = -O1
debug_build_flags = -O1

Then everything will start.

So the issue here is with the PlatformIO build when using -Og and -O0, something somewhere is broken.