Skip to content

Commit 7e788c4

Browse files
committed
If sketch is not connected to serial - dump serial output
Current code would hang after a few Serial.print like statements happened when we are not connected to the Serial monitor. So I put overrides in for the Serial.write(buf, cnt) and Serial.flush() That would first check to see if Serial returns true (DTR)... This appears to match the behavior of the MBED Portenta H8 code.
1 parent 55fa748 commit 7e788c4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cores/arduino/SerialUSB.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class SerialUSB_ : public ZephyrSerial {
1818
void begin(unsigned long baudrate) { begin(baudrate, SERIAL_8N1); }
1919

2020
operator bool() override;
21+
size_t write(const uint8_t *buffer, size_t size) override;
22+
void flush() override;
2123

2224
protected:
2325
uint32_t dtr = 0;

cores/arduino/USB.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,16 @@ arduino::SerialUSB_::operator bool() {
124124
return dtr;
125125
}
126126

127+
128+
size_t arduino::SerialUSB_::write(const uint8_t *buffer, size_t size) {
129+
if (!Serial) return 0;
130+
return arduino::ZephyrSerial::write(buffer, size);
131+
}
132+
133+
void arduino::SerialUSB_::flush() {
134+
if (!Serial) return;
135+
arduino::ZephyrSerial::flush();
136+
}
137+
127138
arduino::SerialUSB_ Serial(usb_dev);
128139
#endif

0 commit comments

Comments
 (0)