Skip to content

Commit

Permalink
[SERIAL] Fix STM HAL DMA received size computation datarace in case o…
Browse files Browse the repository at this point in the history
…f DATA RX during computation.
  • Loading branch information
nicolas-rabault committed Sep 18, 2023
1 parent 25f9ee3 commit a74df88
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions network/serial_network/HAL/STM32F0/serial_network_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions network/serial_network/HAL/STM32F4/serial_network_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions network/serial_network/HAL/STM32G431/serial_network_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions network/serial_network/HAL/STM32G474/serial_network_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions network/serial_network/HAL/STM32L4/serial_network_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a74df88

Please sign in to comment.