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

Thread: Hardware serial debugging in USB stack (Teensy 3.2)

  1. #1
    Junior Member
    Join Date
    Apr 2018

    Hardware serial debugging in USB stack (Teensy 3.2)

    I'm trying to modify the USB stack with support for Force Feedback (FFB). That involves some hefty modifications in the Teensy USB stack code. However, I lack some debugging method since the USB serial method normally used isn't even up yet when I need my debug output.

    So, trying hardware serial instead. I've hooked up a SparkFun FTDI Basic in 3.3V mode and attached to pin 0 and 1 (RX/TX). I've modified the project to listen to that port (COM7) in my case. So far so god. The actual USB code by Paul contains commented lines like these:

    serial_print("Desc found, ");

    When removing the comments and compiling the code everyting compiles fine, but no output. What I need help with is how to set up the Hardware serial1 port to actually work, and how this is done with BAUD rates and so on. I guess this could be put in some early setup routines in the Teensy code, but I don't know where.

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Colmar, France
    You’d have to track down where the (internal, not public) function serial_print() is defined. In Eclipse for example, highlight it and press F3 to open the corresponding source file and jump directly to the implementation of the function.

    You’ll find that it’s defined in the serial1.c core file where it is defined to use Serial1 alias UART0. Thus, it definitively should work on pins 0 and 1. But this code does not handle pin multiplexing and other luxury stuff as in the higher level functions. You’ll have to put a Serial1.begin(yourdesiredbaudrate); in your code somewhere before.
    Last edited by Theremingenieur; 05-30-2019 at 12:40 PM.

  3. #3
    Junior Member
    Join Date
    Apr 2018
    I did all that.
    Even on Eclipse even. Been an Eclipse user for 20 years almost (with Java).

    Did some digging and found that I need this code to be inserted for instance at beginning of the usb_setup() method in usb_dev.c:

    BAUD2DIV will devide down the baud with respect to crystal settings etc. After this debug printing works, even inside Eclipse (Sloeber) Serial monitor view.

  4. #4
    Junior Member
    Join Date
    Apr 2018
    Did some more digging and Paul's own serial initialization is in usb_init() in usb_dev.c
    I modified the code to include hardware flow control, otherwise I got buffer overruns all the time:
    void usb_init(void)
    	int i;
    	serial_set_rts(2); // Added RTS flow control. I.e a wire between pin 2 and the CTS pin on the FTDI Basic from SparkFun (or similar).

Posting Permissions

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