cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using µSD card with SDIO and FatFs

KMach.2
Associate II

 I'm trying to make a program one of the features of which is SD card support. I'm using HAL libraries entirely, it's hard to find an example that combines SD card, SDIO communication and HAL libraries.

1. problem is that function f_mkdir, f_open returns FR_DISK_ERR no matter what order they are used.

I checked the physical connections, the signals show up in the communication. If there is no SD card in the slot it returns FR_NOT_READY.

2. i don't use an SD Card detect switch, could it be because of this? How can I bypass Dtetect_SDIO? Or make it so that the program works?

MCU: STM32F103VETxLQFP100

CubeIDE v1.7.0

CubaMX v6.3.0

The target program looks different, but with this code I tried to find errors.

uint32_t wbytes; //File write counts

 uint8_t wtext[] = "text to write logical drive"; //file write buffer

 short int res[5];

 res[0] = f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);

 if(res[0] == FR_OK)

 {

 res[1] = f_mkdir("sd_test"); //daje FR_DISK_ERR

 res[2] = f_open(&SDFile, "test.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ); //daje FR_DISK_ERR

 if(res[2] == FR_OK)

 res[3] = f_write(&SDFile, wtext, sizeof(wtext), (void *)&wbytes);

 else

 res[3] = 21;

 res[4] = f_close(&SDFile);

 }

13 REPLIES 13
ONadr.1
Senior III

Perharps help

https://controllerstech.com/interface-sd-card-with-sdio-in-stm32/

There are a plenty of good ideas and examples for STM32.

Unfortunately I have seen, checked and in my case it does not help with my problem.

ONadr.1
Senior III

I try this microSD comunication on 32F401xxx CPU. A have some trouble when I use only internal CPU pullups. After I use 10k external pullups, good 3,3V power source and power blocking capacitors, there were no problem here.

I'm using 5V USB voltage and TC1107 stabilizer to obtain 3.3V with 47K resistors. This is probably not the problem. I checked the other resistors just to be sure. Also no.

ONadr.1
Senior III

Is it possible to read some file on uSD?

ONadr.1
Senior III

Hello @KMach.2​ ,

Could you please provide the reference of the SD Card used.

I also invite you to take a look at the examples provided in our firmware package ( Path : Projects\STM3210C_EVAL\Applications\FatFs )

and customize it to your board.

BeST Regards,

Walid

I tried it on two different cards. The first, target one is a 2GB kingston older one and the second one is a 4GB kingston SDHC. I don't know their parameters, but I specifically chose smaller/older cards. I formatted them properly to FAT format before using them.

ONadr.1
Senior III

And when you save a file from a PC to the card, can you then open it and read it?