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.
2026-02-03 3:37 AM
Thanks FBL, but unfortunately the examples are very old and use a much earlier version of the host stack, but in any case I don't see any reference to resume (or suspend). Apologies if I am missing something - please give me a pointer.
Are the rules for accessing the HPRT register documented anywhere? In RM0410 I see this:
Host suspend
The application decides to suspend the USB activity by setting the port suspend bit in the
host port control and status register (PSUSP bit in OTG_HPRT). The OTG_FS/OTG_HS
core stops sending SOFs and enters the suspended state.
The suspended state can be optionally exited on the remote device’s initiative (remote
wakeup). In this case the remote wakeup interrupt (WKUPINT bit in OTG_GINTSTS) is
generated upon detection of a remote wakeup signaling, the port resume bit in the host port
control and status register (PRES bit in OTG_HPRT) self-sets, and resume signaling is
automatically driven over the USB. The application must time the resume window and then
clear the port resume bit to exit the suspended state and restart the SOF.
If the suspended state is exited on the host initiative, the application must set the port
resume bit to start resume signaling on the host port, time the resume window and finally
clear the port resume bit.
I think the Ai generated code is doing this - at least for host resume?