cancel
Showing results for 
Search instead for 
Did you mean: 

_SDIO_GET_FLAG Error

MBolo.1
Associate III

So I'm using a SDIO connection to write some files to the SD card (MCU STM32F446Vet6).

Using the PC8-PC12 lines. Using the FATFS and SDIO from CubeMX. In main.c file have this sniped of code

/* USER CODE BEGIN 2 */
  if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK)
      {
          Error_Handler();
      }
      else
      {
 
          res=f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext));
         if(res != FR_OK)
          {
             Error_Handler();
          }
          else
          {
              //Open file for writing (Create)
              if(f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
              {
                  Error_Handler();
              }
              else
              {
 
 
 
                  //Write to the text file
                  res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
                  if((byteswritten == 0) || (res != FR_OK))
                  {
                      Error_Handler();
                  }
                  else
                  {
 
 
 
                      f_close(&SDFile);
                  }
              }
          }
      }
      f_mount(&SDFatFS, (TCHAR const*)NULL, 0);
  /* 

at line 9 (res=f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext));) getting the Error FR_NOT_READY. After following the step by step debugging ended to the file

stm32f4xx_II_sdmmc.c where I'm getting in this code

uint32_t SDMMC_GetCmdResp7(SDIO_TypeDef *SDIOx)
{
  uint32_t sta_reg;
  /* 8 is the number of required instructions cycles for the below loop statement.
  The SDIO_CMDTIMEOUT is expressed in ms */
  uint32_t count = SDIO_CMDTIMEOUT * (SystemCoreClock / 8U /1000U);
  
  do
  {
    if (count-- == 0U)
    {
      return SDMMC_ERROR_TIMEOUT;
    }
    sta_reg = SDIOx->STA;
  }while(((sta_reg & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)) == 0U) ||
         ((sta_reg & SDIO_FLAG_CMDACT) != 0U ));
 
  int c= __SDIO_GET_FLAG(SDIOx, SDIO_FLAG_CTIMEOUT);
  if(c)
  {
    /* Card is SD V2.0 compliant */
    __SDIO_CLEAR_FLAG(SDIOx, SDIO_FLAG_CTIMEOUT);
    
    return SDMMC_ERROR_CMD_RSP_TIMEOUT;
  }
  else if(__SDIO_GET_FLAG(SDIOx, SDIO_FLAG_CCRCFAIL))
  {
    /* Card is SD V2.0 compliant */
    __SDIO_CLEAR_FLAG(SDIOx, SDIO_FLAG_CCRCFAIL);
    
    return SDMMC_ERROR_CMD_CRC_FAIL;
  }
  else
  {
    /* Nothing to do */
  }
  
  if(__SDIO_GET_FLAG(SDIOx, SDIO_FLAG_CMDREND))
  {
    /* Card is SD V2.0 compliant */
    __SDIO_CLEAR_FLAG(SDIOx, SDIO_FLAG_CMDREND);
  }
  
  return SDMMC_ERROR_NONE;
  
} 

at line 24 Error SDMMC_ERROR_CMD_RSP_TIMEOUT;.

From the code it looks like __SDIO_GET_FLAG(SDIOx, SDIO_FLAG_CTIMEOUT) comes TRUE which triggers the __SDIO_CLEAR_FLAG(SDIOx, SDIO_FLAG_CTIMEOUT). It looks to avoid any Errors I should NOT get TRUE at any of statements starting to line 19.

Questions what triggers that Error and how to fix it , and also more information on those _SDIO_FLAG_XXXX functions would be very appreciated.

0 REPLIES 0