cancel
Showing results for 
Search instead for 
Did you mean: 

very slowly initialisation of SD

EEuge
Senior

Code generated by CubeMX

static void MX_SDMMC1_SD_Init(void)
{
 
  /* USER CODE BEGIN SDMMC1_Init 0 */
 
  /* USER CODE END SDMMC1_Init 0 */
 
  /* USER CODE BEGIN SDMMC1_Init 1 */
 
  /* USER CODE END SDMMC1_Init 1 */
  hsd1.Instance = SDMMC1;
  hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
  hsd1.Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE;
  hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
  hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B;
  hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd1.Init.ClockDiv = 0;
	HAL_SD_Init(&hsd1);
  /* USER CODE BEGIN SDMMC1_Init 2 */
BSP_SD_Init();	
	HAL_Delay(200);
  /* USER CODE END SDMMC1_Init 2 */
 
}

There is a function in - SDMMC_GetCmdResp1(SD MMC x, SD MMC_CMD_UP_CMD, SD MMC_CMD TIMEOUT);

When the Sdmmc->STA register is checked in the body of this function, the check takes a very long time, since the CMDACT bit is in one. After 20-30 seconds, the bit is reset and the card works perfectly. Tellingly, the initialization time may be shorter, sometimes everything passes at once.

4-bit mode, 48 MHz frequency.

How to fix?

1 REPLY 1
EEuge
Senior

P.s. I tested with a debugger that where fail the program. Inside of the SD_PowerON function exist a while loop. When the cards don't recognize this while loop run infinitelly and never go out from there.

/* Send ACMD41 SD_APP_OP_COND with Argument 0x80100000 */
 
while(validvoltage == 0)
 
{
 
  if(count++ == SDMMC_MAX_VOLT_TRIAL)
 
  {
 
    return HAL_SD_ERROR_INVALID_VOLTRANGE;
 
  }
 
 
 
  /* SEND CMD55 APP_CMD with RCA as 0 */
 
  errorstate = SDMMC_CmdAppCommand(hsd->Instance, 0);
 
  if(errorstate != HAL_SD_ERROR_NONE)
 
  {
 
    return HAL_SD_ERROR_UNSUPPORTED_FEATURE;
 
  }
 
 
 
  /* Send CMD41 */
 
  errorstate = SDMMC_CmdAppOperCommand(hsd->Instance, SDMMC_STD_CAPACITY);
 
  if(errorstate != HAL_SD_ERROR_NONE)
 
  {
 
    return HAL_SD_ERROR_UNSUPPORTED_FEATURE;
 
  }
 
 
 
  /* Get command response */
 
  response = SDMMC_GetResponse(hsd->Instance, SDMMC_RESP1);
 
 
 
  /* Get operating voltage*/
 
  validvoltage = (((response >> 31) == 1) ? 1 : 0);
 
}