cancel
Showing results for 
Search instead for 
Did you mean: 

FATFS on SD card have some error when D-cache is enabled

ClockZLZ
Associate II

All my code works on RTOS.

When I enable D-Cache,fs_mount() from FATFS on SD card returns FR_NO_FILESYSTEM,SD card can not work.

When I disable D-Cache, fs_mount() returns FR_OK, SD card can write and read.

But at the same time , i need to use Ethernet on my device . When I close D-Cache, my Ethernet can not work.

How can I resolve these two conflicting issues?

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello @ClockZLZ and welcome to the community.

Most probably it's something related to cache coherency/maintenance.

See this thread:

https://community.st.com/t5/stm32-mcus-embedded-software/fatfs-f-open-fails-when-data-cache-is-enabled/td-p/110777

 

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.

View solution in original post

7 REPLIES 7
Andrew Neil
Evangelist III

FatFS is open-source.

So step into fs_mount()  and see exactly where it is failing, and what causes that failure.

Similarly, step the code in the working case and see where it differs.

 

PS:

 


@ClockZLZ wrote:

at the same time , i need to use Ethernet on my device . When I close D-Cache, my Ethernet can not work.


Are you sure that the issue is actually to do with D-Cache, or is it some other conflict between your Ethernet & SD-Card stuff ...?

SofLit
ST Employee

Hello @ClockZLZ and welcome to the community.

Most probably it's something related to cache coherency/maintenance.

See this thread:

https://community.st.com/t5/stm32-mcus-embedded-software/fatfs-f-open-fails-when-data-cache-is-enabled/td-p/110777

 

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.
Pavel A.
Evangelist III

When I close D-Cache, my Ethernet can not work.

Does it crash / catch exception or fault when you disable D-cache? Ethernet should work even without D-cache, at least on older 'H7 such as H743.

Using the Cortex-M7 D-cache correctly is not trivial, this is why it is not enabled by default. When the cache is disabled, most libraries made for Cortex-M4 can be reused as is.

My SD card problem is the same as:

Solved: Re: fs_mount() from FATFS on SD card returns FR_NO... - STMicroelectronics Community

The Ethernet part is maintained by my colleague,i will make sure if there is any other conflict between your Ethernet & SD-Card.

thank you for your opinion!

Thank you very much for your opinion !

No crash or fault occure when I disable D-cache. In fact , in order to make Ethernet work will , I enable D-cache and MPU for it. 

If you are sure Ethernet can work without D-cache.  I will have a try.

it's usef to uncomment L63 in sd_diskio.c to activate Cache maintenance:

/* USER CODE BEGIN enableSDDmaCacheMaintenance */
#define ENABLE_SD_DMA_CACHE_MAINTENANCE  1 
/* USER CODE END enableSDDmaCacheMaintenance */

After doing this my SD Card can mount successfully when D-cache is enabled.

If you are sure Ethernet can work without D-cache.  I will have a try.

I got it working on STM32H743/53 with some previous version of ST libraries and ETH driver, not sure that the current will work as is. Hardware itself does work with properly assigned memories and no D-cache.