diff options
| author | Scott Shawcroft <scott@chickadee.tech> | 2016-10-25 18:23:04 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@chickadee.tech> | 2016-10-25 18:29:04 -0700 |
| commit | 614c1fdba2aca393e6769221cf8d8b55ee3464fe (patch) | |
| tree | 2671d97622b368026b29c4d7a3c700c75713c425 | |
| parent | b7768a74a72fdb37d6d128bd8b3eafc7159fcd3e (diff) | |
atmel-samd: Only output to USB after DTR and don't send anything larger than the room left in the USB TX buffer.
| -rw-r--r-- | atmel-samd/boards/arduino_zero/conf_usb.h | 6 | ||||
| -rw-r--r-- | atmel-samd/mphalport.c | 15 |
2 files changed, 17 insertions, 4 deletions
diff --git a/atmel-samd/boards/arduino_zero/conf_usb.h b/atmel-samd/boards/arduino_zero/conf_usb.h index d1ee1e849..4702fe93b 100644 --- a/atmel-samd/boards/arduino_zero/conf_usb.h +++ b/atmel-samd/boards/arduino_zero/conf_usb.h @@ -54,8 +54,10 @@ extern void mp_cdc_disable(uint8_t port); #define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() void usb_rx_notify(void); #define UDI_CDC_SET_CODING_EXT(port,cfg) -#define UDI_CDC_SET_DTR_EXT(port,set) -#define UDI_CDC_SET_RTS_EXT(port,set) +#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) +void usb_dtr_notify(uint8_t port, bool set); +#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) +void usb_rts_notify(uint8_t port, bool set); /** * USB CDC low level configuration diff --git a/atmel-samd/mphalport.c b/atmel-samd/mphalport.c index 3b70b3d05..7102bf220 100644 --- a/atmel-samd/mphalport.c +++ b/atmel-samd/mphalport.c @@ -50,7 +50,7 @@ void mp_msc_disable() bool mp_cdc_enable(uint8_t port) { - mp_cdc_enabled = true; + mp_cdc_enabled = false; return true; } @@ -59,6 +59,14 @@ void mp_cdc_disable(uint8_t port) mp_cdc_enabled = false; } +void usb_dtr_notify(uint8_t port, bool set) { + mp_cdc_enabled = set; +} + +void usb_rts_notify(uint8_t port, bool set) { + return; +} + void usb_rx_notify(void) { irqflags_t flags; @@ -177,7 +185,10 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) { #endif #ifdef USB_REPL - if (mp_cdc_enabled && udi_cdc_is_tx_ready()) { + // Always make sure there is enough room in the usb buffer for the outgoing + // string. If there isn't we risk getting caught in a loop within the usb + // code as it tries to send all the characters it can't buffer. + if (mp_cdc_enabled && udi_cdc_get_free_tx_buffer() >= len) { udi_cdc_write_buf(str, len); } #endif |
