Skip to content

Commit

Permalink
FIX: do not send CDC ZLP when endpoint is not ready, this bug might c…
Browse files Browse the repository at this point in the history
…ause rx data corruption
  • Loading branch information
r2axz committed Dec 1, 2020
1 parent c371133 commit e64537e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions usb_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ static void usb_cdc_port_send_rx_usb(int port) {
circ_buf_t *rx_buf = &cdc_state->rx_buf;
uint8_t rx_ep = usb_cdc_get_port_data_ep(port);
size_t rx_bytes_available = circ_buf_count(rx_buf->head, rx_buf->tail, USB_CDC_BUF_SIZE);
if (rx_bytes_available) {
size_t ep_space_available = usb_space_available(rx_ep);
if (ep_space_available) {
size_t ep_space_available = usb_space_available(rx_ep);
if (ep_space_available) {
if (rx_bytes_available) {
if (cdc_state->line_coding.bDataBits == usb_cdc_data_bits_7) {
size_t bytes_count = ep_space_available < rx_bytes_available ? ep_space_available : rx_bytes_available;
uint8_t *buf_ptr = &rx_buf->data[rx_buf->tail];
Expand All @@ -340,11 +340,11 @@ static void usb_cdc_port_send_rx_usb(int port) {
}
cdc_state->rx_zlp_pending = (usb_circ_buf_send(rx_ep, rx_buf, USB_CDC_BUF_SIZE) == ep_space_available);
usb_cdc_update_port_rts(port);
}
} else {
if (cdc_state->rx_zlp_pending) {
cdc_state->rx_zlp_pending = 0;
usb_send(rx_ep, 0, 0);
} else {
if (cdc_state->rx_zlp_pending) {
cdc_state->rx_zlp_pending = 0;
usb_send(rx_ep, 0, 0);
}
}
}
}
Expand Down

0 comments on commit e64537e

Please sign in to comment.