File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
cores/arduino/stm32/usb/cdc Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 3232#define CDC_MAX_PACKET_SIZE USB_MAX_EP0_SIZE
3333#endif
3434
35+ #define USB_CDC_TRANSMIT_TIMEOUT 3
36+
3537/* USBD_CDC Private Variables */
3638/* USB Device Core CDC handle declaration */
3739USBD_HandleTypeDef hUSBD_Device_CDC ;
@@ -43,6 +45,7 @@ CDC_TransmitQueue_TypeDef TransmitQueue;
4345CDC_ReceiveQueue_TypeDef ReceiveQueue ;
4446__IO uint32_t lineState = 0 ;
4547__IO bool receivePended = true;
48+ static uint32_t transmitStart = 0 ;
4649
4750
4851/** USBD_CDC Private Function Prototypes */
@@ -212,6 +215,7 @@ static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
212215
213216static int8_t USBD_CDC_Transferred (void )
214217{
218+ transmitStart = 0 ;
215219 CDC_TransmitQueue_CommitRead (& TransmitQueue );
216220 CDC_continue_transmit ();
217221 return (USBD_OK );
@@ -247,7 +251,13 @@ void CDC_deInit(void)
247251
248252bool CDC_connected ()
249253{
250- return hUSBD_Device_CDC .dev_state == USBD_STATE_CONFIGURED && lineState ;
254+ uint32_t transmitTime = 0 ;
255+ if (transmitStart ) {
256+ transmitTime = HAL_GetTick () - transmitStart ;
257+ }
258+ return hUSBD_Device_CDC .dev_state == USBD_STATE_CONFIGURED
259+ && transmitTime < USB_CDC_TRANSMIT_TIMEOUT
260+ && lineState ;
251261}
252262
253263void CDC_continue_transmit (void )
You can’t perform that action at this time.
0 commit comments