cancel
Showing results for 
Search instead for 
Did you mean: 

FREE RTOS / SDCARD / SDIO / FATFS f_open Problem

Ljunh.1
Associate II

0693W0000059Pu7QAE.png0693W0000059PtnQAE.png0693W0000059PtTQAU.png0693W0000059PsuQAE.pngI am using STM32F767NIH6 board.

I would like to apply SD card this time.

It works well in non os, but in free rtos, the sd card fails.

if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == 0)

{

if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0)!=FR_OK)

printf("mount err\r\n");

else

{

printf("mount ok\r\n");

if(f_open(&SDFile, "test.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)

{

printf("Failed to open Write file\r\n");

}

else

{

printf("Opened Write file successfully\r\n");

//Write data to text file

res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);

if((byteswritten == 0) || (res != FR_OK))

{

printf("Failed to write file!\r\n");

}

else

{

printf("File written successfully\r\n");

printf("Write Content: %s\r\n", wtext);

}

f_close(&SDFile);

}

f_open(&SDFile, "test.txt", FA_READ);

memset(rtext,0,sizeof(rtext));

res = f_read(&SDFile, rtext, sizeof(rtext), (UINT*)&bytesread);

if((bytesread == 0) || (res != FR_OK))

{

printf("Failed to read file!\r\n");

}

else

{

printf("File read successfully\r\n");

printf("File content: %s\r\n", (char *)rtext);

}

f_close(&SDFile);

}

}

When applied in freertos, an error occurs with a return value of 3 in f_open.

FR_NOT_READY, /* (3) The physical drive cannot work */

I don't know what to do when a problem like this happens.

Please understand even if the translation is a little strange.

11 REPLIES 11

Unrelated to shown code.

Would be related to a card/sdmmc interaction, likely timing related. Make sure you're not yielding focus at a critical point.

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

How do I get the timing right?

Slh
Senior

I have the same problem. I debugged and noticed that in the f_open() function, the program stays in this line and does not continue:

0693W0000059jMFQAY.png 

I use STM32F779. I attached the .ioc file.

Not just me then, my thread is https://community.st.com/s/question/0D53W00000Ip7vMSAR/fatfs-on-sd-card-with-freertos-does-it-insist-on-using-dma

ST really need to provide some documentation on how to get SD+FATFS+FreeRTOS working.

Haven't you solved it yet?

So this is the manufacturer's problem?

I don't see ST taking ownership of this any time soon. Their cop out is that "CubeMX and HAL libraries are for demonstration only". This may be fairly standard across the industry, but the number of bugs is distressingly high. If we accept that code will have bugs then the mitigation should be that they are at least documented once discovered, but ST documentation is also disappointing.

I've started another thread on my problems here https://community.st.com/s/question/0D53W00000MgE7qSAF/stm32f767-sdmmc-dma-read-missing-first-16-bytes

Please let me know if this problem is solved.

I'll keep trying and let you know when I solve it.

I've posted an update as I'm making progress!