STM32H743 SDMMC write problem
Hi,
I have a very strange problem with the STM32H743 SDMMC... I'm using a custom board with a 8GB SDHC Class 10 SD Card. I'm using the CubeMX generated code for SDMMC1, but I checked and it should be the same code as the example project (STM32Cube_FW_H7_V1.7.0\Projects\STM32H743I-EVAL\Applications\FatFs\FatFs_uSD_DMA_Standalone).
Reading and writing with the IDMA works perfectly (once I figured out all the MPU cache challenges).
I'm using a loop to call the FS_FileOperations() function from the example project 100 times. This means, a small .txt file will be written 100 times to the SD card and after each write, the data is read back. Usually this works without an issue, however, I have some SD Cards (they look the same from the outside) that will cause the write operation to get stuck with a massive timeout.
The timeout occurs in this function (sd_diskio_dma.c:(
DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
{
DRESULT res = RES_ERROR;
WriteStatus = 0;
uint32_t timeout;
/*
* since the MPU is configured as write-through, see main.c file, there isn't any need
* to maintain the cache as its content is always coherent with the memory.
* If needed, check the file "Middlewares/Third_Party/FatFs/src/drivers/sd_diskio_dma_template.c"
* to see how the cache is maintained during the write operations.
*/
if(BSP_SD_WriteBlocks_DMA(0, (uint32_t*)buff,
(uint32_t)(sector),
count) == BSP_ERROR_NONE)
{
/* Wait that writing process is completed or a timeout occurs */
timeout = HAL_GetTick();
while((WriteStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT))
{
}
/* incase of a timeout return error */
if (WriteStatus == 0)
{
res = RES_ERROR;
}
else
{
WriteStatus = 0;
timeout = HAL_GetTick();
while((HAL_GetTick() - timeout) < SD_TIMEOUT)
{
if (BSP_SD_GetCardState(0) == SD_TRANSFER_OK)
{
res = RES_OK;
break;
}
}
}
}
return res;
}It seems to appear completly random (sometimes it even works all of the 100 times). After the timeout appeared, the SD card no longer accepts read or write data and when trying to reinitialize the SDMMC a RX_OVERRUN occurs. The only way to resolve this, is to completly reset the STM32H7.
Has anyone seen a behavior like this before or can point me in a direction to search for?
I already tried to modify most of the SDMMC parameters, my hardware looks good and for me, the strange thing is that it works perfectly with some SD cards and that this error seems to be completly random.
