AnsweredAssumed Answered

Getting HAL error working on SDIO 1 bit interface on CubeMX

Question asked by Niyathi Shenoy on Feb 16, 2018
Latest reply on Feb 16, 2018 by Clive One

Hi I am working on SDIO 1 bit interface. I am using stm32cubemx version 4.24.0 and STM32Cube FW_F4 V1.19.0.

This is the code that i have written:

FATFS myFATAFS;
FIL myFILE;
UINT testByte;

 

 

if(f_mount(&myFATAFS, SDPath, 1)==FR_OK){
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);

char myPath[] = "WRITE1.TXT\0";
if( f_open(&myFILE, myPath, FA_WRITE | FA_CREATE_ALWAYS)==FR_OK){
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
}
char myData[] = "Hello";

if( f_write(&myFILE, myData, sizeof(myData), &testByte)==FR_OK)
{
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);
}
f_close(&myFILE);
HAL_Delay(500);
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_15);
}

Here my f_mount is FR_OK, f_open also is FR_OK and i checked the sd card it has a file WRITE1.TXT created. However, f_write doesn't write anything into the created file.I am getting an error in "HAL_StatusTypeDef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout)" where it says :

else if(__HAL_SD_GET_FLAG(hsd, SDIO_FLAG_TXUNDERR))
{
/* Clear all the static flags */
__HAL_SD_CLEAR_FLAG(hsd, SDIO_STATIC_FLAGS);
hsd->ErrorCode |= HAL_SD_ERROR_TX_UNDERRUN;
hsd->State = HAL_SD_STATE_READY;
return HAL_ERROR;
}

 

And in return it gives the following error:

uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout)
{
uint8_t sd_state = MSD_OK;

if (HAL_SD_WriteBlocks(&hsd, (uint8_t *)pData, WriteAddr, NumOfBlocks, Timeout) != HAL_OK)
{
sd_state = MSD_ERROR;
}

return sd_state;
}

I have attached the picture of my cubemx settings  

Outcomes