Skip to main content
Visitor II
March 2, 2022
Solved

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

  • March 2, 2022
  • 6 replies
  • 6187 views

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?

    This topic has been closed for replies.
    Best answer by Slh

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

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

    6 replies

    Technical Moderator
    March 2, 2022

    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

    SlhAnswer
    Graduate II
    March 2, 2022

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

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

    JTLGEAuthor
    Visitor II
    March 2, 2022

    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 */

    }

    Graduate II
    March 2, 2022

    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

    JTLGEAuthor
    Visitor II
    March 3, 2022

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

    Graduate II
    December 4, 2024

    @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

    Visitor II
    October 23, 2022

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

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