2012-08-20 11:06 AM
I have a design that was switched from an STM32F103ZDT6 to a STM32L151ZDT6. On the 'F103, the USB functioned perfectly, but on the 'L151, I'm having trouble getting it going.
Looking at all the various source in the STM32_USB-FS-Device_Lib_V3.4.0 files, NOWHERE does it ever set GPIO_AF_USB to configure PA11/PA12 from GPIO to USB. As near as I can tell, it appears that this may happen as soon as the RCC_APB1ENR_USBEN bit is set in RCC_APB1ENR.Is this actually the case? If so, I cannot find ANY references in the documentation that GPIO_AF_USB in the GPIOx_AFR registers, along with GPIO_Mode_AF and the various pull-up/pull-down bits do not need to be set for the USB peripheral.If this is the case, why does GPIO_AF_USB in the GPIOx_AFR registers even exist?--jc #stm32l151-usb-pa11-pa122015-10-07 01:10 PM
2018-09-20 07:24 PM
don't use USB (save leak current)
HAL_NVIC_DisableIRQ(USB_LP_IRQn);
HAL_PCD_DeInit(&hpcd_USB_FS);
HAL_PCD_DevDisconnect(&hpcd_USB_FS);
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_11, LL_GPIO_MODE_ANALOG);
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_ANALOG);
Enable USB
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_11, LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_INPUT);
MX_USB_DEVICE_Init();
HAL_NVIC_EnableIRQ(USB_LP_IRQn);
Even if AF is set, USB can't use it. But when it's set as In-port, it can be used now.