PlatformIO Community

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 5.2.0a3 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: https://github.com/platformio/platformio-docs/pull/75

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.

grafik

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.

grafik

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