Skip to main content
Visitor II
November 12, 2024
Solved

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

  • November 12, 2024
  • 3 replies
  • 1742 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

     

    3 replies

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

    ClockZLZAuthor
    Visitor II
    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ƎALLEmAnswer
    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

     

    ClockZLZAuthor
    Visitor II
    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.

    Super User
    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
    Visitor II
    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.

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