STM32H7: FatFs mounting fails when using FreeRTOS + SDMMC
I am working with an STM32H743VIT6 and I am trying to migrate an existing bare-metal LVGL + SDMMC + FatFs project to FreeRTOS + LVGL + SDMMC + FatFs
In my previous bare-metal project, the SD card worked correctly.
However, after creating a new project using STM32CubeMX with FreeRTOS + SDMMC + FatFs, the FatFs mount operation fails from the beginning.
The problem occurs when calling:
f_mount(&SDFatFS, SDPath, 1);
void LVGL_Task(void *argument) {
(void)argument;
printf("LVGL Task START\r\n");
FRESULT fres;
printf("before f_mount\r\n");
fres = f_mount(&SDFatFS, (TCHAR const *)SDPath, 1);
printf("after f_mount, result = %d\r\n", fres);
if (fres == FR_OK) {
printf("SD success\r\n");
} else {
printf("SD fail\r\n");
}
printf("before ui_init\r\n");
ui_init();
printf("after ui_init\r\n");
while (1) {
uint32_t delay = lv_timer_handler();
if (delay > 1000)
delay = 10;
osDelay(delay);
}
}
I have placed the buf address in AXI SRAM and confirmed that the address is correct through UART printing
Linker:
/* Specify the memory areas */
MEMORY
{
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
LVGL_RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 320K
SD_DMA_RAM (xrw) : ORIGIN = 0x24050000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x24060000, LENGTH = 128K
DMA_RAM (xrw) : ORIGIN = 0x30000000, LENGTH = 64K
RAM_D2 (xrw) : ORIGIN = 0x30010000, LENGTH = 224K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
}
fatfs.c:
/* USER CODE BEGIN Variables */
__attribute__((section(".SD_DMA_RAM")))
__attribute__((aligned(32))) FATFS SDFatFS;
char SDPath[4];
/* USER CODE END Variables */
After a timeout of 30 seconds, SD fail will be displayed

Is there something wrong with the configuration of my STM32cubemx? Here are pictures of my various configurations




I have enabled D-Cache, but I managed the MDMA_buf address with an MPU to prevent D-Cache from accessing it. My LCD's DMAobuf also works this way, so there is no problem

I have already confirmed that the hardware and SD card itself are working because the previous bare-metal implementation can mount and read the same SD card successfully.
