Skip to content

Commit 2d6c8d6

Browse files
committed
drivers: ethernet: eth_stm32_hal: Assure cache coherency
Use sys_cache_data_flush_range function in eth_tx function to assure cache coherency before DMA read operation. Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <[email protected]>
1 parent 77ef9bc commit 2d6c8d6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/ethernet/eth_stm32_hal.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
3333
#include <zephyr/irq.h>
3434
#include <zephyr/net/lldp.h>
3535
#include <zephyr/drivers/hwinfo.h>
36+
#include <zephyr/cache.h>
3637

3738
#if defined(CONFIG_NET_DSA)
3839
#include <zephyr/net/dsa.h>
@@ -428,6 +429,14 @@ static int eth_tx(const struct device *dev, struct net_pkt *pkt)
428429
/* Reset TX complete interrupt semaphore before TX request*/
429430
k_sem_reset(&dev_data->tx_int_sem);
430431

432+
/**
433+
* Assure cache coherency before DMA read operation.
434+
* Clean the data cache for the memory region specified by tx_config.TxBuffer->buffer
435+
* and tx_config.TxBuffer->len to ensure that any modified data in the cache is written
436+
* back to the main memory before the DMA controller reads it.
437+
*/
438+
sys_cache_data_flush_range((void *)(tx_config.TxBuffer->buffer), tx_config.TxBuffer->len);
439+
431440
/* tx_buffer is allocated on function stack, we need */
432441
/* to wait for the transfer to complete */
433442
/* So it is not freed before the interrupt happens */

0 commit comments

Comments
 (0)