cancel
Showing results for 
Search instead for 
Did you mean: 

Using SDMMC/SDIO and FATfs for reading SD Card for STM32L471VGT6

morris
Associate II

MCU: STM32L471VGT6

I am trying to get an SD Card to work for my system. I am using a custom board and I cant share any drawings. However, what I am using for the SD Card:

Sd card adapter: https://learn.adafruit.com/adafruit-microsd-spi-sdio

Sd card: SDHC 32 GIG micro sd card.

The wiring is okay, I checked so many times.

The sd card and adapter works for spi, tried it on arduino.

What I have tried in STM32CubeMX:

Enable SDMMC1 (Tried both SD 1 bit and wide 4 bit)

- Formatted it on windows to FAT32

- Interrrupt on

- DMA on

- Pullup on every pin except CK

- Put sdmmc clock to 48 MHz

- DMA template enabled on FATFS

I have tried different PCB, tried different sd adapter, tried different sd card

What My code is crashing on is the f_mount. It returns 

FR_DISK_ERR after a while.
1 ACCEPTED SOLUTION

Accepted Solutions

I found it, I had to run 

PeriphCommonClock_Config() after exited my sleep mode becuase the sdmmc runs on a clock that doesnt get started by  SystemClock_Config().

View solution in original post

14 REPLIES 14
SofLit
ST Employee

Hello @morris  and welcome to the community.

Please read these recommendations on this link on how to post a thread on the community. Especially the details of your HW (MCU part number), a concise description of your problem  etc ..

So please share schematics/project etc to let community members to help you efficiently.

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.

As I said I cant share any schematics

AScha.3
Chief III

Hi,

f_mount is the first , that has to work. If not - no useful access to card.

Connection cpu to card at max. 50mm length;

+ What you should do :

1. set port/pins to medium or med./high speed , not high; + pullups ON an all pins to sd-card.

2. set 1-bit mode (4-bit much more critical...for later playing around...)

3. no DMA template (also...later)

4. in Cube->fatfs : enable ex-fat and long filenames (working also with 64GB ex-fat cards, as you buy them, bigger i dont have, but should work also; dont format cards, usually they have "best" matching format when new..)

Then try mount (...1); (1 = now)

If you feel a post has answered your question, please click "Accept as Solution".

@morris wrote:

As I said I cant share any schematics


That really cripples the possibilities for remote assistance!

Can you not at least show the connections of the SD Card adaptor to the microcontroller?

And give the full microcontroller part number.

Do you have a logic analyser to see what's happening on the wires?

Can you reproduce the issue on an ST board?

 

EDIT:

 


@morris wrote:

The sd card and adapter works for spi, tried it on arduino


Are you sure it works for SDIO ?


@morris wrote:

As I said I cant share any schematics


Sorry this feedback doesn't help .. 

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.

The pins speed made it worked. You are amazing!!! Now I can use the sd card at:

- 1 bit mode

- interrupt ON

- DMA TX/DMA RX

- Medium speed with pullup

 

The solution breaks when I try to:

-Enable dma template

- Enable 4 bit mode

 

Do I want Dma template, I have read somewhere that it acheives best performace. How do make 4 bit mode work?

 

 

I updated the original post with the part number of the stm.

Yep the adapter works for both sdio and spi

Do you have a logic analyser to see what's happening on the wires?

Can you not at least show the connections of the SD Card adaptor to the microcontroller?

Can you reproduce the issue on an ST board?

:)

- DMA : didnt work for me, but never tried much with this, because : WHEN i read (or write) the sd-card, i always need it NOW, so nothing different, if the cpu waits for data and transfers "itself", or waits for "dma-ready", done, same time.

But it could be better and important in other area, in RTOS system etc, because no cpu load for data transfer.

 

- 4.bit mode: sure, is faster, but also much more sensitive to connection (reflection, ringing etc.) on the lines;

thats also why pin-speed is important: the cpu pins are so fast switching, that this produces a lot of EMI and rf-ringing.

And also on line length: i had an adapter, about 80mm from cpu - never 4bit mode working. Same with 30mm distance working on 4bit mode, full speed (50 MHz on sdmmc module).

So dont think, 4-bit is 4 times as fast, real is: if you read lets say 8kB from card, at 25Mbit this needs about 2,6ms; but at first the command is send to card, some xx us, then card access its memory area, needs about 0.5 ...3ms, sometimes 100ms (no joke!) , so reading 8KB needs about 4ms and if you can do same at 4-bit mode, it will need about 1...3ms .

If you feel a post has answered your question, please click "Accept as Solution".