2

Win10, STM32CubeMx ver. 6.5.0, STM32CubeIDE ver. 1.18.0, MCU - STM32F103C6

I'm creating a new project using either STM32CubeMX or STM32CubeIDE. In the Pinout & Configuration window, I configure USB for data transfer. Under the Middleware > USB_DEVICE tab, I select VPC mode. I leave other settings at their defaults. The clock is configured to use an external 8 MHz oscillator.

Next, I set up the microcontroller’s clock tree. In the Code generation settings, I enable the option Generate peripheral initialization as a pair of [...].

After generating the code, I notice that the GPIO pins PA11 and PA12 (USB D+ and D-) are not fully configured: no pull-up/pull-down resistors, no alternate function mode, etc. Here are examples of the generated code:

void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) {
  if (pcdHandle->Instance == USB) {
    /* USER CODE BEGIN USB_MspInit 0 */
    /* USER CODE END USB_MspInit 0 */
    __HAL_RCC_USB_CLK_ENABLE(); // Enable USB clock
    HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
    /* USER CODE BEGIN USB_MspInit 1 */
    /* USER CODE END USB_MspInit 1 */
  }
}

void MX_GPIO_Init(void) {
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE(); 
}

Other peripherals (e.g., timers) generate code correctly.

Question: Why are PA11 and PA12 not configured for USB, despite selecting USB_DEVICE in CubeMX?

I tried reinstalling the software, logging into the ST account, and testing different USB operation modes.

2
  • 3
    No further configuration is needed for these pins, other than enabling the USB module. From the STM32F10x reference manual: "As soon as the USB is enabled, these pins are automatically connected to the USB internal transceiver." Commented Mar 14 at 2:47
  • Yes, you are correct. Thank you very much. I need to review the reference manual more carefully. Commented Mar 17 at 14:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.