cembeddedsd-cardstm32f1fatfs

FATFS via SPI for NUCLEOF103RB not working, returns FR_NOT_READY (3)


I have been sitting on this problem for a couple of days where I have been trying to use f_mount on a 8GB SD card (I formatted it to FAT32 and to a sector size of 4096.) I am also copying a very popular library by eziya: https://blog.naver.com/eziya76/221188701172. The chip I am using on my NUCLEO board is a STM32F103RB.

Although the program is very simple, no matter what I do, the SD card never gets mounted. When trying to read the available space and the total space, it always returns 0.

Here is my code for the main loop:

FATFS fs;
FIL fil;
FRESULT fresult;
char buffer[1024];

UINT br, bw;

FATFS *pfs;
DWORD fre_clust;
uint32_t total, free_space;
fresult = f_mount(&fs, "", 1);
printf("%d \n", fresult);
if (fresult != FR_OK) printf("Unsuccessful again\n");
else printf("Mounted successfully! \n");

f_getfree("", &fre_clust, &pfs);
total = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5);
printf("Total size: \t%lu\n",total);
free_space = (uint32_t)(fre_clust * pfs->csize * 0.5);
printf("SD CARD free space: \t%lu\n", free_space);

I used SPI for the configuration, here are my configurations for the CubeIDE:

SPI configuration:
enter image description here

FATFS configuration:

enter image description here

SPI pinout in the CubeIDE:

enter image description here

I set the CS output on default high for the SPI communication protocol.
enter image description here

The clock configuration:

enter image description here

I use this SD card reader module

enter image description here

What I have tried and didn't work:

Any help is welcome, thank you so much!


Solution

  • So in the end I was able to figure out the issue. I did what was suggested and went through the program step-by-step through breakpoints. What I found is that is was definitely a hardware issue. I switched out a bunch of these blue SD card reader modules, and it still didn't work. However, when I used a totally different SD card reader from SparkFun, it suddenly worked. NONE of these blue SD card reader modules worked. To sum it up -- Beware of these Blue Devils.