3
\$\begingroup\$

I am trying to read and write to a class 10 - 2GB SD card from STM32 with the help of FATFS R0.11, but f_mount() function is returning FR_NO_FILESYSTEM error code. I have tested the same code on a class 4 - 2GB and class 10 - 16GB SD card, and it worked perfectly. What am I doing wrong here for this specific SD card?

Code:

FIL filTest;
FATFS fs;

FRESULT initSD()
{

    disk_initialize(0);
    FRESULT res;

    res = f_mount(&fs, "", 1);

    if(res != FR_OK)
    {

        return res;

    }

    res = f_open(&filTest, "test.txt", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
    return res;

}
\$\endgroup\$
2
  • 2
    \$\begingroup\$ The "class 10 - 2GB SD" is bogus. Speed classes only apply to SDHC cards IIRC, and those are >=4 GB. \$\endgroup\$
    – Turbo J
    Apr 1, 2017 at 22:25
  • \$\begingroup\$ Did you try reformatting the card? \$\endgroup\$
    – JimmyB
    Apr 3, 2017 at 20:30

2 Answers 2

3
\$\begingroup\$

You will get a return code FR_NO_FILESYSTEM if a file system does not exist (LINK). Just format the SD card and it should be fine. I'm assuming you're using Elm Chan's free implementation of FAT.

More fun stuff: If you go deep enough into ff.c you can see we call check_fs() inside find_volume(). It is in check_fs() we check if the SD card or flash or any memory has a FAT file system. We need a file system to mount a disk. You can use f_mkfs to format a system into FAT. (LINK)

\$\endgroup\$
1
\$\begingroup\$

I had the problem that 1 of my 4 SD Cards lying arround was working. On the others i got FR_NO_FILESYSTEM when mounting with f_mount. If you check your card with HxD in sector 0 the last 2 bytes should be 0x55 and 0xAA when FAT formatted.

My cards where correctly formatted but were not recognized as FAT Format and the bug was actually in the low level implementation.

On STM32 (with spi HAL library) when reading from the SD Card a 0xFF has to be sent (MOSI has to be HIGH for every bit) and so i had to use the HAL_SPI_TransmitReceive() function to send a 0xFF while receiving.

After that the other cards worked without problem.

I guess some cards can live without it.

\$\endgroup\$
1
  • \$\begingroup\$ This sorted the problem for me! \$\endgroup\$
    – Pyrohaz
    May 12, 2020 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.