drivers: usb_dc_stm32: implement usb_dc_wakeup_request

Implement usb_dc_wakeup_request for STM32 USB DC and default to enable
remote wakeup functionality when the drivers is selected.

This allows the device to wake the host up by calling
usb_wakeup_request().

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
This commit is contained in:
Fabio Baltieri 2022-12-15 21:43:35 +00:00 committed by Carles Cufí
commit 4b48d91cce
2 changed files with 21 additions and 0 deletions

View file

@ -53,6 +53,7 @@ config USB_DC_STM32
select USE_STM32_HAL_PCD
select USE_STM32_HAL_PCD_EX
select USB_DC_HAS_HS_SUPPORT if "$(DT_STM32_USBHS_SPEED)"
imply USB_DEVICE_REMOTE_WAKEUP
help
Enable STM32 family USB device controller shim driver.

View file

@ -1038,6 +1038,26 @@ int usb_dc_ep_mps(const uint8_t ep)
return ep_state->ep_mps;
}
int usb_dc_wakeup_request(void)
{
HAL_StatusTypeDef status;
status = HAL_PCD_ActivateRemoteWakeup(&usb_dc_stm32_state.pcd);
if (status != HAL_OK) {
return -EAGAIN;
}
/* Must be active from 1ms to 15ms as per reference manual. */
k_sleep(K_MSEC(2));
status = HAL_PCD_DeActivateRemoteWakeup(&usb_dc_stm32_state.pcd);
if (status != HAL_OK) {
return -EAGAIN;
}
return 0;
}
int usb_dc_detach(void)
{
HAL_StatusTypeDef status;