cancel
Showing results for 
Search instead for 
Did you mean: 

SD Card Time out STM32F779II

Ahmed Tolba
Associate II

I'm using STM32F779II With a microsd card. That is clocked at 48MHz.

When writing to the sdcard as a block, I get HAL_TimeOut, using that function:

err = HAL_SD_WriteBlocks(&sd_handle, (uint8_t *)src, block_num, num_blocks, 6000);

After writing I wait like that :

static HAL_StatusTypeDef sdcard_wait_finished(SD_HandleTypeDef *sd,

uint32_t timeout) {

// Wait for HAL driver to be ready (eg for DMA to finish)

uint32_t start = HAL_GetTick();

while (sd->State == HAL_SD_STATE_BUSY) {

if (HAL_GetTick() - start >= timeout) {

return HAL_TIMEOUT;

}

}

// Wait for SD card to complete the operation

for (;;) {

HAL_SD_CardStateTypeDef state = HAL_SD_GetCardState(sd);

if (state == HAL_SD_CARD_TRANSFER) {

return HAL_OK;

}

if (!(state == HAL_SD_CARD_SENDING || state == HAL_SD_CARD_RECEIVING ||

state == HAL_SD_CARD_PROGRAMMING)) {

return HAL_ERROR;

}

if (HAL_GetTick() - start >= timeout) {

return HAL_TIMEOUT;

}

}

return HAL_OK;

}

And here is How I'm initializing it:

secbool sdcard_power_on(void) {

if (sectrue != sdcard_is_present()) {

return secfalse;

}

if (sd_handle.Instance) {

return sectrue;

}

HAL_SD_MspInit(&sd_handle);

// turn on SD card circuitry

sdcard_active_pin_state();

HAL_Delay(50);

// SD device interface configuration

sd_handle.Instance = SDMMC1;

sd_handle.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;

sd_handle.Init.ClockBypass = SDMMC_CLOCK_BYPASS_ENABLE;

sd_handle.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;

sd_handle.Init.BusWide = SDMMC_BUS_WIDE_1B;

sd_handle.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;

sd_handle.Init.ClockDiv = 0;

// init the SD interface, with retry if it's not ready yet

for (int retry = 10; HAL_SD_Init(&sd_handle) != HAL_OK; retry--) {

if (retry == 0) {

goto error;

}

HAL_Delay(50);

}

// configure the SD bus width for wide operation

if (HAL_SD_ConfigWideBusOperation(&sd_handle, SDMMC_BUS_WIDE_4B) != HAL_OK) {

HAL_SD_DeInit(&sd_handle);

goto error;

}

}

0 REPLIES 0