USBHost_t36 on Teensy4.1: is there a way to cut power to the port again?

bazmonkey

Member
I use the USB Host +5V pin (but not the rest of the USB Host) to power a a small device, and I'd like to be able to turn it on/off in software. Is there a way to do this? I naively hoped that there would be a way to just reverse what USBHost::begin() does, since voltage doesn't get delivered until that happens.

Thanks for any help!
 
Try this

Code:
        GPIO8_DR_CLEAR = 1<<26;  // turn off USB host power
        delay(100);  // allow time for 100uF capacitor to discharge
 
Thank you, Paul. Appreciate the fast reply!

Is there a similarly-simple way to turn on the USB Host power this way? I can't simply do another USBHost::begin(), right?

EDIT: nevermind, found it in ehci.cpp:

Code:
  GPIO8_GDIR |= 1<<26;
  GPIO8_DR_SET = 1<<26;

It's a wav sampler in a MIDI instrument that I'm powering this way: it's all well under 500mA and this saves us installing a hardware switch to save battery when not using the sampler (and audio-out).

Happy new year!
 
Last edited:
For any googlers that find their way here, what I ended up doing is (ignore the USE_TEENSY35 part... this code is also for running on them):

Code:
#include <imxrt.h>

/// @brief Enables power to the USBHost controller pin.
void usb_power_on() {
  #ifndef USE_TEENSY35
  GPIO8_GDIR |= 1<<26;
  GPIO8_DR_SET = 1<<26;
  #endif
}

/// @brief Cuts power to the USBHost controller pin.
void usb_power_off() {
  #ifndef USE_TEENSY35
  GPIO8_DR_CLEAR = 1<<26;
  #endif
}

I'm using the USBHost pins solely for the power so I can avoid needing the rest of USBHost_t36.h. I do include a delay as recommended but I do it separately. Works like a charm!
 
It is possible to disconnect power to a port on a device, depending on the device and the port in question. Here are a few ways this can be done:

Unplug the device: Depending on the device, you may be able to simply unplug it from the wall or power strip to cut power to all of the ports.

Use a power strip: If the device is plugged into a power strip with a switch, you can flip the switch to cut power to all of the devices connected to the power strip.

Use a smart power strip: Some power strips have the ability to control power to individual outlets or ports. You can use the app or control panel for the power strip to cut power to the specific port you want.

Use a power outlet timer: Some power outlet timers can be programmed to turn off power to a specific outlet at a certain time. This can be used to cut power to a specific port on a device.

Regard: sportsurge
 
It is possible to disconnect power to a port on a device, depending on the device and the port in question. Here are a few ways this can be done:

Unplug the device: Depending on the device, you may be able to simply unplug it from the wall or power strip to cut power to all of the ports.

Use a power strip: If the device is plugged into a power strip with a switch, you can flip the switch to cut power to all of the devices connected to the power strip.

Use a smart power strip: Some power strips have the ability to control power to individual outlets or ports. You can use the app or control panel for the power strip to cut power to the specific port you want.

Use a power outlet timer: Some power outlet timers can be programmed to turn off power to a specific outlet at a certain time. This can be used to cut power to a specific port on a device.

Regard: sportsurge

He wants to
and I'd like to be able to turn it on/off in software
I don't think your suggestions achieve that.
 
Back
Top