stm32 - STM32CubeMx doesn't generate whole code for USB - Stack Overflow

Win10, STM32CubeMx ver. 6.5.0, STM32CubeIDE ver. 1.18.0, MCU - STM32F103C6I'm creating a new proj

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744678884a4587493.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信