cancel
Showing results for 
Search instead for 
Did you mean: 

fs_mount() from FATFS on SD card returns FR_NO_FILESYSTEM. Why?

HTD
Senior III

The hardware is configured, initialization passes (fails if no card is inserted).

The card is 8GB micro SD formatted on Windows with exFAT, contains 1 file "test.txt" with content "HELLO".

The exFAT option is enabled for the FATFS.

Here's my code:

FATFS fs;
FRESULT fr = f_mount(&fs, (TCHAR*)"0:/", (BYTE)1);

In the next line the debugger shows "fr = FR_NO_FILESYSTEM".

It behaved the same with SD card formatted with FAT32. Since the card is 8GB it can't be formatted with FAT16.

My question is very similar to:

https://community.st.com/s/question/0D50X00009Xkf5gSAB/frnofilesystem-fatfs4pins-sdcard-with-nucleol476rg

EDIT:

OK, I've found why it happens and the workaround for it, check my answer below.

1 ACCEPTED SOLUTION

Accepted Solutions
HTD
Senior III

Fixed. Sort of. DMA was not working but required.

How have I figured it out? I've changed DMA functions to interrupt functions and it worked.

Then I unnecessarily hacked the driver to not use the DMA feature... Skip that part.

Why DMA was not working?

https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices

How to fix it? Just disable `CPU DCache` in `System Core / CORTEX_M7` in Cube.

Did my TouchGFX application slowed down? IDK. My impression - not at all.

If anyone would try to test SD card reader from STM32H747I-DISCO (or maybe other H7 setups) - keep that in mind. You must disable DCache or DMA and all that depends on DMA will fail just reading garbage. Also - if you wonder what options in SDMMC1 you can enable: pretty all of them except "External trasceiver present" - though I'm not sure about it, I haven't tested enabling it.

So I have my SDMMC1 configured as "4 bit bus with auto dir voltage converter", "hardware control flow enabled", "Clock divider = 1" - that gives 75MHz to the SD.

In FATFS I have all RTOS related options enabled, also LFN (with stack), UTF8/UNICODE, exFAT. Works as charm with modern cards >4GB formatted in Windows.

For card detection pin - I've read it could use ANY GPIO input. It's quite weird, because in the documentation for STM32H747I-DISCO stands that is a specific pin: PI8. It's not configured as input though, so it has to be done manually before configuring FATFS.

That's it, it took me way too much time to figure it all out, maybe someone could use what I've learned here.

View solution in original post

4 REPLIES 4

>Why?

Probably because the MBR or BPB read by your DISKIO layer doesn't look valid/correct to the version of FatFS you're running.

Check its reading data properly, and as expected. Inspect the data.

Trace / walk the code, you have ALL the source.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I did it. Of course it doesn't look valid.

fmt = check_fs(fs, bsect);

This returns 3. Not a valid value. But why? The card is OK. Windows reads it.

Also

fr = f_mkfs((TCHAR*)SDPath, FS_EXFAT, 0, 0, 1024);

returns FR_DISK_ERR. Should write 2 sectors, but failed.

What I discovered that my SDMMC1 in Cube does not have DMA settings. And it uses DMA. Weird.

HTD
Senior III

Fixed. Sort of. DMA was not working but required.

How have I figured it out? I've changed DMA functions to interrupt functions and it worked.

Then I unnecessarily hacked the driver to not use the DMA feature... Skip that part.

Why DMA was not working?

https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices

How to fix it? Just disable `CPU DCache` in `System Core / CORTEX_M7` in Cube.

Did my TouchGFX application slowed down? IDK. My impression - not at all.

If anyone would try to test SD card reader from STM32H747I-DISCO (or maybe other H7 setups) - keep that in mind. You must disable DCache or DMA and all that depends on DMA will fail just reading garbage. Also - if you wonder what options in SDMMC1 you can enable: pretty all of them except "External trasceiver present" - though I'm not sure about it, I haven't tested enabling it.

So I have my SDMMC1 configured as "4 bit bus with auto dir voltage converter", "hardware control flow enabled", "Clock divider = 1" - that gives 75MHz to the SD.

In FATFS I have all RTOS related options enabled, also LFN (with stack), UTF8/UNICODE, exFAT. Works as charm with modern cards >4GB formatted in Windows.

For card detection pin - I've read it could use ANY GPIO input. It's quite weird, because in the documentation for STM32H747I-DISCO stands that is a specific pin: PI8. It's not configured as input though, so it has to be done manually before configuring FATFS.

That's it, it took me way too much time to figure it all out, maybe someone could use what I've learned here.