Closed futurezeb closed 5 months ago
I have done some further research, the combination of cache + DMA is known to be tricky. See this forum post: Hint: DMA and cache coherency
When the DMA writes data to the RxBuffers, it ignores the dcache.
Any previously cached data is still valid, even after the pbuf
memory is freed and overwritten by the DMA.
So I am pretty confident that it is required to clear the dcache after freeing the pbuf
memory, otherwise the memory written to by HAL_ETH_ReadData
will contain invalid cache entries.
A subsequent read of that memory location will read garbage bytes from the cache.
ST Internal Reference: 158119
Hello @futurezeb,
Thank you for your report. We partially reproduced your scenario:
However, we were unable to reproduce the issue. Please allow me to close this issue. You can reopen it at any time if you have any details to share with us.
You can find an example with Dcache management here.
with regards,
Describe the set-up
I am transmitting random packets of length=255 byte to the mcu and back to the pc in a endless loop. The packet contains random data + a crc32 checksum of that data at the end. At random times, when calculating that packet checksum on the mcu, the checksums do not match. That means that the receiving of that packet failed.
Describe the bug When the
pbuf
, that is free'd in the functionpbuf_free_custom
, is not invalidated afterwards (usingSCB_InvalidateDCache_by_Addr
), 32 bytes of the old contents of thatpbuf
randomly appear when receiving a message in a later packet.How To Reproduce
Explicitly invalidate the contents of the freed
pbuf
in the function like this}
void pbuf_free_custom( struct pbuf* p ) { ... // start of the function
for( pbuf q = p; q != nullptr; q = q->next ) { SCB_InvalidateDCache_by_Addr( (uint32_t) q->payload, q->len ); }
LWIP_MEMPOOL_FREE( RX_POOL, custom_pbuf );
... // remaining function }