From acfc9d130b01fe260c49699ae4fdb6db7a9021d0 Mon Sep 17 00:00:00 2001 From: Anthony DiGirolamo Date: Fri, 5 Feb 2021 21:57:35 -0800 Subject: [PATCH] pw_sys_io_arduino: Fix broken while loop in WriteByte This was causing hangs. Removed since Serial.write will block under the hood as is. Change-Id: I4ce5caedbd0f9e371e1c0c916c4ee963f838a6aa Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/31973 Reviewed-by: Stan Iliev Reviewed-by: Anthony DiGirolamo Pigweed-Auto-Submit: Anthony DiGirolamo Commit-Queue: Auto-Submit --- pw_sys_io_arduino/sys_io_arduino.cc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pw_sys_io_arduino/sys_io_arduino.cc b/pw_sys_io_arduino/sys_io_arduino.cc index 9e86c73f5..4709ad5aa 100644 --- a/pw_sys_io_arduino/sys_io_arduino.cc +++ b/pw_sys_io_arduino/sys_io_arduino.cc @@ -44,15 +44,9 @@ Status TryReadByte(std::byte* dest) { return OkStatus(); } -// Send a byte over USART1. Since this blocks on every byte, it's rather -// inefficient. At the default baud rate of 115200, one byte blocks the CPU for -// ~87 micro seconds. This means it takes only 10 bytes to block the CPU for -// 1ms! +// Send a byte over the default Arduino Serial port. Status WriteByte(std::byte b) { - // Wait for TX buffer to be empty. When the buffer is empty, we can write - // a value to be dumped out of UART. - while (Serial.availableForWrite() < 1) { - } + // Serial.write() will block until data can be written. Serial.write((uint8_t)b); return OkStatus(); }