cancel
Showing results for 
Search instead for 
Did you mean: 

Stuck while reading/wirting from/to SD card

JBond.1
Senior

Hi, I have STM32F407 and trying to read/wirte from/to SD card and often the code get stuck in the this loop:

 

static uint32_t SD_FindSCR(SD_HandleTypeDef *hsd, uint32_t *pSCR)
{
  //...

  while(!__HAL_SD_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT))
  {
    if(__HAL_SD_GET_FLAG(hsd, SDIO_FLAG_RXDAVL))
    {
      *(tempscr + index) = SDIO_ReadFIFO(hsd->Instance);
      index++;
    }
    else if(!__HAL_SD_GET_FLAG(hsd, SDIO_FLAG_RXACT))
    {
      break;
    }

    if((HAL_GetTick() - tickstart) >=  SDMMC_DATATIMEOUT)
    {
      return HAL_SD_ERROR_TIMEOUT;
    }
  }

  //...
}

 

 for some reason SDMMC_DATATIMEOUT is huge number

 

#ifndef SDMMC_DATATIMEOUT
#define SDMMC_DATATIMEOUT                             0xFFFFFFFFU
#endif /* SDMMC_DATATIMEOUT */

 

Where could I redefine it so I would not need to edit generated code?

Also why do I get stuck in this loop in the first place? (files are not huge to read/write so this should not be an issue?)

Could it be the issue after I upgraded CubeMX 6.6.1 to 6.9.2?

1 REPLY 1
JBond.1
Senior

It seems I had this error, because of bad power supply. Attached too many things to power supply and this started happening. It seems to be fixed!