diff options
author | Damien George <damien.p.george@gmail.com> | 2019-05-08 12:45:24 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-05-08 12:45:24 +1000 |
commit | b8c74014e42331afca3db5911b30032a109f73f1 (patch) | |
tree | b5b089e54b131ff99a9e3f88f6a58f6182333051 | |
parent | 97753a1bbc5a20003bcf2a7f90cff2ca5c81ee92 (diff) |
stm32/usbd_cdc_interface: Don't retransmit chars if USB is reconnected.
Before this change, if the USB was reconnected it was possible that some
characters in the TX buffer were retransmitted because tx_buf_ptr_out and
tx_buf_ptr_out_shadow were reset while tx_buf_ptr_in wasn't. That
behaviour is fixed here by retaining the TX buffer state across reconnects.
Fixes issue #4761.
-rw-r--r-- | ports/stm32/usb.c | 2 | ||||
-rw-r--r-- | ports/stm32/usbd_cdc_interface.c | 10 |
2 files changed, 6 insertions, 6 deletions
diff --git a/ports/stm32/usb.c b/ports/stm32/usb.c index 18841fdee..8b7608a15 100644 --- a/ports/stm32/usb.c +++ b/ports/stm32/usb.c @@ -69,7 +69,7 @@ typedef struct _usb_device_t { usbd_hid_itf_t usbd_hid_itf; } usb_device_t; -usb_device_t usb_device; +usb_device_t usb_device = {0}; pyb_usb_storage_medium_t pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_NONE; // predefined hid mouse data diff --git a/ports/stm32/usbd_cdc_interface.c b/ports/stm32/usbd_cdc_interface.c index 586f2d525..4a4a8beb8 100644 --- a/ports/stm32/usbd_cdc_interface.c +++ b/ports/stm32/usbd_cdc_interface.c @@ -64,14 +64,14 @@ static uint8_t usbd_cdc_connect_tx_timer; uint8_t *usbd_cdc_init(usbd_cdc_state_t *cdc_in) { usbd_cdc_itf_t *cdc = (usbd_cdc_itf_t*)cdc_in; - // Reset all the CDC state - // Note: we don't reset tx_buf_ptr_in in order to allow the output buffer to - // be filled (by usbd_cdc_tx_always) before the USB device is connected. + // Reset the CDC state due to a new USB host connection + // Note: we don't reset tx_buf_ptr_* in order to allow the output buffer to + // be filled (by usbd_cdc_tx_always) before the USB device is connected, and + // to retain transmit buffer state across multiple USB connections (they will + // be 0 at MCU reset since the variables live in the BSS). cdc->rx_buf_put = 0; cdc->rx_buf_get = 0; cdc->rx_buf_full = false; - cdc->tx_buf_ptr_out = 0; - cdc->tx_buf_ptr_out_shadow = 0; cdc->tx_need_empty_packet = 0; cdc->connect_state = USBD_CDC_CONNECT_STATE_DISCONNECTED; |