cancel
Showing results for 
Search instead for 
Did you mean: 

Something wrong with SDIO

Xin Yang
Associate II
Posted on November 14, 2017 at 09:39

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?

5 REPLIES 5
Posted on November 14, 2017 at 16:40

You're supposed to start the card at 400 KHz, not 24 MHz

Personally not a fan of HAL or Polling mode, seem to be a lot of bug reports in current CubeMX release for F4. I'd recommend validating the hardware with the SPL examples.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 14, 2017 at 18:09

I saw that hal libraries start the card with SDIO_INIT_CLK_DIV.

so you recommend me use DMA mode or other SDIO driver?

Posted on November 15, 2017 at 03:02

I use 4-bit SDIO with DMA, and can typically get 5-8 MBps for writes, and 10-11 MBps for reads, depending on the cards being used. Polling tends to eat bandwidth other tasks could use.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 15, 2017 at 08:23

does the DMA code in cubeMX worked fine,or i need to find some?

Posted on November 16, 2017 at 03:21

Seems i roll back to 3.7R2 and then problem solved.thanks a lot