From d70725e4e07f0bc4d345e6524055f2fd78569829 Mon Sep 17 00:00:00 2001 From: jsanchez-2g Date: Tue, 18 Aug 2026 14:35:17 -0500 Subject: [PATCH] arm/stm32: Fix the USB reset sequence in arm_usbinitialize(). The code that claimed to "enable clocking to the USB peripheral" cleared RCC_APB1ENR_USBEN inside RCC_APB1RSTR. That is both the wrong register and the wrong bit: USBEN belongs to RCC_APB1ENR, while APB1RSTR holds RCC_APB1RSTR_USBRST. The peripheral clock is enabled by the RCC setup performed at boot, so the write had no useful effect and merely cleared an unrelated reset bit. Issue a proper reset pulse on RCC_APB1RSTR_USBRST instead, so the controller starts from a known state. On STM32L0 the D+/D- lines are connected to the USB transceiver automatically once the peripheral is enabled and there is no alternate function to select, so skip the GPIO configuration on that chip. The board GPIO_USB_DM/GPIO_USB_DP definitions do not exist there. Assisted-by: GitHub Copilot:claude-opus-5 Signed-off-by: jsanchez-2g --- arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c b/arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c index ef5c19aa9ce..c37b559fffb 100644 --- a/arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c +++ b/arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c @@ -3684,20 +3684,19 @@ void arm_usbinitialize(void) */ struct stm32_usbdev_s *priv = &g_usbdev; - uint32_t regval; usbtrace(TRACE_DEVINIT, 0); /* Configure USB GPIO alternate function pins */ - +#ifndef CONFIG_STM32_STM32L0 stm32_configgpio(GPIO_USB_DM); stm32_configgpio(GPIO_USB_DP); +#endif - /* Enable clocking to the USB peripheral */ + /* Reset the USB peripheral */ - regval = getreg32(STM32_RCC_APB1RSTR); - regval &= ~RCC_APB1ENR_USBEN; - putreg32(regval, STM32_RCC_APB1RSTR); + modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_USBRST); + modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_USBRST, 0); /* Power up the USB controller, but leave it in the reset state */