AnsweredAssumed Answered

CubeMx 4.15.1 + STM32L476RC + 1.5.1 + FatFS SD

Question asked by luo.xinheng on Jul 13, 2016
Latest reply on Jul 15, 2016 by FTITI.Walid
hello sir.
my project write SD card error, but it read SD card properly.
when I debug into code, I found __HAL_SD_SDMMC_GET_FLAG() in HAL_SD_WriteBlocks() function always get error flag SDMMC_FLAG_DCRCFAIL. and it write nothing to SD card.
I checked my hardware, but it is OK. 
what wrong with my program?



  if(NumberOfBlocks > 1)
  {
    ......
  }
  else
  {
    /* Check for error conditions */
    errorstate = SD_CmdResp1Error(hsd, SD_CMD_READ_SINGLE_BLOCK); 
    
    if (errorstate != SD_OK)
    {
      return errorstate;
    }    
    
    /* In case of single block transfer, no need of stop transfer at all */
    while(!__HAL_SD_SDMMC_GET_FLAG(hsd, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DBCKEND))
    {
      if (__HAL_SD_SDMMC_GET_FLAG(hsd, SDMMC_FLAG_RXFIFOHF))
      {
        /* Read data from SDMMC Rx FIFO */
        for (count = 0; count < 8; count++)
        {
          *(tempbuff + count) = SDMMC_ReadFIFO(hsd->Instance);
        }
        
        tempbuff += 8;
      }
    }   
  }

Outcomes