From 8f932bedfd0cc3570c663a6c9ecfcbd746f6d156 Mon Sep 17 00:00:00 2001 From: Peter Dmr Date: Tue, 11 Nov 2025 18:30:25 +0000 Subject: [PATCH] Fix listening for a Start-Of-Frame byte --- first-steps/3-simple-uart-protocol/mcu/sup.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/first-steps/3-simple-uart-protocol/mcu/sup.c b/first-steps/3-simple-uart-protocol/mcu/sup.c index 67958e1..b141049 100644 --- a/first-steps/3-simple-uart-protocol/mcu/sup.c +++ b/first-steps/3-simple-uart-protocol/mcu/sup.c @@ -119,19 +119,15 @@ void sup_handle_rx_byte(const uint8_t byte) return; } - // Always listen for a Start-Of-Frame byte, which can reset a broken frame transmission. - if (byte == SUP_SOF) - { - reset_rx_frame_state(); - rx_frame_state->parsing_state = SUP_STATE_WAIT_ID; - return; - } - switch (rx_frame_state->parsing_state) { case SUP_STATE_WAIT_SOF: - // This state is effectively handled by the check above, - // but we keep the case for clarity. Any byte other than SOF is ignored. + // Listen for a Start-Of-Frame byte. Any byte other than SOF is ignored. + if (byte == SUP_SOF) + { + reset_rx_frame_state(); + rx_frame_state->parsing_state = SUP_STATE_WAIT_ID; + } break; case SUP_STATE_WAIT_ID: