Skip to content

Commit 388e8ef

Browse files
Fixed issue in F1 and F3 with HardwareSerial read(), which should return -1 if no data in the input buffer, (be non-blocking)
1 parent 8c6f302 commit 388e8ef

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

STM32F1/cores/maple/HardwareSerial.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ void HardwareSerial::end(void) {
159159
*/
160160

161161
int HardwareSerial::read(void) {
162-
// Block until a byte becomes available, to save user confusion.
163-
while (!this->available())
164-
;
165-
return usart_getc(this->usart_device);
162+
if(usart_data_available(usart_device) > 0) {
163+
return usart_getc(usart_device);
164+
} else {
165+
return -1;
166+
}
166167
}
167168

168169
int HardwareSerial::available(void) {

STM32F3/cores/maple/wirish/HardwareSerial.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ void HardwareSerial::end(void) {
118118
* I/O
119119
*/
120120

121-
uint8 HardwareSerial::read(void) {
122-
// Block until a byte becomes available, to save user confusion.
123-
while (!this->available())
124-
;
125-
return usart_getc(this->usart_device);
121+
int HardwareSerial::read(void) {
122+
if(usart_data_available(usart_device) > 0) {
123+
return usart_getc(usart_device);
124+
} else {
125+
return -1;
126+
}
126127
}
127128

128129
uint32 HardwareSerial::available(void) {

STM32F3/cores/maple/wirish/HardwareSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class HardwareSerial : public Print {
6262

6363
/* I/O */
6464
uint32 available(void);
65-
uint8 read(void);
65+
int read(void);
6666
void flush(void);
6767
virtual void write(unsigned char);
6868
using Print::write;

0 commit comments

Comments
 (0)