Skip to main content
Associate III
January 18, 2024
Question

SD card driver for NUCLEO-L433RC-P ?

  • January 18, 2024
  • 22 replies
  • 4479 views

I have the NUCLEO-L433RC-P development board and looking for some code that will allow me to read and write to a micro SD card, but I can't seem to find anything in the example code for this processor.

I found some SD card example code but they were for a different processors and I don't know how to change the processor to an STM32L433

How can I get some software that will allow me to use an SD card with this development board ?

 

 

This topic has been closed for replies.

22 replies

Andrew Neil
Super User
January 18, 2024

FatFs is widely used on many (most?) microcontrollers - it can be easily ported to any microcontroller:

http://elm-chan.org/fsw/ff/

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
johngjAuthor
Associate III
January 18, 2024

Thanks Andrew, I've been trying to use FatFs on an NXP dev board but with no success (see link below for details) which is why I was hoping ST would have an off the shelf solution.

https://community.nxp.com/t5/S32K/Issue-with-SD-card-using-SPI-on-S32K146-CMD17-response-not-zero/m-p/1791257#M30833

Fatfs is only the driver to control a FAT system, it does not include anything to send the SPI commands to the SD card ?

 

mƎALLEm
ST Technical Moderator
January 18, 2024

Hello,

Inspire from the example: Projects\STM32L476G-EVAL\Applications\FatFs provided in STM32CubeL4.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
johngjAuthor
Associate III
January 18, 2024

Thanks SofLit, I tried to use one of the FatFs_uSD_Standalone examples but it would not run because it was using the wrong processor and I don't know how to change it to a STM32L433.

The settings for MCU in the project properties are greyed out and cannot be changed...

 

johngj_0-1705597768010.png

 

 

 

 

 

 

mƎALLEm
ST Technical Moderator
January 18, 2024

You need to start from scratch using CubeMx to initialize the needed peripherals mainly the SDIO + Adding FatFs and populate your project by inspiring from the example.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Tesla DeLorean
Guru
January 18, 2024

ST doesn't make examples for every conceivable part / board, but rather only those boards they build with specific hardware.

The L4 is perhaps a bit more complex in this regards as there are perhaps 3 SDIO/SDMMC implementations. But it should be possible to migrate the examples for DISCO or EVAL series boards to the NUCLEO with a suitably wired harness. Previously built working examples for clients.

I'd recommend boards like this WaveShare one with appropriate pull-ups and termination

https://www.waveshare.com/wiki/Micro_SD_Storage_Board

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
mƎALLEm
ST Technical Moderator
January 18, 2024
To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
johngjAuthor
Associate III
January 19, 2024

Thanks SofLit,  I followed the youtube video but get the following build errors...

johngj_0-1705673367025.png

The only difference between the youtube video and my project is that I am using the NUCLEO-L433RC-P (whereas the video is using the STM32F746G-DISCO).

I have to use SPI peripheral as the interface, because the L433RC does not have the SDMMC peripheral

 

 

Andrew Neil
Super User
January 19, 2024

So are those suggestions correct?

ie, should it be USERFatFS rather than SDFatFS, etc?

What are the other 3 warnings & 3 others?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
johngjAuthor
Associate III
January 19, 2024

Thanks Andrew, yes I found the problem and changed USERFatFS to SDFatFS

The problem now is that the project needs an SPI driver to communicate with the SD card.

I enabled the SPI peripheral when creating the project, but dont know how to write the SPI driver for the SD card

Are there any examples ?

I spent a lot of time trying to get the SD card driver working on the NXP dev board, but couldnt get it to work so thought I would try ST.

I didnt expect an SD card driver to be so difficult and when you search online it seems many people have difficulties trying to to the drivers to work with an SD card, yet alone the issue with compatibility with different types of SD cards available.

Its not like SD cards are a new technology, surely there should be robust and mature drivers out there ?

mƎALLEm
ST Technical Moderator
January 19, 2024

Why are you planning to use SPI instead of SDIO? is there any constraint?

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
johngjAuthor
Associate III
January 19, 2024

Does the STM32L433 have SDIO ?

If it does, I still need a driver for the SDIO so that it can communicate with the SD card

Does an SPI or SDIO driver have to be written from scratch using the 400+ page SD specification or is there some example code ?

mƎALLEm
ST Technical Moderator
January 19, 2024

And you don't need to write the driver. All the drivers are provided in the STM32CubeL4 but the peripheral initialization could be done through CubeMx.

I suggest you to start by familiarizing with CubeMx: https://www.youtube.com/watch?v=Yw5lS55bL5I

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
johngjAuthor
Associate III
January 23, 2024

I have managed to get an SD card driver working using this guide...

Video version:

Written version:

I have tried two different SD cards:

1. Kingston 16GB microSDHC CL10 

2. Transcend 2 GB MicroSD Micro SD Card, Class 30 (TS2GUSD)

However, it does not work with the Transcend 2GB card.

During debugging, free_space returns the value zero...

 

free_space = (uint32_t)(fre_clust * pfs->csize * 0.5);

 

And f_open returns the value FR_NO_FILESYSTEM...

 

fresult = f_open(&fil,"file1.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE);

Why does the 16GB SD card work, but the 2 GB SD card doesn't ?

I tested the 2GB SD card in Windows 10, I formatted it as FAT32 and tried saving and deleting a file.  

So the card is functional, but it does not work with this driver running on the STM32.

I have attached the project for reference.

Andrew Neil
Super User
January 23, 2024

@johngj wrote:

During debugging, free_space returns the value zero...

 

free_space = (uint32_t)(fre_clust * pfs->csize * 0.5);

 


So fre_clust or pfs->csize (or both) must be zero.

Check back through the code to see where the wrong value is creeping in ...

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
johngjAuthor
Associate III
January 23, 2024

fre_clust is zero

pfs->csize is 2048

What does it mean if fre_clust is zero ?

During the function f_getfree, the result of..

res = find_volume(&path, &fs, 0);

...is FR_NO_FILESYTEM

johngjAuthor
Associate III
January 24, 2024

So there is something wrong with the driver then ?

Because the card works in my Windows laptop, I can format, read, write and delete files to the card

But the driver for the NUCLEO-L433RC-P thinks it has no file system, when it obviously does

Andrew Neil
Super User
January 24, 2024

Is the card even initialising properly?

Perhaps the card doesn't (fully/properly) support SPI access?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.