Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Teensy 4 low-level debugging

  1. #1

    Teensy 4 low-level debugging

    Howdy folks,
    tl;dr: What is the best approach to be able to view the debug/printf[1] statements when working with the Teensy 4.0?

    I've been investigating adding a new usb interface to the teensy 4. However, I'm not very familiar with how to debug in this embedded environment. Namely, if my program crashes I want to see the stack info, and ideally be able to view debug print statements.

    So, a lot of questions:
    - How do folks tend to do this?
    - Is the answer a serial monitor that I plug into hardware serial? If so, what product should I buy?
    - Are there any instructions/schematics/examples for doing this with the teensy 4?
    - Is there some other way to have the program dump the stack trace to [external] storage?
    - Do other debugging approaches exist? My initial searching led me to "JTAG debugger", but I'm not too familiar and it seems like a separate use case.

    Apologies for the multitude of questions, I'm confident in being able to move forward so long as I can see what my code gets to and what fails . Many thanks!



  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    One recent published example would be this thread: RawHID-recv()-hangs-after-updating-to-Teensyduino-1-4-9-or-higher-for-Teensy-4-0

    KurtE uses a logic analyzer and triggers pins on entry and exit to observe timing and where a hang stops or fails to exit. It was in fact a USB problem and it never faulted - just hung when processing one event was

    That link is to TTL Serial# output from target debug Teensy to a second Teensy with [GND/Rx/Tx] connected - with common .begin(speed) - providing another view of debug spew when using USB is blocked - as perhaps in this case where it is the area of development. That sample shows 115Kbaud - going to 2Mbaud will allow faster output with less delay.

    Nor sure if there is an L.A. at hand for use - but reading that thread should give a start …

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    As @defragster mentioned, I do a lot of stuff with a Logic Analyzer (in my case, I have a couple from Saleae).

    Since we don't have access to hardware debug support, often times I do as @defragster mentioned and setup things like digitalWriteFast sometimes with High and start and low at bottom, other times I toggle an IO pin, ...

    Sometimes I turn on some of the debug support in the teeny4 core.
    That is you edit the file ...\teensy4\debug\printf.h
    And you uncomment the define at the start of the file: //#define PRINT_DEBUG_STUFF

    And then build your sketch. This will in some places in the core files cause debug prints go out to the Serial4 TX pin and default at 115200. So you can use some form of USB to Serial adapter to then connect up to ths pin and see the data. You can for example use another Teensy to do this.

    You can look through the different places in the core files that include this file and have printf statements that output.

    This is good for some stuff, but can easily screw up testing things that are timing dependent.

  4. #4
    Thanks folks, this is an excellent starting point!

    I'll investigate that post, logic analyzers, and setting up on that serial4 tx pin.

    For hardware serial on the teensy 4, do I need a MAX232 chip like the 3.* boards[1], or will connecting the relevant pins to a usb<->serial adapter work?


  5. #5
    For posterity, I ended up buying this[1] TTL<->USB Serial adapter from sparkfun. Uncommented "#define PRINT_DEBUG_STUFF" in debug/printf.h, connected the cable to hardware serial4, and set the serial monitor in Arduino IDE to /dev/ttyUSB0 and viola, we have debug!

    Thanks so much folks, this really helped!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts