Skip to content

Fixed error, when host send some buffer, less then minimum. #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cores/arduino/stm32/usb/cdc/usbd_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,18 @@ uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
}
}

uint8_t USBD_CDC_ClearBuffer(USBD_HandleTypeDef *pdev)
{
/* Suspend or Resume USB Out process */
if (pdev->pClassData != NULL) {
/* Prepare Out endpoint to receive next packet */
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, 0, 0);
return USBD_OK;
} else {
return USBD_FAIL;
}
}

#endif /* USBD_USE_CDC */
#endif /* USBCON */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
2 changes: 2 additions & 0 deletions cores/arduino/stm32/usb/cdc/usbd_cdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,

uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);

uint8_t USBD_CDC_ClearBuffer(USBD_HandleTypeDef *pdev);

uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
/**
* @}
Expand Down
8 changes: 6 additions & 2 deletions cores/arduino/stm32/usb/cdc/usbd_cdc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
CDC_ReceiveQueue_CommitBlock(&ReceiveQueue, (uint16_t)(*Len));
receivePended = false;
/* If enough space in the queue for a full buffer then continue receive */
CDC_resume_receive();
if (!CDC_resume_receive()) {
USBD_CDC_ClearBuffer(&hUSBD_Device_CDC);
}
return USBD_OK;
}

Expand Down Expand Up @@ -271,7 +273,7 @@ void CDC_continue_transmit(void)
}
}

void CDC_resume_receive(void)
bool CDC_resume_receive(void)
{
/*
* TS: main and IRQ threads can't pass it at same time, because
Expand All @@ -284,7 +286,9 @@ void CDC_resume_receive(void)
/* Set new buffer */
USBD_CDC_SetRxBuffer(&hUSBD_Device_CDC, block);
USBD_CDC_ReceivePacket(&hUSBD_Device_CDC);
return true;
}
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/stm32/usb/cdc/usbd_cdc_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern CDC_ReceiveQueue_TypeDef ReceiveQueue;
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void CDC_continue_transmit(void);
void CDC_resume_receive(void);
bool CDC_resume_receive(void);
void CDC_init(void);
void CDC_deInit(void);

Expand Down