Skip to content

Commit 5f9d84f

Browse files
committed
USBSerial: improve 1200bps reset routine
1 parent 2f9d2f0 commit 5f9d84f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cores/arduino/USB/PluggableUSBSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class USBSerial: public USBCDC, public ::mbed::Stream, public HardwareSerial {
294294

295295
private:
296296
RingBufferN<256> rx_buffer;
297-
rtos::Thread t;
297+
rtos::Thread* t;
298298
int _baud, _bits, _parity, _stop;
299299

300300
void onInterrupt() {

cores/arduino/USB/USBSerial.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626

2727
using namespace arduino;
2828

29+
static rtos::EventFlags event;
30+
2931
static void waitForPortClose() {
32+
33+
event.wait_any(0xFF);
3034
// wait for DTR be 0 (port closed) and timeout to be over
3135
long start = millis();
3236
static const int WAIT_TIMEOUT = 200;
@@ -37,11 +41,9 @@ static void waitForPortClose() {
3741
_ontouch1200bps_();
3842
}
3943

40-
static events::EventQueue queue(2 * EVENTS_EVENT_SIZE);
41-
4244
void usbPortChanged(int baud, int bits, int parity, int stop) {
4345
if (baud == 1200) {
44-
queue.call(waitForPortClose);
46+
event.set(1);
4547
}
4648
}
4749

@@ -68,7 +70,8 @@ USBSerial::~USBSerial()
6870
void USBSerial::begin(unsigned long) {
6971
this->attach(usbPortChanged);
7072
this->attach(::mbed::callback(this, &USBSerial::onInterrupt));
71-
t.start(callback(&queue, &::events::EventQueue::dispatch_forever));
73+
t = new rtos::Thread(osPriorityNormal, 256, nullptr, "USBevt");
74+
t->start(waitForPortClose);
7275
}
7376

7477
int USBSerial::_putc(int c)

0 commit comments

Comments
 (0)