2024-01-18 07:20 AM
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 ?
2024-01-19 06:58 AM
So are those suggestions correct?
ie, should it be USERFatFS rather than SDFatFS, etc?
What are the other 3 warnings & 3 others?
2024-01-19 07:05 AM - edited 2024-01-19 07:06 AM
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 ?
2024-01-19 07:08 AM
I find this a huge shortcoming!
The video I shared has only 13 minutes and is simple to reproduce. Let's say 1 hour to setup all the stuff. Frankly, I don't think we can assume 1 hour of a such a task is a huge work ;).
2024-01-19 07:10 AM
Why are you planning to use SPI instead of SDIO? is there any constraint?
2024-01-19 07:22 AM
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 ?
2024-01-19 07:41 AM
It seems you're using the NUCLEO-L433RC-P which has 64 pin package with SMPS. Unfortunately, and according to the datasheet, this package does not support SDIO feature but you can use SPI instead:
2024-01-19 07:47 AM
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
2024-01-23 08:19 AM - edited 2024-01-23 08:28 AM
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.
2024-01-23 08:30 AM
@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 ...
2024-01-23 08:40 AM - edited 2024-01-23 08:44 AM
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