AnsweredAssumed Answered

Trouble with SDMMC driver and STM32F7

Question asked by Andrew Messier on Jun 1, 2018
Latest reply on Jun 4, 2018 by Clive Two.Zero

Hi everyone,

 

I'm using an STM32F777 part, with files generated by the very latest version of CubeMX (4.25.1)

I've spent the day struggling through issues writing a file to an SD card using the fatfs middleware.  I've pretty much followed the path of issues experienced by piet t in these two threads:

 

SD_Read bug? 

f_write bug - report 

 

So far, I've had to add pull-up resistors in the CubeMX configuration for the CMD and data lines (which I understand shouldn't be strictly necessary) and applied these two fixes:

 

1.  Initialized "ReadStatus" and "WriteStatus" to '1' in the respective SD_read and SD_write functions in sd_diskio.c

2.  Reset the state of the peripheral after the ReadBlocksDMA and WriteBlocksDMA with these lines:

__HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_FLAGS);

hsd->State = HAL_SD_STATE_READY;

both of which were discovered and reported in the threads linked above.

Now my code succeeds occasionally (30%-ish?), but when it fails it spins in the following loop in SDMMC_GetCmdResp1

 

do
{
   if (count-- == 0)
   {
      return SDMMC_ERROR_TIMEOUT;
   }

}while(!__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT));

Has anyone come across this or have a clue what might be wrong?

 

Thanks,

Drew

Outcomes