Skip to content

fix(sdio): bounce SDRAM-targeted reads through internal SRAM on H750#7318

Open
raphaelcoeffic wants to merge 1 commit intomainfrom
fix-sdio-sdram-dma-overrun
Open

fix(sdio): bounce SDRAM-targeted reads through internal SRAM on H750#7318
raphaelcoeffic wants to merge 1 commit intomainfrom
fix-sdio-sdram-dma-overrun

Conversation

@raphaelcoeffic
Copy link
Copy Markdown
Member

On STM32H750, DMA from SDMMC into SDRAM can cause FIFO overruns when the SDRAM controller can't keep up with the SDMMC receive rate. The disk cache fills go into internal SRAM so they're safe, but three paths bypass the cache and hand the caller's buffer (often an SDRAM heap allocation) directly to the DMA:

  • reads larger than DISK_CACHE_BLOCK_SECTORS (disk_cache.cpp:149)
  • reads near the end of the disk (disk_cache.cpp:156)
  • FatFs f_read multi-sector reads that exceed the block size

Drop the SDRAM heap clause from _IS_DMA_BUFFER on STM32H7 so SDRAM buffers take the bounce path, and grow the bounce buffer to 8 KB (DISK_CACHE_BLOCK_SECTORS) on H7 to keep throughput reasonable for large reads. H7RS keeps the original behaviour — its SDRAM is fast enough not to trigger this.

On STM32H750, DMA from SDMMC into SDRAM can cause FIFO overruns when
the SDRAM controller can't keep up with the SDMMC receive rate. The
disk cache fills go into internal SRAM so they're safe, but three paths
bypass the cache and hand the caller's buffer (often an SDRAM heap
allocation) directly to the DMA:

 - reads larger than DISK_CACHE_BLOCK_SECTORS (disk_cache.cpp:149)
 - reads near the end of the disk (disk_cache.cpp:156)
 - FatFs f_read multi-sector reads that exceed the block size

Drop the SDRAM heap clause from _IS_DMA_BUFFER on STM32H7 so SDRAM
buffers take the bounce path, and grow the bounce buffer to 8 KB
(DISK_CACHE_BLOCK_SECTORS) on H7 to keep throughput reasonable for
large reads. H7RS keeps the original behaviour — its SDRAM is fast
enough not to trigger this.
@raphaelcoeffic
Copy link
Copy Markdown
Member Author

@sneone can you please test with this if that improves anything?

@raphaelcoeffic raphaelcoeffic added the backport/2.12 To be backported to a 2.12 release also. label Apr 24, 2026
@sneone
Copy link
Copy Markdown
Contributor

sneone commented Apr 24, 2026

@sneone can you please test with this if that improves anything?

Ok, I tested it and it works fine. I even changed the SD card clock to 50M and it still reads and writes to the SD card correctly (I only did a few dozen simple tests). I think it would be better to change the variable scratch to 32-byte alignment.

@pfeerick pfeerick added this to the 2.12.1 milestone Apr 28, 2026
@pfeerick pfeerick added the bug 🪲 Something isn't working label Apr 28, 2026
@richardclli richardclli modified the milestones: 2.12.1, 2.11.7 Apr 29, 2026
@richardclli
Copy link
Copy Markdown
Member

This should be able to merge in 2.11 branch, right?

@pfeerick
Copy link
Copy Markdown
Member

pfeerick commented Apr 29, 2026

I'll try to cherry-pick it in, will see how that goes.

@raphaelcoeffic Don't forget to consider this from above

I think it would be better to change the variable scratch to 32-byte alignment.

@pfeerick pfeerick added the backport/2.11 To be backported to a 2.11 release also. label Apr 29, 2026
@richardclli
Copy link
Copy Markdown
Member

I tried to cherry pick to 2.11, no conflicts

@richardclli
Copy link
Copy Markdown
Member

richardclli commented Apr 30, 2026

Already did long time ago by #6517 , but wait this one is not cherry picked to 2.11 branch. @pfeerick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/2.11 To be backported to a 2.11 release also. backport/2.12 To be backported to a 2.12 release also. bug 🪲 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants