cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX IDE code for Nucleo F303ZE virtual comm port does not detect USB cable disconnect.

DGeie.1
Associate

I am trying to use USB port on a Nucleo-F303ZE board as CDC.  I am using the latest CubeMX IDE.  To get the PC to recognize USB device, I had to modify the HAL_PCDEx_SetConnectionState function as follows to get PC to recognize the USB device:

void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)

{

 /* USER CODE BEGIN 6 */

 HAL_GPIO_WritePin(USB_PowerSwitchOn_GPIO_Port,USB_PowerSwitchOn_Pin,state);

 /* USER CODE END 6 */

}

However, the USB CDC_DeInit_FS is not getting called when the USB cable is disconnected. It is getting called when the cable is re-inserted. Re-inserting the USB cable triggers the USB_LP_CAN_RX0_IRQ which eventually calls the CDC DeInit.

void USB_LP_CAN_RX0_IRQHandler(void)

{

 /* USER CODE BEGIN USB_LP_CAN_RX0_IRQn 0 */

 /* USER CODE END USB_LP_CAN_RX0_IRQn 0 */

 HAL_PCD_IRQHandler(&hpcd_USB_FS);

 /* USER CODE BEGIN USB_LP_CAN_RX0_IRQn 1 */

 /* USER CODE END USB_LP_CAN_RX0_IRQn 1 */

}

After re-inserting the USB cable, the DeInit is called followed by an Init.

What do I need to change to get the Nucleo to recognize the USB cable has been disconnected?

Thanks

0 REPLIES 0