AnsweredAssumed Answered

How to differentiate USB Mass Storage and Battery charging mode: STM32L476

Question asked by j.martin on Nov 28, 2017
Latest reply on Nov 28, 2017 by Ben K

Hello all,

I'm using STM32L476 in a custom PCB board. Using USB OTG libary (from L4 cube examples), our code initialize USB Mass storage by following four lines of code upon USB connectivity (detected by a connected GPIO pin):

 

USBD_Init(&USBD_Device, &MSC_Desc, 0);                                              // USB MSC initialization
USBD_RegisterClass(&USBD_Device, USBD_MSC_CLASS);                   // USB class registration
USBD_MSC_RegisterStorage(&USBD_Device, &USBD_DISK_fops);        // Storage call backs
USBD_Start(&USBD_Device);                                                                      // Start USB MSC

 

We want to put the device in low power sleep mode when the USB is connected to the battery charger (not with PC for USB MSC). I request to know, how to differentiate the USB status: USB connected to PC (USB MSC initialized) vs the USB connected to wall Battery charger.

 

Is there any variable to look? The above functions return USBD_OK in both cases (USB connected to PC or Wall charger).

 

Thank you in advance for your kind reply.

Outcomes