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

Thread: Teensy 4.0 USB Host Issues

  1. #1

    Teensy 4.0 USB Host Issues

    Hey there!

    I've been working on making a MIDI hub and things have been going really well so far. I've got the Teensy talking to PC through USB, and a bunch of incoming and outgoing DIN ports all talking to each other. My last task is to get the USB Host working so that I can plug a hub into it and plug MIDI controllers into the hub. However, this is where I'm getting stuck. My code wasn't working, so I decided to just go to example code and I can't get that working either. I'm using the Examples/Examples for teensy 4.0/USBHost_t36/serial/MIDI/InputExamples sketch to keep things easy while I troubleshoot.

    My Teensy has the VIN/VUSB separated. I have a live 5v rail supplying voltage to the Teensy's VIN and also this new additional USB port. I soldered wires to the D- and D+ pads directly below the existing Teensy USB port (on the bottom side of the board). The 5v, D-, D+, GND are all wired into a female USB A port (in that order when looking at the rear of the port), and a midi instrument is plugged into it. When I run the sketch I get the "USB Host InputFunctions example" message in the serial monitor, but no messages from keyon, keyoff, etc...

    I just had a thought and am wondering if I fried anything by supplying 5v, however I don't think usb will run without it so I imagine the D- and D+ are 5v tolerant... I hope. I've also tried supplying 3v with no luck. I really hope I can figure this out with some help, though, I'm so close to completing the project!

    Thanks for any advice!

    Edit: Also, I've selected Serial + MIDI as the USB Type

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,449
    Quote Originally Posted by Sandwich View Post
    I have a live 5v rail supplying voltage to the Teensy's VIN and also this new additional USB port. I soldered wires to the D- and D+ pads directly below the existing Teensy USB port (on the bottom side of the board). The 5v, D-, D+, GND are all wired into a female USB A port (in that order when looking at the rear of the port), and a midi instrument is plugged into it. When I run the sketch I get the "USB Host InputFunctions example" message in the serial monitor, but no messages from keyon, keyoff, etc...
    Just a quick sanity check... You didn't mention the USB cable GND to Teensy GND connection. The grounds need to be all connected together, Teensy, USB host cable, and the external power.

  3. #3
    Correct, 5v rail's GND is connected to power supply, Teensy, and the new USB. Probably not the best picture, but the 5v rail is the top one, USB port is at the top left, yellow wire is D- and orange is D+...


  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,449
    Those wires might not be cable of 480 Mbit/sec speed. Usually you would need to cut the end off a real USB cable and use its wires, or keep the wires from Teensy 4.0 to the USB connector very short and close to each other or tightly twisted together.

    Try uncommenting this line in ehci.cpp in the USBHost_t36 lib:

    Code:
    	//USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec
    In the current version, it's at line #262.

  5. #5
    Quote Originally Posted by PaulStoffregen View Post

    Code:
    	//USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec
    Uncommenting that line (both with the previous line uncommented or commented out) produces the compiling error:

    Code:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\USBHost_t36\ehci.cpp: In static member function 'static void USBHost::begin()':
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\USBHost_t36\ehci.cpp:262:19: error: 'USBHS_PORTSC_PFSC' was not declared in this scope
    
      USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec
    I think I have half a butchered USB cable I can try to solder in later today.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,449
    Oh, opps, looks like the define for Teensy 4.0 is missing from utility/imxrt_usbhs.h

    Add this line to that file:

    Code:
    #define USBHS_PORTSC_PFSC      USB_PORTSC1_PFSC

  7. #7
    I've switched over to using a USB cable section and in the process realized there was issues with my wiring, I either had a bad example or was too tired and wired wrong. I've got everything hooked up and soldered together and now the Teensy can see my MIDI controller messages. Now it's just getting all that working with the existing MIDI Hub code and I'm good. Thank you for the help Paul, everyone here really appreciates all the time you spend solving issues. Even this issue you solved unintentionally by suggesting the wire might be the issue which quickly lead me correcting my wiring issues.

    Edit: Also, for future reference, adding in the #define to the .h file did fix the compiling error for low speed USB.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,449
    Glad you got it up and running!

    Quote Originally Posted by Sandwich View Post
    adding in the #define to the .h file did fix the compiling error for low speed USB.
    I've added it on github, so future versions will have this define

    https://github.com/PaulStoffregen/US...31ec84dff3f625
    Last edited by PaulStoffregen; 02-02-2020 at 08:57 AM.

Posting Permissions

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