cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX breaks SDMMC DMA transfert for FatFS using SD card

VBurs
Associate II

Hi,

I have a STM32F779BI on a custom board that communicates with a LCD display using the LTDC interface in 16bits (480x272). I am using a single buffer inside the RAM of the MCU. So far TouchGFX works pretty well but once i activated the Software package for touchgfx inside Cubemx, i see that a "MX_TouchGFX_Init();" is added in the Main init section and i have to manually call the "MX_TouchGFX_Process();" in a task when all my board is up and running and can finally start the drawing process on the LCD.

My problem is that i have a task for logging data on a SD card using FatFS. Since i am using FreeRTOS, i had to implement the writes and Reads using the DMA on the SDMMC. This works pretty well too when touchgfx is not initialized ("MX_TouchGFX_Init();") and started ("MX_TouchGFX_Process();").

At first i thought it was a problem of NVIC priority for the SDMMC DMA versus the DMA2D interrupt priority. However, i made sure to give the DMA2D a priority less than for the DMA SDMMC and it still don't work.

The reason i know it's not behaving correctly is that FatFs return "FR_NO_FILESYSTEM" when doing a "f_open()". Normally, the FatFs generated by CubeMx does not need any modifications and if it breaks, is usually due to a lower layer (DMA transfer in this case).

Has anyone experienced problem with the Sdcard when using touchgfx in this communiation: SDMMC+DMA+FATFS+FReeRTOS+TouchGFX?

I have provided the project as is where you can look into my cubemx file for settings.

Thanks in advance for the help.

35 REPLIES 35
Piranha
Chief II

With regards to that explanation then, is that something that we should implement manually before/after FatFS interactions? I'd have thought that level of D-Cache management would have been done by the FatFS library if it was necessary?

The D-cache maintenance code should not be in the generic library, but in the DISKIO driver for the specific platform. And, as in this case the driver is implemented by ST, it is a broken bloatware. Therefore the real answer is - toss out the code implemented by incompetent fools and replace it with a decent one.

Hello!

i have read the documentation you provide in your post.

But unfortunately i have no succes for using TouchGFX + FATFS SDMMC on a stm32f746G-disco

i have also tried FatFs with USB HOST with the same result

did you have some working code that you want to shere here?

thank you

Andrea

Hello!

i know this post is from 2021 but i have the same issue now in the end of 2023

 

there is no an official ST solution at this issue? 

i'm unable to write to a file on SD card or USB disk if the touchgfx is used

 

i have tryed many solution provided in the forum but i 'm stuck on this project for weeks

thank you in advance if you have a working solution

 

Andrea 

 

Hello,

I think I found the solution. I compared a working version to a non working version with git diff and I found the following changes fix my problem:

1. It seems that when we generate code that this line in fatfs_platform.c "if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == GPIO_PIN_RESET)" changes == to != which is incorrect. So we need to have == and NOT !=. We have to change this after every generate.

2. The generator removes multiple lines from bsp_driver_sd.c right before sd_stat = HAL_SD_Init(&hsd1); The lines that were removed and we need to add again"

-  hsd1.Instance = SDMMC1;
-  hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
-  hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
-  hsd1.Init.BusWide = SDMMC_BUS_WIDE_4B;
-  hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
-  hsd1.Init.ClockDiv = 0;"

 3. Also in my application I added f_mount(&SDFatFS, (TCHAR const*)SDPath, 0); to MX_FATFS_Init and then used the other commands in freertos.c. In freertos.c I also added extern variables and included fatfs.h to my freeRTOS.c. We can add f_mount after LinkDriver at USER CODE BEGIN Init The extern variables:

"

extern uint8_t retSD;

extern char SDPath[4];

extern FATFS SDFatFS;

extern FIL SDFile

"

4.This is the example that I used and works: "

FRESULT res; /* FatFs function common result code */

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

uint8_t wtext[] = "Are we working right now?"; /* File write buffer */

uint8_t rtext[100]; /* File read buffer */

 

BSP_SD_Init();

 

res = f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);

 

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

 

res = f_close(&SDFile);

"