Skip to content

Commit

Permalink
Add check if the last packet we tried to transfer is dragging for too
Browse files Browse the repository at this point in the history
long.
  • Loading branch information
ghent360 committed Feb 18, 2019
1 parent bb3117c commit e1fab94
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cores/arduino/stm32/usb/cdc/usbd_cdc_if.c
Expand Up @@ -32,6 +32,8 @@
#define CDC_MAX_PACKET_SIZE USB_MAX_EP0_SIZE
#endif

#define USB_CDC_TRANSMIT_TIMEOUT 3

/* USBD_CDC Private Variables */
/* USB Device Core CDC handle declaration */
USBD_HandleTypeDef hUSBD_Device_CDC;
Expand All @@ -43,6 +45,7 @@ CDC_TransmitQueue_TypeDef TransmitQueue;
CDC_ReceiveQueue_TypeDef ReceiveQueue;
__IO uint32_t lineState = 0;
__IO bool receivePended = true;
static uint32_t transmitStart = 0;


/** USBD_CDC Private Function Prototypes */
Expand Down Expand Up @@ -212,6 +215,7 @@ static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)

static int8_t USBD_CDC_Transferred(void)
{
transmitStart = 0;
CDC_TransmitQueue_CommitRead(&TransmitQueue);
CDC_continue_transmit();
return (USBD_OK);
Expand Down Expand Up @@ -247,7 +251,13 @@ void CDC_deInit(void)

bool CDC_connected()
{
return hUSBD_Device_CDC.dev_state == USBD_STATE_CONFIGURED && lineState;
uint32_t transmitTime = 0;
if (transmitStart) {
transmitTime = HAL_GetTick() - transmitStart;
}
return hUSBD_Device_CDC.dev_state == USBD_STATE_CONFIGURED
&& transmitTime < USB_CDC_TRANSMIT_TIMEOUT
&& lineState;
}

void CDC_continue_transmit(void)
Expand Down

0 comments on commit e1fab94

Please sign in to comment.