While working on a project based on STM32F202VG, I experienced intermittent and unexplainable problems with USB used with CDC class.
Sometimes everything was working perfectly, but after power-cycling the board or the PC, opening the COM port failed with a Windows "Incorrect parameter" error.
After an in-depth analysis, I discovered a difference between correc" and incorrect initialization.
The two sequences are identical up to a certain point. Then, there is a difference in a setup packet from the board to the PC.
See the transcript from Device Monitoring Studio:
Control Transfer (UP), 2017-05-14 18:15:21,8528439 +0,0001177. (1. Device: STMicroelectronics Virtual COM Port (COM13)) Status: 0x00000000
Pipe Handle: Control Pipe00 00 00 00 00 00 00
Control Transfer (UP), 2017-05-14 18:14:31,2491097 +0,0001700. (1. Device: STMicroelectronics Virtual COM Port (COM13)) Status: 0x00000000
Pipe Handle: Control Pipe80 64 06 2B 3E 50 1B
...pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));memset(pdev->pClassData,0,sizeof(USBD_CDC_HandleTypeDef)); // THIS LINE WAS ADDEDif(pdev->pClassData == NULL)...
If needed, I have the full trasncripts of the "good" and "bad" USB initialization sequence.
I am using STM32Cube FW_F2 V1.6.0