USBHost.end()

sjm-mcl

Active member
Is there some way of closing down the USB host port once my code has finished accessing an MSC device to save power. At the start of my code I use usbHost.begin(), I'd like to know if there's anything like usbHost.end() which would amongst other things cut power to the usb host port. I see from the schematic that usb host port power is controlled by pin EMC-40, I've searched but I cannot find anything useful regarding this pin. Thanks for your time.
 
To answer my own question, the hack presented here seems to work, but I'd prefer something cleaner if anyone has any ideas
Code:
 #include <USBHost_t36.h>

// Setup USBHost stuff
USBHost         usbMSC;
USBDrive        msDrive1(usbMSC);
USBFilesystem   usbPartn(usbMSC);

void setup()
 {
  // Start USBHost_t36
  usbMSC.begin();
  Serial1.print("\r\nChecking for media... ");
  t = millis();
  while (!usbPartn)
   {
    if ((millis() - t) > 3000)
     {
      Serial1.println("Timeout, halting.");
      while(1);
     }    
    usbMSC.Task();
   }
  Serial1.println("Done.");

  // Access USB media here...

  // Done with usb media, close all
  usbPartn.end();
  msDrive1.end();
  // Hack to turn off 5v USB host power:
  // Pin EMC_40 controls the USB host power switch (U5)
  // ehci.cpp seems to route the EMC_40 pad to GPIO8
  // _SET for USB Power ON, _CLEAR for USB Power OFF
  // The below seems to work, but not sure how/why!
  GPIO8_DR_CLEAR = 1<<26;
 }
Hope this helps anyone else ending up here
 
Back
Top