Skip to main content
Associate
Nov 12, 2024 11:05 AM UTC
Solved

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

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?

This topic has been closed for replies.
mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
Nov 12, 2024 11:29 AM UTC

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 "Best answer" on the reply which solved your issue or answered your question.

7 replies

Andrew Neil
Super User
Nov 12, 2024 11:22 AM UTC

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 ...?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
ClockZLZAuthor
Associate
Nov 13, 2024 1:04 AM UTC

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!

mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
Nov 12, 2024 11:29 AM UTC

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 "Best answer" on the reply which solved your issue or answered your question.
ClockZLZAuthor
Associate
Nov 13, 2024 2:16 AM UTC

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.

Pavel A.
Nov 12, 2024 11:35 AM UTC

> 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.

ClockZLZAuthor
Associate
Nov 13, 2024 1:15 AM UTC

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.

Pavel A.
Nov 13, 2024 12:07 PM UTC

> 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.