diff --git a/network/serial_network/HAL/STM32F0/serial_network_hal.c b/network/serial_network/HAL/STM32F0/serial_network_hal.c index 34f66a071..705d6a573 100644 --- a/network/serial_network/HAL/STM32F0/serial_network_hal.c +++ b/network/serial_network/HAL/STM32F0/serial_network_hal.c @@ -139,6 +139,9 @@ void SerialHAL_Loop(void) { if (SERIAL_RX_DMA_TC(SERIAL_RX_DMA) != RESET) // DMA buffer overflow { + // Recompute the RX_PointerPosition to be sure to get the DMA buffer after the overflow. + // If the RX_PointerPosition was taken just before the overflow we may compute this with a wrong value. + RX_PointerPosition = rx_buffer_size - LL_DMA_GetDataLength(SERIAL_RX_DMA, SERIAL_RX_DMA_CHANNEL); SERIAL_RX_DMA_CLEAR_TC(SERIAL_RX_DMA); size = (rx_buffer_size - RX_PrevPointerPosition) + RX_PointerPosition; } diff --git a/network/serial_network/HAL/STM32F4/serial_network_hal.c b/network/serial_network/HAL/STM32F4/serial_network_hal.c index 4b21d53af..cb38b3706 100644 --- a/network/serial_network/HAL/STM32F4/serial_network_hal.c +++ b/network/serial_network/HAL/STM32F4/serial_network_hal.c @@ -142,6 +142,9 @@ void SerialHAL_Loop(void) { if (SERIAL_RX_DMA_TC(SERIAL_RX_DMA) != RESET) // DMA buffer overflow { + // Recompute the RX_PointerPosition to be sure to get the DMA buffer after the overflow. + // If the RX_PointerPosition was taken just before the overflow we may compute this with a wrong value. + RX_PointerPosition = rx_buffer_size - LL_DMA_GetDataLength(SERIAL_RX_DMA, SERIAL_RX_DMA_CHANNEL); SERIAL_RX_DMA_CLEAR_TC(SERIAL_RX_DMA); size = (rx_buffer_size - RX_PrevPointerPosition) + RX_PointerPosition; } diff --git a/network/serial_network/HAL/STM32G431/serial_network_hal.c b/network/serial_network/HAL/STM32G431/serial_network_hal.c index 05b93944a..035565c34 100644 --- a/network/serial_network/HAL/STM32G431/serial_network_hal.c +++ b/network/serial_network/HAL/STM32G431/serial_network_hal.c @@ -142,6 +142,9 @@ void SerialHAL_Loop(void) { if (SERIAL_RX_DMA_TC(SERIAL_RX_DMA) != RESET) // DMA buffer overflow { + // Recompute the RX_PointerPosition to be sure to get the DMA buffer after the overflow. + // If the RX_PointerPosition was taken just before the overflow we may compute this with a wrong value. + RX_PointerPosition = rx_buffer_size - LL_DMA_GetDataLength(SERIAL_RX_DMA, SERIAL_RX_DMA_CHANNEL); SERIAL_RX_DMA_CLEAR_TC(SERIAL_RX_DMA); size = (rx_buffer_size - RX_PrevPointerPosition) + RX_PointerPosition; } diff --git a/network/serial_network/HAL/STM32G474/serial_network_hal.c b/network/serial_network/HAL/STM32G474/serial_network_hal.c index 726eceb51..589048861 100644 --- a/network/serial_network/HAL/STM32G474/serial_network_hal.c +++ b/network/serial_network/HAL/STM32G474/serial_network_hal.c @@ -142,6 +142,9 @@ void SerialHAL_Loop(void) { if (SERIAL_RX_DMA_TC(SERIAL_RX_DMA) != RESET) // DMA buffer overflow { + // Recompute the RX_PointerPosition to be sure to get the DMA buffer after the overflow. + // If the RX_PointerPosition was taken just before the overflow we may compute this with a wrong value. + RX_PointerPosition = rx_buffer_size - LL_DMA_GetDataLength(SERIAL_RX_DMA, SERIAL_RX_DMA_CHANNEL); SERIAL_RX_DMA_CLEAR_TC(SERIAL_RX_DMA); size = (rx_buffer_size - RX_PrevPointerPosition) + RX_PointerPosition; } diff --git a/network/serial_network/HAL/STM32L4/serial_network_hal.c b/network/serial_network/HAL/STM32L4/serial_network_hal.c index 71ae31a07..60ac5ac66 100644 --- a/network/serial_network/HAL/STM32L4/serial_network_hal.c +++ b/network/serial_network/HAL/STM32L4/serial_network_hal.c @@ -141,6 +141,9 @@ void SerialHAL_Loop(void) { if (SERIAL_RX_DMA_TC(SERIAL_RX_DMA) != RESET) // DMA buffer overflow { + // Recompute the RX_PointerPosition to be sure to get the DMA buffer after the overflow. + // If the RX_PointerPosition was taken just before the overflow we may compute this with a wrong value. + RX_PointerPosition = rx_buffer_size - LL_DMA_GetDataLength(SERIAL_RX_DMA, SERIAL_RX_DMA_CHANNEL); SERIAL_RX_DMA_CLEAR_TC(SERIAL_RX_DMA); size = (rx_buffer_size - RX_PrevPointerPosition) + RX_PointerPosition; }