STM32L4R9I-DISCO USB Virtual COM Port - "Unknown Device" Issues
PCB Silkscreen: MB1311C (No revision number visible)
IDE: Keil uVision 5.16a
FW: STM32Cube_FW_L4_V1.14.0
STM32CubeMX Version: 5.3.0
PC OS: WIndows 7 Ultimate 64-bit
ST VCP Driver Version: 1.5.0
I am experiencing two issues related to this error. If I need to create separate posts for each, please let me know and I apologize in advance. I am new to this processor so bear with me. Let me preface by saying that I have been able to successfully get the VCP functionality working on my devkit, but I am still experiencing intermittent issues.
Issue A. USB low-power must be enabled for USB to work. Why is this? Is this an error with STM32CubeMX?
Steps to reproduce:
- Open STM32CubeMX and create a project by selecting the STM32L4R9I-DISCO board.
- It will ask you to initialize all peripherals to default. Select "Yes".
- Under Pinout & Configuration -> Connectivity -> USB_OTG_FS, set the mode to Device Only. DO NOT enable "Low power" in the "Parameter Settings" tab.
- Under Pinout & Configuration -> Middleware -> USB_DEVICE, set "Class For FS IP" to "Communications Device Class (Virtual Port Com)".
- Click the "Project Manager" tab, configure the project with a stack and heap size of 0x1000 for MDK-ARM V5.
- Generate the code, build and run the project.
- Plug in the USB cable and wait. You receive "Unknown Device"
- Now repeat steps 1-6, and be sure to ENABLE "Low power" mode in step 3.
- Plug in the USB cable. Device is immediately recognized as a virtual COM port device.
After comparing the two projects created in the above steps, I see the following key differences:
I. The "Low power" project sets up the USB interrupt (below), whereas the non-low-power variant doesn't in usbd_conf.c.
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
if(pcdHandle->Init.low_power_enable == 1)
{
/* Enable EXTI Line 17 for USB wakeup */
__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT();
}II. OTG_FS_IRQHandler() is declared in stm32l4xx_it.c (below) in the "Low-power" variant while not being declared in the non-low-power variant.
/**
* @brief This function handles USB OTG FS global interrupt.
*/
void OTG_FS_IRQHandler(void)
{
/* USER CODE BEGIN OTG_FS_IRQn 0 */
/* USER CODE END OTG_FS_IRQn 0 */
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
/* USER CODE BEGIN OTG_FS_IRQn 1 */
/* USER CODE END OTG_FS_IRQn 1 */
}Any thoughts, comments, or feedback on this? Again I am new to USB on the STM32, so this might be a silly question :).
Issue B. Unplugging and plugging the USB cable into the PC multiple (5-10) times eventually results in "Unknown Device" within Device Manager.
Steps to reproduce:
- Create a "Low-power" USB project using STM32CubeMX as mentioned above in step 8.
- Load and run the code on the devkit and wait for the PC to properly recognize the virtual COM port.
- Unplug the USB cable and wait for the device to disappear from device manager.
- Plug the USB cable back into the PC and wait for it to be properly recognized as a virtual COM port.
- Repeat steps 3 and 4 ten times. During this time, the device will stop being recognized and will appear as an "Unknown Device". Unplugging and re-plugging the USB cable does not resolve the problem and the firmware appears to have locked up.
Thoughts, comments, or feedback?
Thanks for any help or insight received!
Derek
