FatFs + SDMMC + DATAEND interrupt
I've been struggling to get FatFs working on STM32L496 / L471 for some time now. At present my code uses polling which even at low card clock with certain interrupts disabled is not reliable enough, giving me random FR_DISK_ERR. I know I have to get DMA working, and have spent the last two weeks focussed on just that. (Some of that was wasted not realizing CubeMX had not merely initialized but also started the watchdog, giving strange debug behaviour.)
I am not using an OS.
To simplify things I've been looking at single block DMA writes. The FatFs code SD_write() calls HAL_SD_WriteBlocks_DMA() via BSP_SD_WriteBlocks_DMA() then waits for WriteStatus to be set via callbacks. The first callback is SD_DMATransmitCplt. Stock code merely enables the SDMMC DATAEND interrupt, since - unlike the read block case - data does not reach the card until the DPSM has fully flushed the TX FIFO.
The second callback ought to triggered by DATAEND but I never get the DATAEND interrupt. I get TXUNDERR instead. If I follow the RM's advice and disable DMA requests via SDMMC_DCTRL_DMAEN in the transfer complete callback, I still get TXUNDERR. And when I run the code to completion then pause, DCOUNT still contains 388 bytes the same as when the DMA callback occurred.
If I disable TXUNDERR interrupts at transfer complete (should be safe), I never get DATAEND.
MASK & DATAENDIE is enabled in every case. RM tells me DATAEND occurs when DCOUNT counts down to zero. I can demonstrate DMA single block write-read round-trip even with stock code but since WriteStatus is never set, FatFs times out.
Right now - if I can prove single and multi-block transfers actually work given enough time - I am going to attempt a workaround by setting a "DMA Transfer Complete" flag in the callback then polling TXFIFOE. This would be in a modified version of SD_write(). But I'd really like to get DATAEND working so I'm making fewer modifications to stock code.
Thanks for reading this far and any suggestions.
