tenbaht / sduino

An Arduino-like programming API for the STM8
http://tenbaht.github.io/sduino/
GNU Lesser General Public License v2.1
347 stars 213 forks source link

HardwareSerial_flush bug & proposed fix #117

Open stefaandesmet2003 opened 3 years ago

stefaandesmet2003 commented 3 years ago

Hi, HardwareSerial_flush won't flush all characters from the serial buffer. I believe the error is in this line: while (transmitting && !(UARTx->SR & UARTx_FLAG_TC)); which should be : while (transmitting || !(UARTx->SR & UARTx_FLAG_TC)); Current implementation will flush until first character is transmitted (TC flag set) and ignoring buffer empty condition (transmitting variable) I had the issue when using flush() before sleeping the STM8. Cheers, Stefaan.

daviddam71 commented 2 years ago

I just ran into the bug as well. The fix proposed worked perfectly.