How to shut USB ports down at Teensy 4

YasarYY

Member
Hi,

I want to disable both USB ports (main and host) at Teensy 4.1, at setup(), for power reduction. I checked forums/web but found answers for older Teensy boards. There is an end() method at usb_serial_class, which is not implemented. I also searched IMXRT1060 documents but cannot find instructions for shutting USB ports down. As a result I cannot find info on how to do this.

So, how can USB ports at Teensy 4 be disabled via code?
 
Section 42.4.3 USB Power Control in the reference manual might get you started. You could also search the forum for power-related questions generally. I remember there being posts about trying to reduce power on T4, but not about USB power specifically.
 
I looked that section, it mentions a low power suspend mode, which seems not a shut down/disable. I found below code in this forum, for switching off USB by disabling USB clock at Teensy 3.6.

Code:
SIM_SCGC4 &= ~SIM_SCGC4_USBOTG;

This is documented at MK66 processor's reference manual. I was hoping finding something similar for IMXRT1060.

I would give low power suspend mode you suggested a try. How can I access processor registers for this, I guess there are some low level header files to be included? 🤔
 
So, I ended up with below code to disable 2 USB ports:

Code:
    // clear USBPHY_CTRL_ENAUTOCLR_CLKGATE
    USBPHY1_CTRL &= ~USBPHY_CTRL_ENAUTOCLR_CLKGATE;
    USBPHY2_CTRL &= ~USBPHY_CTRL_ENAUTOCLR_CLKGATE;
    // set USBPHY_CTRL_CLKGATE to disable USB clock
    USBPHY1_CTRL |= USBPHY_CTRL_CLKGATE;
    USBPHY2_CTRL |= USBPHY_CTRL_CLKGATE;

But, current draw has dropped only 0.5 mA (109.8 -> 109.3 mA). Enabling (by opposite operations) and disabling continuously differs only 0.5 mA. I would expect a more noteworthy drop, as in https://www.pjrc.com/teensy/low_power.html.

I will dig more, but why there is almost no change at current draw? 🤔
 
That page is from the days of Teensy 2.0, things are a bit more efficient since then.

The second USB port (the host port) is off by default so disabling it probably won't do anything. The primary port is acting as a device so it's not going to do anything unless a host specifically tells it to.
 
Hmm, thank you for these explanations 😌
Then, it seems the only way to have a significant power reduction is to play with the CPU frequency.
 
After writing complete code for the instructions[1], current draw has dropped 6.6 mA (109.8 -> 103.2 mA). Still not much, but worth doing for my case 😌
Powering USB2 down does nothing, as jmarsh stated above.

Code:
// USB power-down sequence, with disabling auto-clearance of the CLKGATE bit to prevent auto-wakeup
// USB1 is device port and USB2 is host port, so powering USB1 down is enough, since USB2 is off by default
// disable interrupts
cli();
// prevent auto-wakeup
USBPHY1_CTRL &= ~USBPHY_CTRL_ENAUTOCLR_CLKGATE;
// disable PHY clock
USB1_PORTSC1 |= USB_PORTSC1_PHCD;
// power-down USB components (001E1C00h is register's reset value)
USBPHY1_PWD |= 0x001E1C00;
// disable USB clock
USBPHY1_CTRL |= USBPHY_CTRL_CLKGATE;
// enable interrupts
sei();

[1]: Section 42.4.3.1 Entering Low Power Suspend Mode, For device operation mode, in the reference manual page 2257.
 
Back
Top