cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4x SDIO Issue with some SDCard

vbesson
Senior

Hello, 

I have a stm42f411 with SDIO 4B configured and working properly. 

the SDIO conf is the following:

 

hsd.Instance = SDIO;
  hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
  hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
  hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
  hsd.Init.BusWide = SDIO_BUS_WIDE_4B;
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd.Init.ClockDiv = 8;
  /* USER CODE BEGIN SDIO_Init 2 */
  hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
  if (HAL_SD_Init(&hsd) != HAL_OK){
    log_error("MX_SDIO_SD_Init: error HAL_SD_Init");
  }
  if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK){
    log_error("MX_SDIO_SD_Init: HAL_SD_ConfigWideBusOperation error");
  }

 

Over 10 SDCard, same brand, all working on linux, windows, only 4 are passing without error the Hal_SD_init and  ConfigWideBusOperation

in Hal_SD_Init 

 

static uint32_t SD_PowerON(SD_HandleTypeDef *hsd)
{
  __IO uint32_t count = 0U;
  uint32_t response = 0U, validvoltage = 0U;
  uint32_t errorstate;

  /* CMD0: GO_IDLE_STATE */
  errorstate = SDMMC_CmdGoIdleState(hsd->Instance);
  if(errorstate != HAL_SD_ERROR_NONE)
  {
    return errorstate;
  }

  /* CMD8: SEND_IF_COND: Command available only on V2.0 cards */
  errorstate = SDMMC_CmdOperCond(hsd->Instance);
  if(errorstate != HAL_SD_ERROR_NONE)
  {
    hsd->SdCard.CardVersion = CARD_V1_X;
    /* CMD0: GO_IDLE_STATE */
    errorstate = SDMMC_CmdGoIdleState(hsd->Instance);
    if(errorstate != HAL_SD_ERROR_NONE)
    {
      return errorstate;
    }

 

I received an errorState==4

It is coming from :

 

uint32_t SDMMC_CmdOperCond(SDIO_TypeDef *SDIOx)
{
  SDIO_CmdInitTypeDef  sdmmc_cmdinit;
  uint32_t errorstate;
  
  /* Send CMD8 to verify SD card interface operating condition */
  /* Argument: - [31:12]: Reserved (shall be set to '0')
  - [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
  - [7:0]: Check Pattern (recommended 0xAA) */
  /* CMD Response: R7 */
  sdmmc_cmdinit.Argument         = SDMMC_CHECK_PATTERN;
  sdmmc_cmdinit.CmdIndex         = SDMMC_CMD_HS_SEND_EXT_CSD;
  sdmmc_cmdinit.Response         = SDIO_RESPONSE_SHORT;
  sdmmc_cmdinit.WaitForInterrupt = SDIO_WAIT_NO;
  sdmmc_cmdinit.CPSM             = SDIO_CPSM_ENABLE;
  (void)SDIO_SendCommand(SDIOx, &sdmmc_cmdinit);
  
  /* Check for error conditions */
  errorstate = SDMMC_GetCmdResp7(SDIOx);

  return errorstate;
}

 

and inside 

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 ));
    
  if(__SDIO_GET_FLAG(SDIOx, SDIO_FLAG_CTIMEOUT))
  {
    /* 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;
  }

 

Do you have any clue of what is happening ? 

Thanks 

Vincent

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
vbesson
Senior

Hello All, 

I finally found the issue, and it was not related to the STM32 nor the SDCARD. 

Using a cheap ST-LINK32 I discover that It was damaged and not providing the right output voltage to the STM32. Thus the init of the sdcard was not done correctly,

Changing the ST-LINK has solved the issue, I hope it will help others 

Vincent 

 

View solution in original post

3 REPLIES 3

@vbesson wrote:

I received an errorState==4


So have you looked-up what that means?

vbesson
Senior

it seems to be 

SDMMC_ERROR_CMD_RSP_TIMEOUT
and ?
vbesson
Senior

Hello All, 

I finally found the issue, and it was not related to the STM32 nor the SDCARD. 

Using a cheap ST-LINK32 I discover that It was damaged and not providing the right output voltage to the STM32. Thus the init of the sdcard was not done correctly,

Changing the ST-LINK has solved the issue, I hope it will help others 

Vincent