Skip to content

Commit

Permalink
FIX: do nost send CDC ZLP when endpoint is not ready, might cause dat…
Browse files Browse the repository at this point in the history
…a corruption
  • Loading branch information
r2axz committed Dec 1, 2020
1 parent e5ce677 commit b35dcc1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions usb_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,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 @@ -322,11 +322,12 @@ 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);
}
} else {
if (cdc_state->rx_zlp_pending) {
cdc_state->rx_zlp_pending = 0;
usb_send(rx_ep, 0, 0);
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);
}
}
}
}
Expand Down

0 comments on commit b35dcc1

Please sign in to comment.