cancel
Showing results for 
Search instead for 
Did you mean: 

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

Nxyoutou
Associate
Hey everyone,

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:

Z4bvFoim.png

 

FATFS configuration:

JfGicY82.png

 

The SPI pinout in CubeIDE:

WSXm2zwX.png

 


I set the CS output on default high for the SPI communication protocol.

fjBGj06t.png

 

The clock configuration:

gwsKU9qI.png

 

I use this SD card reader module

ZL511bxm.png

 

What I have tried and didn't work:

  • Switch out the SD card reader module.

  • Switch out the microSD card.

  • Use an internal Pull-up resistor for the MOSI and CS lines (I didn't have an option to choose pull-up resistors. for MISO and SCK.)

  • Have "Low" as default CS output.

  • Checked the SCK signal on the oscilloscope and it was reading something, which seemed to me alright, so I don't think it's a hardware issue.

  • Put some signs into the "" of the f_mount input.

  • Use 0 as the initialization input for the f_mount function (this returns always FR_OK though, so it doesn't really help.)

  • Double check SPI connections (everything should be connected correctly.)

Any help is welcome, thank you so much!

1 REPLY 1
SofLit
ST Employee

Hello @Nxyoutou and welcome to the community,

I propose you to look at the Adafuit SD implementation (using SPI) provided in STM32CubeF1 BSP: in https://github.com/STMicroelectronics/STM32CubeF1/blob/master/Drivers/BSP/Adafruit_Shield/stm32_adafruit_sd.c

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.