Skip to content

Commit b949b94

Browse files
committed
Add check if the last packet we tried to transfer is dragging for too
long.
1 parent 08f932a commit b949b94

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: cores/arduino/stm32/usb/cdc/usbd_cdc_if.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
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 */
3739
USBD_HandleTypeDef hUSBD_Device_CDC;
@@ -43,6 +45,7 @@ CDC_TransmitQueue_TypeDef TransmitQueue;
4345
CDC_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

213216
static 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

248252
bool 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

253263
void CDC_continue_transmit(void)

0 commit comments

Comments
 (0)