cancel
Showing results for 
Search instead for 
Did you mean: 

How can i write and read on SD using FREERTOS e FATFS?

JTLGE
Associate II

Hello,

I am using STEVAL-STWINKT1B development board and I can write and read sd card using setting to SD 4 bits Wide Bus and FATFS.

If I add on STM32CUBEMX as middleware FREERTOS I can't read the SD in fact I get back FR_NOT_READY when I execute the f_open method.

How can I solve this problem?

1 ACCEPTED SOLUTION

Accepted Solutions
Slh
Senior

Did you adjust the heap-size and task-size enough?

For using RTOS with SDCARD, you better active DMA for SDCARD.

View solution in original post

7 REPLIES 7
SofLit
ST Employee

Hello,

I suggest to refer to one of examples provided in a CubeFx. For example the one provided in STM32F7 under the path: Projects\STM32F769I_EVAL\Applications\FatFs\FatFs_uSD_RTOS

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Slh
Senior

Did you adjust the heap-size and task-size enough?

For using RTOS with SDCARD, you better active DMA for SDCARD.

JTLGE
Associate II

In my project on the STM cube MX I modified the following parameters:

Freertos - config parameters- minimal stack 256

Project manage - linker settings Minimum Heap Size 0x400

Project manage - linker settings Maximum Heap Size 0x800

Moreover FatFS has the setting use dma enabled and on the SDMMC1 interface I don't have the tab to select the DMA settings (I think it's set by default but I'm not sure).

this is the task where i use FatFs:

void StartDefaultTask(void *argument)

{

/* USER CODE BEGIN 5 */

FRESULT fres;

uint32_t byteswritten, bytesread; /* File write/read counts */

uint8_t wtext[] = "STM32 FATFS works great!"; /* File write buffer */

fres = f_mount(&SDFatFS, (TCHAR const*)SDPath, 1);

fres = f_open(&SDFile, "TEST.csv", FA_CREATE_ALWAYS | FA_WRITE);

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

fres = f_close(&SDFile);

HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);

/* USER CODE END 5 */

}

Slh
Senior

Test it once with 1-Bit mode and in RTOS:

change your Stack size of your task to minimum 4KB.

Minimal Stack size 128 word

Total heap size 16000

JTLGE
Associate II

thanks a lot for the help now is working properly writing to sd even in 4 bit mode

Bsm
Associate II

I created implementation with general operations for fatsfs & freertos with CubeMX u can test this code

github.com/Bsm-B/Stm32-FatFs-FreeRTOS/

@JTLGE 

I am running into the same issue how did you fix it? I also don't have the DMA tab for sdmmc and I have the following settings.

Freertos - config parameters- minimal stack 256

Project manage - linker settings Minimum Heap Size 0x1000

Project manage - linker settings Maximum Heap Size 0x1000