AnsweredAssumed Answered

HAL, cube MX, 411RE, SDIO microSD, FatFS Problem

Question asked by elgarbe on Apr 19, 2015
Latest reply on Apr 20, 2015 by elgarbe
I have a uSD card on a custom shield conected by SDIO (PC12, PC8, PD2 lines)

I debug software and hardware (with my oscilloscope). I focus on this function

static HAL_SD_ErrorTypedef SD_Initialize_Cards(SD_HandleTypeDef *hsd)
{
  SDIO_CmdInitTypeDef sdio_cmdinitstructure;
  HAL_SD_ErrorTypedef errorstate = SD_OK;
  uint16_t sd_rca = 1;
   
  if(SDIO_GetPowerState(hsd->Instance) == 0) /* Power off */
  {
    errorstate = SD_REQUEST_NOT_APPLICABLE;
     
    return errorstate;
  }
   
  if(hsd->CardType != SECURE_DIGITAL_IO_CARD)
  {
    /* Send CMD2 ALL_SEND_CID */
    sdio_cmdinitstructure.Argument         = 0;
    sdio_cmdinitstructure.CmdIndex         = SD_CMD_ALL_SEND_CID;
    sdio_cmdinitstructure.Response         = SDIO_RESPONSE_LONG;
    sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
    sdio_cmdinitstructure.CPSM             = SDIO_CPSM_ENABLE;
    SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
     
    /* Check for error conditions */
    errorstate = SD_CmdResp2Error(hsd);
     
    if(errorstate != SD_OK)
    {
      return errorstate;
    }

I have TIMEOUT error from CMD2 and I don't have any signal change on D0 during SDIO_SendCommand. I have clk, and command signal

I put this code on gpio_init, just to test PC8 pin:
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET);

and pin is ok.

any idea?

BTW I think that there is a bug on Cube MX SDIO initialization. It generate this code:

void MX_SDIO_SD_Init(void)
{
 
  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_1B;
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd.Init.ClockDiv = 0;
 
}

I think that there is a missing   HAL_SD_Init(&hsd, &SDCardInfo);

Outcomes