cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151 USB - What actually switches PA11/PA12 from GPIO to USB?

jcwren
Associate
Posted on August 20, 2012 at 20:06

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-pa12
11 REPLIES 11
arnaud239955
Associate II
Posted on October 07, 2015 at 22:10

And a call to

void

MX_GPIO_Init_Exit_Stop (void)

{

  /* GPIO Ports Clock Enable */

  __GPIOC_CLK_ENABLE();

  __GPIOH_CLK_ENABLE();

  __GPIOA_CLK_ENABLE();

  __GPIOB_CLK_ENABLE();

}

in the interrupt routine that exits the application from stop mode.

Zirco

pakuri.saito
Associate

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.