summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-10-31 15:43:45 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-10-31 15:43:45 -0700
commit268bf6f99e325acf1385b7b1dfe4ac0584c1667f (patch)
tree9a24dcc27a11f08e1d856df9ff426f73a44ced5e
parent8c7571a75d7839702dc2626e91a5da9a564022cd (diff)
atmel-samd: Fix non-DEBUG USB cdc.
I believe the issue was that LTO exacerbates a problem where a CDC read is initiated but fails and leaves pending_read true preventing further reads.
-rw-r--r--ports/atmel-samd/usb.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/ports/atmel-samd/usb.c b/ports/atmel-samd/usb.c
index 993ac7eaa..740486aa1 100644
--- a/ports/atmel-samd/usb.c
+++ b/ports/atmel-samd/usb.c
@@ -107,7 +107,11 @@ static volatile bool pending_read;
static int32_t start_read(void) {
pending_read = true;
- return cdcdf_acm_read(cdc_packet_buffer, 64);
+ int32_t result = cdcdf_acm_read(cdc_packet_buffer, 64);
+ if (result != ERR_NONE) {
+ pending_read = false;
+ }
+ return result;
}
static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count) {
@@ -222,7 +226,7 @@ void init_usb(void) {
usbdc_attach();
}
-static inline bool cdc_enabled(void) {
+static bool cdc_enabled(void) {
if (mp_cdc_enabled) {
return true;
}
@@ -239,11 +243,10 @@ static inline bool cdc_enabled(void) {
}
bool usb_bytes_available(void) {
- if (!pending_read) {
+ if (cdc_enabled() && !pending_read) {
start_read();
}
if (usb_rx_count == 0) {
- cdc_enabled();
return false;
}
return usb_rx_count > 0;