cancel
Showing results for 
Search instead for 
Did you mean: 

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

leogarberoglio
Associate III
Posted on April 19, 2015 at 23:36

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);
1 REPLY 1
leogarberoglio
Associate III
Posted on April 20, 2015 at 01:57

I trace the error to f_open function -> finde_volume -> get_ldnumber. Becouse this is 0 it call disk_initialize. Here is a calling to SD_initialize and here BSP_SD_Init then HAL_SD_Init. It returns 0 (SD_OK), so BSP_SD_Init return 0 (MSD_OK) and disk_initialize return 0 (ok?)

back to finde_volume I have

    fmt = check_fs(fs, bsect);                    /* Load sector 0 and check if it is an FAT boot sector as SFD */

wich returns 2 wich mean error /* No FAT volume is found */

but, I take the usd card, put into adapter and inserted on the PC and I just check that this is a FAT filesystem.... so, it is not hardware related issue, right? I mean, my custom shield and uSD connections are right?

BR