drivers: usb_dc_stm32: implement usb_dc_detach()
Implement support to detach USB device. Signed-off-by: romain pelletant <romainp@kickmaker.net>
This commit is contained in:
parent
0b4d33bcbb
commit
8aa4164518
|
@ -348,6 +348,22 @@ static int usb_dc_stm32_clock_enable(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int usb_dc_stm32_clock_disable(void)
|
||||
{
|
||||
const struct device *clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
|
||||
struct stm32_pclken pclken = {
|
||||
.bus = USB_CLOCK_BUS,
|
||||
.enr = USB_CLOCK_BITS,
|
||||
};
|
||||
|
||||
if (clock_control_off(clk, (clock_control_subsys_t *)&pclken) != 0) {
|
||||
LOG_ERR("Unable to disable USB clock");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(USB_OTG_FS) || defined(USB_OTG_HS)
|
||||
static uint32_t usb_dc_stm32_get_maximum_speed(void)
|
||||
{
|
||||
|
@ -994,7 +1010,8 @@ int usb_dc_ep_mps(const uint8_t ep)
|
|||
|
||||
int usb_dc_detach(void)
|
||||
{
|
||||
LOG_ERR("Not implemented");
|
||||
HAL_StatusTypeDef status;
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_SOC_SERIES_STM32WBX
|
||||
/* Specially for STM32WB, unlock the HSEM when USB is no more used. */
|
||||
|
@ -1008,6 +1025,22 @@ int usb_dc_detach(void)
|
|||
*/
|
||||
#endif /* CONFIG_SOC_SERIES_STM32WBX */
|
||||
|
||||
LOG_DBG("HAL_PCD_DeInit");
|
||||
status = HAL_PCD_DeInit(&usb_dc_stm32_state.pcd);
|
||||
if (status != HAL_OK) {
|
||||
LOG_ERR("PCD_DeInit failed, %d", (int)status);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = usb_dc_stm32_clock_disable();
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (irq_is_enabled(USB_IRQ)) {
|
||||
irq_disable(USB_IRQ);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue