AnsweredAssumed Answered

Something wrong with SDIO

Question asked by Xin Yang on Nov 14, 2017
Latest reply on Nov 16, 2017 by Xin Yang

there is something wrong with my stm32f427VI while i'm trying to operate sdio.

 

i am init the sdio interface in pooling mode.

after this ,while i call HAL_SD_WriteBlocks.it's return HAL_ERROR.

and Error code is 16 Transmit FIFO underrun.

but the HAL_SD_ReadBlocks works fine.

can any one help me with this problem,please 

this nagged me for many days.

here is my init part:

 

uint8_t BSP_SD_Init(void)
{
uint8_t SD_state = MSD_OK;

uSdHandle.Instance = SDIO;
uSdHandle.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
uSdHandle.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
uSdHandle.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
uSdHandle.Init.BusWide = SDIO_BUS_WIDE_1B;
uSdHandle.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
uSdHandle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
if (HAL_SD_Init(&uSdHandle) != HAL_OK)
SD_state = MSD_ERROR;
if (SD_state == MSD_OK)
{
if (HAL_SD_ConfigWideBusOperation(&uSdHandle, SDIO_BUS_WIDE_4B) == HAL_OK)
SD_state = MSD_OK;
else
SD_state = MSD_ERROR;
}
return SD_state;
}

void HAL_SD_MspInit(SD_HandleTypeDef *hsd)
{
if (hsd->Instance == SDIO)
{

GPIO_InitTypeDef GPIO_Init_Structure;

/* Enable SDIO clock */
__HAL_RCC_SDIO_CLK_ENABLE();
/* Enable GPIOs clock */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();

/* Common GPIO configuration */
GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP;
GPIO_Init_Structure.Pull = GPIO_PULLUP;
GPIO_Init_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Init_Structure.Alternate = GPIO_AF12_SDIO;

/* GPIOC configuration */
GPIO_Init_Structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;

HAL_GPIO_Init(GPIOC, &GPIO_Init_Structure);

/* GPIOD configuration */
GPIO_Init_Structure.Pin = GPIO_PIN_2;
HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure);

}

HAL_StatusTypeDef sd = HAL_SD_WriteBlocks(&uSdHandle, buffer, 1, 1, 100000);//HAL_ERROR
HAL_SD_CardStateTypeDef sta = HAL_SD_GetCardState(&uSdHandle);//HAL_SD_CARD_TRANSFER
uint32_t ero = HAL_SD_GetError(&uSdHandle);//ero=16/Transmit FIFO underrun  

is there anything i missed?or wrong?

Outcomes