Teensy 4.1 debugging

jokn

Member
I have a teensy 4.1 board here on my desk. It is my first teensy project and my first contact to the arduino frame work. I started with PlatformIO and get a blinky program successful running. Now I want to test the debugger, but it seems ther is no possibility to debug on a teensy 4.1. First I thought I can do this with a segger J-link, but cannot find any connector.
Can anybody confirm?? Is there no way for debugging a teeny 4.1 board out of the box even with a j-link -- really ? I cannoz beleive that.
 
No there is no hardware debugging available.
However there are debugging facilities, especially using VisualMicro with VisualStudio, see here.
I use it all the time and would not be without it. It also does not suffer the same problems as PlatformIO.
Give it a try, it's free for a month, then a low one off payment for an annual or forever license.
 
I' very disappointed. From my point of view I freely avaibale SWD or JTAG connecter is a must have. The board has a very powerfull MCU but without a debug connector not usable for me.
 
I' very disappointed. From my point of view I freely avaibale SWD or JTAG connecter is a must have. The board has a very powerfull MCU but without a debug connector not usable for me.

Teensy is a great product, with exceptionally good software and the best support forum/community. If you decide to try to do something with your T4.1, you'll find good resources here.
 
I'm profosisional developer and did look for a small board with ethernet and high speed usb. So I was happy to find teensy. Maybe teensy is a gread produkt but I would like to undestand how it works in in junktion with the arduino framework. Please take in account so far I had never worked with the arduino framework. Mostly i used STM based eval boards for new projects which has an st-link debugger on board. At first I though it's almost the same with teensy, but there seems to be a complete another pilosophy to develop embedded applikations. There is an mysterious chip om the bord which occupies the jtag interface but do not have a connection to the usb device. What is this chip doing? Is there any preinstaled bootloader on the chip? Is it possible to develop applikations with otther framesworks than arduino?
Meanwhile I have found a lot of hardware hacking examples to get the Jtag interface usable.It seems there a lot of other peaple which are not happy to work without a professional debug interface.
 
I'm profosisional developer and did look for a small board with ethernet and high speed usb. So I was happy to find teensy. Maybe teensy is a gread produkt but I would like to undestand how it works in in junktion with the arduino framework. Please take in account so far I had never worked with the arduino framework. Mostly i used STM based eval boards for new projects which has an st-link debugger on board. At first I though it's almost the same with teensy, but there seems to be a complete another pilosophy to develop embedded applikations. There is an mysterious chip om the bord which occupies the jtag interface but do not have a connection to the usb device. What is this chip doing? Is there any preinstaled bootloader on the chip? Is it possible to develop applikations with otther framesworks than arduino?
Meanwhile I have found a lot of hardware hacking examples to get the Jtag interface usable.It seems there a lot of other peaple which are not happy to work without a professional debug interface.

Maybe others will give their opinion, but I'll try to answer. Arduino makes it easy for the beginner to get started. You can buy a board and immediately write programs, with little or no knowledge of what is going on behind the scenes. Instead of a debugger connection, there is a USB serial connection used for both firmware update and serial I/O with the device. Arduino is open source, with many freely available libraries. Arduino was originally 8-bit AVR devices, though some are now 32-bit ARM devices. Teensy is Arduino-compatible, meaning you can develop with the Arduino IDE, and it uses the Arduino APIs for basic analog and digital I/O, etc., but made 32-bit ARM devices available when Arduino was entirely (?) 8-bit AVR, so it has always provided more processing power than the official Arduino devices and other Arduino-compatible boards. If you google things like "Arduino versus bare metal" you will find many articles and blog posts about the trade-offs. The chip on Teensy that is attached to the JTAG pins is a bootloader. This makes it easy to load code, but it does make the debugger unavailable for general use. A few people have modified boards to use a hardware debugger. You can find the posts on this forum. The way that I update firmware in my own projects is through the method shown in this thread (https://forum.pjrc.com/threads/4316...sy-3-5-amp-3-6?p=297272&viewfull=1#post297272). The code to update firmware is included in the application. New code is received by the application, buffered in flash (or RAM), then overwrites the old firmware.
 
