Skip to content

Commit caff3d1

Browse files
kjbraceyadbridge
authored andcommitted
Add memory barriers to STM32F7xx Ethernet
Pending official update from STM, add memory barriers to the Ethernet HAL code for the STM32F7xx family. Cortex-M7 has a merging write buffer that is not automatically flushed by accesses to devices, so without these DMBs, we sometimes lose synch with the transmitter. The DMBs are architecturally needed in every version of this HAL, but adding just to the STM32F7 version for now to clear test, as the problem has only been observed on Cortex-M7-based devices. Fixes #5622.
1 parent 2b4ff78 commit caff3d1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_eth.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameL
717717
heth->TxDesc->Status |=ETH_DMATXDESC_FS|ETH_DMATXDESC_LS;
718718
/* Set frame size */
719719
heth->TxDesc->ControlBufferSize = (FrameLength & ETH_DMATXDESC_TBS1);
720+
/* Ensure rest of descriptor is written to RAM before the OWN bit */
721+
__DMB();
720722
/* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
721723
heth->TxDesc->Status |= ETH_DMATXDESC_OWN;
722724
/* Point to next descriptor */
@@ -746,13 +748,18 @@ HAL_StatusTypeDef HAL_ETH_TransmitFrame(ETH_HandleTypeDef *heth, uint32_t FrameL
746748
heth->TxDesc->ControlBufferSize = (size & ETH_DMATXDESC_TBS1);
747749
}
748750

751+
/* Ensure rest of descriptor is written to RAM before the OWN bit */
752+
__DMB();
749753
/* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
750754
heth->TxDesc->Status |= ETH_DMATXDESC_OWN;
751755
/* point to next descriptor */
752756
heth->TxDesc = (ETH_DMADescTypeDef *)(heth->TxDesc->Buffer2NextDescAddr);
753757
}
754758
}
755759

760+
/* Ensure all descriptors are written to RAM before checking transmitter status */
761+
__DMB();
762+
756763
/* When Tx Buffer unavailable flag is set: clear it and resume transmission */
757764
if (((heth->Instance)->DMASR & ETH_DMASR_TBUS) != (uint32_t)RESET)
758765
{

0 commit comments

Comments
 (0)