From 0146cc851d2e3308107b0133072957a87972430c Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Tue, 10 Jul 2012 22:10:11 +0200 Subject: [PATCH 1/2] Leonardo: after burning a sketch, remove the magic baud rate (1200bps) to avoid future unwanted board resets --- app/src/processing/app/debug/AvrdudeUploader.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/debug/AvrdudeUploader.java b/app/src/processing/app/debug/AvrdudeUploader.java index b88f6a82977..1948f961505 100755 --- a/app/src/processing/app/debug/AvrdudeUploader.java +++ b/app/src/processing/app/debug/AvrdudeUploader.java @@ -185,7 +185,12 @@ private boolean uploadViaBootloader(String buildPath, String className) long timeout = System.currentTimeMillis() + 2000; while (timeout > System.currentTimeMillis()) { List portList = Serial.list(); - if (portList.contains(Preferences.get("serial.port"))) { + uploadPort = Preferences.get("serial.port"); + if (portList.contains(uploadPort)) { + // Remove the magic baud rate (1200bps) to avoid future unwanted board resets + int serialRate = Preferences.getInteger("serial.debug_rate"); + System.out.println("Set baud rate to " + serialRate); + Serial.touchPort(uploadPort, serialRate); break; } try { From d65cb70de139f30aa87cc936d8bfbb1060c3aa26 Mon Sep 17 00:00:00 2001 From: Peter Van Hoyweghen Date: Mon, 30 Jul 2012 21:54:19 +0200 Subject: [PATCH 2/2] Avoid serial buffer overrun on leonardo --- hardware/arduino/cores/arduino/CDC.cpp | 10 ++++++++-- hardware/arduino/cores/arduino/USBCore.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/cores/arduino/CDC.cpp b/hardware/arduino/cores/arduino/CDC.cpp index 1ee3a488a5e..701e48398fc 100644 --- a/hardware/arduino/cores/arduino/CDC.cpp +++ b/hardware/arduino/cores/arduino/CDC.cpp @@ -141,16 +141,22 @@ void Serial_::end(void) void Serial_::accept(void) { ring_buffer *buffer = &cdc_rx_buffer; - int c = USB_Recv(CDC_RX); int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; // if we should be storing the received character into the location // just before the tail (meaning that the head would advance to the // current location of the tail), we're about to overflow the buffer // and so we don't write the character or advance the head. - if (i != buffer->tail) { + + // while we have room to store a byte + while (i != buffer->tail) { + int c = USB_Recv(CDC_RX); + if (c == -1) + break; // no more data buffer->buffer[buffer->head] = c; buffer->head = i; + + i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; } } diff --git a/hardware/arduino/cores/arduino/USBCore.cpp b/hardware/arduino/cores/arduino/USBCore.cpp index 6766be61ab2..8bcf66c5419 100644 --- a/hardware/arduino/cores/arduino/USBCore.cpp +++ b/hardware/arduino/cores/arduino/USBCore.cpp @@ -603,7 +603,7 @@ ISR(USB_GEN_vect) { #ifdef CDC_ENABLED USB_Flush(CDC_TX); // Send a tx frame if found - while (USB_Available(CDC_RX)) // Handle received bytes (if any) + if (USB_Available(CDC_RX)) // Handle received bytes (if any) Serial.accept(); #endif