Thank you very much for the detailed explanations. I understand you very well and I would agree, but I'm just curious about the specific solution for this bootloader. As far as I know the i.MX controller has different capabilities to boot from extern device, such has UART and even USB. What is the mystery of using the valuable JTAG port to boot, are there some compatibility reason or is it possibly something like a software protection?
 
Thank you very much for the detailed explanations. I understand you very well and I would agree, but I'm just curious about the specific solution for this bootloader. As far as I know the i.MX controller has different capabilities to boot from extern device, such has UART and even USB. What is the mystery of using the valuable JTAG port to boot, are there some compatibility reason or is it possibly something like a software protection?

Both, perhaps, but that’s a question for Paul.
 
Meanwhile I have a RT1060 evaluation board here on my desk which has a SWD debug port on board. So I can develop on the eval board and finaly download a hexfile to the teensy board. My first attempts were quite successful and can be found here.
 
Teensy debugging - solved (for me)

I have a teensy 4.1 board here on my desk. It is my first teensy project and my first contact to the arduino frame work. I started with PlatformIO and get a blinky program successful running. Now I want to test the debugger, but it seems ther is no possibility to debug on a teensy 4.1. First I thought I can do this with a segger J-link, but cannot find any connector.
Can anybody confirm?? Is there no way for debugging a teeny 4.1 board out of the box even with a j-link -- really ? I cannoz beleive that.

Look no further - please give https://github.com/ftrias/TeensyDebug a try, it solved all my debugging issues with Teensy I've had for years. One huge advantage, it can use Teensy's dual serial capability which means it is easily accessible without any additional hardware and you don't have to sacrifice any other ports for debugging.

In PlatformIO, it is as simple as including the following in platformio.ini
Code:
build_type = debug
lib_deps = https://github.com/ftrias/TeensyDebug/archive/refs/heads/master.zip
build_unflags = -DUSB_SERIAL        
build_flags = -DUSB_DUAL_SERIAL
                    -DDEBUG                   # Comment out to disable debugging.
debug_port = \\.\COM19                        # Teensy, computer and OS dependent -- NEEDS TO BE ADJUSTED
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 =

And in the main progam, debugging could be set up e.g.:
Code:
#ifdef DEBUG //Remove compiler optimizations for hardware debugging
#pragma GCC optimize ("O0") 
#endif

#include <Arduino.h>
#include "TeensyDebug.h"

#define WAIT_FOR_DEBUGGER_SECONDS 120
#define WAIT_FOR_SERIAL_SECONDS 20

[...]

void setup(void)
{
    pinMode(LED_BUILTIN,OUTPUT);
    bool debug_avail=false;
    bool serial_avail=false;

    //Debugger (gdb) support
#ifdef DEBUG
    {   
        SerialUSB1.begin(19200);
        for (uint8_t i = 0; i < (WAIT_FOR_DEBUGGER_SECONDS); i++)
        {
            digitalWrite(LED_BUILTIN,true);
            delay(800);
            digitalWrite(LED_BUILTIN,false);
            delay(200);
            if (SerialUSB1) {
                debug_avail=true;
                break;
            }
            if (Serial()) {
                serial_avail=true;
                break;
            }
        }
        if (debug_avail)
        {
            debug.begin(SerialUSB1);
            delay(100);
            halt_cpu();  
            delay(100);
            debug.printf("Debugger is connected. Connect USB serial monitor now ...\n");
        }  
    }
#endif

    //Serial wait block
    for (uint16_t i = 0; i < (WAIT_FOR_SERIAL_SECONDS*10); i++)
    {
        if ((Serial()) || (serial_avail)) 
        {
            Serial.println("Serial ready.");
            break;
        } else
        {
            delay(100);
            digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));
        }
    }
[...]
}
 
I'm profosisional developer and ... Meanwhile I have found a lot of hardware hacking examples to get the Jtag interface usable. It seems there a lot of other peaple which are not happy to work without a professional debug interface.

Another professional developer here a bit shocked to find no SWD (or JTAG) connector... @jokn, did you find a good method to connect your Segger, or you gave up and used an EV board? I'm developing with FreeRTOS (possibly Zephyr in future), and need a good debug option using Segger J-Link (either SWD as used for almost all ARM debug but JTAG works as well).
 
Back
Top