From 2b6e5227e2e8f3f0856800d1cfdbc281a510c7ee Mon Sep 17 00:00:00 2001 From: Daniel Pazzini Date: Tue, 22 Aug 2023 14:33:48 -0300 Subject: [PATCH] Bug fix - Uart stucked after canceling a receive operation --- Src/main.c | 4 ++++ Src/xmodem.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/Src/main.c b/Src/main.c index 4053214..62e25a3 100644 --- a/Src/main.c +++ b/Src/main.c @@ -236,6 +236,10 @@ static void MX_GPIO_Init(void) /* USER CODE BEGIN 4 */ +void uart_clear_overrun_flag (void){ + huart1.Instance->ICR |= (1 << 3); +} + /* USER CODE END 4 */ /** diff --git a/Src/xmodem.c b/Src/xmodem.c index 7b7568c..d33f678 100644 --- a/Src/xmodem.c +++ b/Src/xmodem.c @@ -19,6 +19,9 @@ static uint16_t xmodem_calc_crc(uint8_t *data, uint16_t length); static xmodem_status xmodem_handle_packet(uint8_t size); static xmodem_status xmodem_error_handler(uint8_t *error_number, uint8_t max_error_number); +/* externs */ +extern void uart_clear_overrun_flag (void); + /** * @brief This function is the base of the Xmodem protocol. * When we receive a header from UART, it decides what action it shall take. @@ -102,6 +105,9 @@ void xmodem_receive(void) } break; } + + /*Prevent an overrun error after stop/cancel in the middle of a pack transference*/ + uart_clear_overrun_flag(); } }