cancel
Showing results for 
Search instead for 
Did you mean: 

AFR settings for USB pins using CubeMX

bnp979
Associate III
Posted on November 10, 2014 at 19:46

I am using the CubeMX interface to setup MSC class USB device software for my STM32L1 device.

I notice that as part of USB initialization nowhere in the code are the GPIO AFR settings corresponding to USB DM and USB DP pins (PA11 & PA12) being set. Isn't this an issue?

The reset value for the AFR registers are listed in the datasheet as 0, which certainly isn't associating these pins with USB.

Thanks

Ben

#usb-afr-gpio
2 REPLIES 2
stm32cube-t
Senior III
Posted on November 13, 2014 at 16:16

Hello,

Not an MX issue.

DS clarification probably required: these functions should be clearly stated as additional functions and not alternate functions, which means that these functions are directly enabled through the peripheral registers instead of the GPIOx_AFR registers. Consequently, MX does not need to generate GPIO initialization code for these.

Best regards.

seth
Associate II
Posted on January 07, 2015 at 15:56

Could you offer some clarification on how this function is enabled in the pins (PA11/PA12)?  In my experience with STM32Cube_FW_L1_V1.0.0 all of the USB examples have the following code snippet to configure the IOs.

  /* Configure USB DM/DP pin. This is optional, and maintained only for user guidance.

     For the STM32L products there is no need to configure the PA12/PA11 pins couple 

     as Alternate Function */

  GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);

  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

When using CubeMX to generate a project targeting the same platform this code was not present in the generated project and the device failed to even properly enumerate.  I copied them from an example into the output from CubeMX and things started working much better.  Clearly the lines are NOT optional as the comment suggests since without them things do not work properly... or perhaps there is something I don't yet understand about the configuration of your usb hardware/software?