cancel
Showing results for 
Search instead for 
Did you mean: 

Getting HAL error working on SDIO 1 bit interface on CubeMX

Niyathi Shenoy
Associate II
Posted on February 16, 2018 at 09:32

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  

3 REPLIES 3
Posted on February 16, 2018 at 10:12

Not seeing an attachment, but not digging into CubeMX settings.

I would recommend you verify the integrity of your circuit and software by testing READING first. It tends to be less destructive to the card and file system.

If you currently under-run, try lower speed clocking of the interface.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Niyathi Shenoy
Associate II
Posted on February 16, 2018 at 10:47

Hi,

This issue is solved by simply declaring these variables:

FATFS myFATAFS;

FIL myFILE;

UINT testByte;

globally rather than locally.

Posted on February 16, 2018 at 14:58

When using a local/auto variable it is often important to initialize properly,

FATFS myFATAFS = {0};

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..