Commit 581d43b7 authored by Damien George's avatar Damien George

stm32/usbd_cdc_interface: Check and handle CDC TX wrap-overflow.

If the device is not connected over USB CDC to a host then all output to
the CDC (eg initial boot messages) is written to the CDC TX buffer with
wrapping, so that the most recent data is retained when the USB CDC is
eventually connected (eg so the REPL banner is displayed upon connection).

This commit fixes a bug in this behaviour, which was likely introduced in
e4fcd216, where the initial data in the CDC
TX buffer is repeated multiple times on first connection of the device to
the host.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent a93d9b8c
......@@ -196,9 +196,13 @@ static uint16_t usbd_cdc_tx_send_length(usbd_cdc_itf_t *cdc) {
return MIN(usbd_cdc_tx_buffer_size(cdc), to_end);
}
static void usbd_cdc_tx_buffer_put(usbd_cdc_itf_t *cdc, uint8_t data) {
static void usbd_cdc_tx_buffer_put(usbd_cdc_itf_t *cdc, uint8_t data, bool check_overflow) {
cdc->tx_buf[usbd_cdc_tx_buffer_mask(cdc->tx_buf_ptr_in)] = data;
cdc->tx_buf_ptr_in++;
if (check_overflow && usbd_cdc_tx_buffer_size(cdc) > USBD_CDC_TX_DATA_SIZE) {
cdc->tx_buf_ptr_out++;
cdc->tx_buf_ptr_out_next = cdc->tx_buf_ptr_out;
}
}
static uint8_t *usbd_cdc_tx_buffer_getp(usbd_cdc_itf_t *cdc, uint16_t len) {
......@@ -353,7 +357,7 @@ int usbd_cdc_tx(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len, uint32_t
}
// Write data to device buffer
usbd_cdc_tx_buffer_put(cdc, buf[i]);
usbd_cdc_tx_buffer_put(cdc, buf[i], false);
}
usbd_cdc_try_tx(cdc);
......@@ -386,7 +390,7 @@ void usbd_cdc_tx_always(usbd_cdc_itf_t *cdc, const uint8_t *buf, uint32_t len) {
}
}
usbd_cdc_tx_buffer_put(cdc, buf[i]);
usbd_cdc_tx_buffer_put(cdc, buf[i], true);
}
usbd_cdc_try_tx(cdc);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment