File tree 1 file changed +11
-1
lines changed
cores/arduino/stm32/usb/cdc
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 32
32
#define CDC_MAX_PACKET_SIZE USB_MAX_EP0_SIZE
33
33
#endif
34
34
35
+ #define USB_CDC_TRANSMIT_TIMEOUT 3
36
+
35
37
/* USBD_CDC Private Variables */
36
38
/* USB Device Core CDC handle declaration */
37
39
USBD_HandleTypeDef hUSBD_Device_CDC ;
@@ -43,6 +45,7 @@ CDC_TransmitQueue_TypeDef TransmitQueue;
43
45
CDC_ReceiveQueue_TypeDef ReceiveQueue ;
44
46
__IO uint32_t lineState = 0 ;
45
47
__IO bool receivePended = true;
48
+ static uint32_t transmitStart = 0 ;
46
49
47
50
48
51
/** USBD_CDC Private Function Prototypes */
@@ -212,6 +215,7 @@ static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
212
215
213
216
static int8_t USBD_CDC_Transferred (void )
214
217
{
218
+ transmitStart = 0 ;
215
219
CDC_TransmitQueue_CommitRead (& TransmitQueue );
216
220
CDC_continue_transmit ();
217
221
return (USBD_OK );
@@ -247,7 +251,13 @@ void CDC_deInit(void)
247
251
248
252
bool CDC_connected ()
249
253
{
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 ;
251
261
}
252
262
253
263
void CDC_continue_transmit (void )
You can’t perform that action at this time.
0 commit comments