Skip to main content
Associate
November 12, 2024
Solved

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

  • November 12, 2024
  • 7 replies
  • 1782 views

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.
Best answer by mƎALLEm

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

 

7 replies

Andrew Neil
Super User
November 12, 2024

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
November 13, 2024

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
November 12, 2024

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
November 13, 2024

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.
November 12, 2024

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
November 13, 2024

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.
November 13, 2024

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.