From e7aa562c0ba467267e7db306fe994093facbff10 Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Wed, 25 Feb 2026 11:41:07 +0100 Subject: [PATCH] sync --- buzzer_tool/config.yaml | 3 ++- firmware/src/protocol.c | 2 ++ firmware/src/usb.c | 12 ++++++++++++ firmware/src/usb.h | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/buzzer_tool/config.yaml b/buzzer_tool/config.yaml index ee8d3b4..4a928aa 100644 --- a/buzzer_tool/config.yaml +++ b/buzzer_tool/config.yaml @@ -1,4 +1,5 @@ # config.yaml serial: port: "COM15" - baudrate: 112500 \ No newline at end of file + baudrate: 112500 + timeout: 20 \ No newline at end of file diff --git a/firmware/src/protocol.c b/firmware/src/protocol.c index ba4864d..1731522 100644 --- a/firmware/src/protocol.c +++ b/firmware/src/protocol.c @@ -208,6 +208,7 @@ void execute_current_command(void) } else { + usb_flush_rx(); send_error(rc); } break; @@ -222,6 +223,7 @@ protocol_state_t waiting_for_command(uint8_t byte) { if (byte < 'a' || byte > 'z') { + LOG_DBG("Ignoring non-command byte: 0x%02x", byte); // Nur aktivieren, wenn nötig! rx_index = 0; return PS_WAITING_FOR_COMMAND; } diff --git a/firmware/src/usb.c b/firmware/src/usb.c index 2c96317..8044086 100644 --- a/firmware/src/usb.c +++ b/firmware/src/usb.c @@ -95,6 +95,18 @@ void usb_write_buffer(const uint8_t *buf, size_t len) } } +void usb_flush_rx(void) +{ + uint8_t dummy; + if (!device_is_ready(cdc_dev)) return; + + // Alles lesen, was gerade im Hardware-FIFO liegt + while (uart_fifo_read(cdc_dev, &dummy, 1) > 0); + + // Semaphore zurücksetzen, falls sie gesetzt war + k_sem_reset(&usb_rx_sem); +} + static void usb_status_cb(enum usb_dc_status_code cb_status, const uint8_t *param) { switch (cb_status) { diff --git a/firmware/src/usb.h b/firmware/src/usb.h index 84fb6ac..9ece4ee 100644 --- a/firmware/src/usb.h +++ b/firmware/src/usb.h @@ -47,4 +47,9 @@ void usb_write_char(uint8_t c); */ void usb_write_buffer(const uint8_t *buf, size_t len); +/** + * @brief Flushes the USB RX FIFO + */ +void usb_flush_rx(void); + #endif // USB_CDC_ACM_H \ No newline at end of file