cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32F7xx CubeMx - SD Disk I/O DMA with RTOS driver - SD_read function invalid address access.

DScab
Associate

Hi, I am using ChaN's FatFS on Cortex M7 microcontroller family (stm32F7xx).

I'm also using CubeMX HAL from ST and FreeRTOS and SDMMC interface with DMA. The environment is the Attolic IDE.

But I'm facing some problems to use it. Sometimes some functions like f_open, f_mkdir, f_opendir returns FR_INT_ERR.

After some tests and internet research, I'm still blocked on this issue and couldn´t solve the problem yet.

So I started debugging the HAL from ST/ChaN FatFS and I found something that could be a possible bug. I'll appreciate if someone could confirm this or analyze it.

The first thing I am using is the "ENABLE_SD_DMA_CACHE_MAINTENANCE=1" configuration.

At file "sd_diskio_dma_rtos.c" on function "SD_read" the following code is:

...

..

#if (ENABLE_SD_DMA_CACHE_MAINTENANCE == 1)

/* the SCB_InvalidateDCache_by_Addr() requires a 32-Byte aligned address, adjust the address and the D-Cache size to invalidate accordingly.*/

     alignedAddr = (uint32_t)buff & ~0x1F;

 

     SCB_InvalidateDCache_by_Addr((uint32_t*)alignedAddr, count*BLOCKSIZE + ((uint32_t)buff - alignedAddr));

#endif 

..

..

If you add a pointer data with start address like 0x20020400 probably it will work fine, but if buffer starts at 0x2002040F then we have a problem because alignedAddr will be 0x20020400 (after & ~0x1F) and the function "SCB_InvalidateDCache_by_Addr" will set data starting 0x20020400 contaminating others variables.

To solve the problem I've forced vars with aligned of 32 at ff.h:

...

typedef struct {

   ...

BYTE win[_MAX_SS] __attribute__((aligned(32))); /* Disk access window for Directory, FAT (and file data at tiny cfg) */

} FATFS;

.....

typedef struct {

   .....

#if !_FS_TINY

BYTE buf[_MAX_SS] __attribute__((aligned(32))); /* File private data read/write window */

#endif

} FIL;

...

...

I made some tests and after write/read more them 1000x, the issue is gone and no more FR_INT_ERR.

Thanks.

Danilo Scabello

1 REPLY 1
heveskar
Senior

I created an issue (with your solution) on ST GitHub, maybe they will try to fix it (even if it may be a problem in the FatFS library itself).