diff --git a/src/devices/BuildHat/Brick.cs b/src/devices/BuildHat/Brick.cs index b044ccf09f..38064d16b3 100644 --- a/src/devices/BuildHat/Brick.cs +++ b/src/devices/BuildHat/Brick.cs @@ -1564,15 +1564,40 @@ private void Reset() private string GetRawVersion() { PortWrite(GetFirmwareVersion); - PortReadLine(); - return PortReadExisting(); + return PortReadUntil(FirmwareVersion); } private string GetRawSignature() { PortWrite("signature\r"); - PortReadLine(); - return PortReadLine(); + return PortReadUntil(FirmwareSignature); + } + + // Reads complete lines from the port until one contains the expected + // marker. Relying on ReadLine (which waits for the newline terminator) + // instead of a fixed delay or ReadExisting makes the reads independent + // of the board speed and serial timing, which differ a lot between + // boards (for example a faster Raspberry Pi 5 may return before the + // firmware has answered). The firmware can prepend echo, prompt or + // asynchronous lines before the answer, so several lines may need to be + // skipped before the expected one is found. + private string PortReadUntil(string marker) + { + // The expected answer normally comes within the first couple of + // lines; the extra budget covers echo, the prompt and any + // asynchronous port notifications that may be interleaved. + const int MaximumLines = 10; + string line = string.Empty; + for (int i = 0; i < MaximumLines; i++) + { + line = PortReadLine(); + if (line.Contains(marker)) + { + break; + } + } + + return line; } private string GetRawVoltage() diff --git a/src/devices/BuildHat/data/firmware.bin b/src/devices/BuildHat/data/firmware.bin index 6bd36fff5e..f6dcde379a 100644 Binary files a/src/devices/BuildHat/data/firmware.bin and b/src/devices/BuildHat/data/firmware.bin differ diff --git a/src/devices/BuildHat/data/signature.bin b/src/devices/BuildHat/data/signature.bin index b99b88af36..8f495fa0b7 100644 --- a/src/devices/BuildHat/data/signature.bin +++ b/src/devices/BuildHat/data/signature.bin @@ -1 +1 @@ -; >g]mVV!Lٙ ]NF鴋X|[-;&X8\Son|$ \ No newline at end of file +N.2wSmQ/IӍm )io\~IAz4ĘɅPw>\w LV \ No newline at end of file diff --git a/src/devices/BuildHat/data/version b/src/devices/BuildHat/data/version index e77edc74d0..1f3109b76c 100644 --- a/src/devices/BuildHat/data/version +++ b/src/devices/BuildHat/data/version @@ -1 +1 @@ -1636109636 +1737564117