2026-02-02 2:57 AM
I am using the ST Host library version 3.54 on an STM32F769 device, supporting HID devices. I am using the internal Full Speed phys.
I have a USB mouse connected and all works fine, however I would like to save power when the mouse is not being used by putting it into suspend. I cannot see any support for this in the ST middleware, so I asked Ai and got this:
USBH_StatusTypeDef USBH_LL_Suspend(USBH_HandleTypeDef *phost)
{
HCD_HandleTypeDef *hhcd = phost->pData;
USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
uint32_t USBx_BASE = (uint32_t)USBx;
USBx->GINTMSK |= USB_OTG_GINTMSK_WUIM;
/* Suspend the port */
USBx_HPRT0 |= USB_OTG_HPRT_PSUSP;
return USBH_OK;
}This works fine - the mouse powers down and there is a useful drop in power consumption.
However, I cannot get the port out of standby. This is the code Ai gave me for the Host to awake the port:
USBH_StatusTypeDef USBH_LL_Resume(USBH_HandleTypeDef *phost)
{
HCD_HandleTypeDef *hhcd = phost->pData;
USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
uint32_t USBx_BASE = (uint32_t)USBx;
/* Clear suspend */
USBx_HPRT0 &= ~USB_OTG_HPRT_PSUSP;
/* Assert resume (K-state) */
USBx_HPRT0 |= USB_OTG_HPRT_PRES;
/* USB spec: resume signalling for at least 20 ms */
USBH_Delay(20);
/* Deassert resume */
USBx_HPRT0 &= ~USB_OTG_HPRT_PRES;
/* SOFs resume automatically */
return USBH_OK;
}Unfortunately, this does not work - the mouse stays in low power mode.
Can anyone see the problem with this? Is there an example for doing this anywhere?
Ideally I would also like the mouse to be able to signal the host to come out of suspend, however despite enabling the WKUINT and adding some stub code to handle it (see below), the interrupt never happens.
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_WKUINT))
{
/* Clear wakeup interrupt */
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_WKUINT);
/* Resume USB host */
__nop(); // stub for testing
}Ai seems to think that the WKUINT does not work on some STM32 devices - is this the case?
Note: I see that the middleware DOES enable the device remote wakeup - see below:
static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
{
pdev->dev_remote_wakeup = 1U;
(void)USBD_CtlSendStatus(pdev);
}
else if (req->wValue == USB_FEATURE_TEST_MODE)
{
pdev->dev_test_mode = (uint8_t)(req->wIndex >> 8);
(void)USBD_CtlSendStatus(pdev);
}
else
{
USBD_CtlError(pdev, req);
}
}Any help would be much appreciated.
2026-02-02 9:37 AM
Hi @barryccl
Did you refer to the example provided here? For host‑initiated resume, you need to handle properly the register HPRT and read it safely.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.