Skip to main content
Visitor II
January 7, 2021
Question

How to detect sleep/resume events from the host of USB HID.

  • January 7, 2021
  • 3 replies
  • 1518 views

Hi,

I'm using my stm32 as a USB HID device and I would like to be able to detect when the host computer goes into sleep mode and when it resumes. How would I detect this change?

I tried checking the following continuously in the main loop but detected no change:

if(((USBD_HandleTypeDef*)hpcd_USB_FS.pData)->dev_state==USBD_STATE_SUSPENDED){

Am I missing something or is there a better way?

    This topic has been closed for replies.

    3 replies

    Super User
    January 8, 2021

    0693W000006I44MQAS.pngJW

    FKopp.1Author
    Visitor II
    January 8, 2021

    This seems to be talking about OTG devices, but I'm just a regular FS usb device

    FKopp.1Author
    Visitor II
    January 8, 2021

    .

    Super User
    January 9, 2021

    You did not care to tell us which STM32 are you using, and my crystal cube told me the wrong one. So one more guess:

    0693W000006I50VQAS.png 

    JW

    FKopp.1Author
    Visitor II
    January 9, 2021

    Thanks for the reply, The device is an stm32L151C8T6A

    I'm doing the following check continuously in the main loop

    if(USB_ISTR & USB_ISTR_SUSP){

    The bit seems always to be 1. Is there something else I need to enable to make this work?