2022-06-10 10:10 AM
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:
EDIT:
OK, I've found why it happens and the workaround for it, check my answer below.
Solved! Go to Solution.
2022-06-12 06:39 AM
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.
2022-06-10 10:15 AM
>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.
2022-06-10 10:53 AM
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.
2022-06-10 12:26 PM
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.
2022-06-12 06:39 AM
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.
2024-08-15 01:32 PM
I am not an expert, apologise if I am wrong but it helped me.
in ff.c at line like 3046 it was as below.
if (sign == 0xAA55 && !memcmp(fs->win + BS_FilSysType32, "FAT32 ", 8))
then I have realised, memcmp returns by comparing 8 bytes but "FAT32 " has only 6 bytes. Thus comparisation returns with "not match". it can not understand if VBR (Volume Boot Record) is really FAT32.
I have changed it to
if (sign == 0xAA55 && !memcmp(fs->win + BS_FilSysType32, "FAT32 ", 6))
It worked... Hope it helps you!
2024-08-15 01:33 PM
ff.c line 3046
if (sign == 0xAA55 && !memcmp(fs->win + BS_FilSysType32, "FAT32 ", 8))
8 is the wrong number, change it to 6