Skip to main content
John Craven
Senior
October 10, 2017
Question

CubeMX support for SD+FatFS+SPI

  • October 10, 2017
  • 5 replies
  • 5054 views
Posted on October 10, 2017 at 21:22

I would like to see CubeMX support for SD cards + FatFS using an SPI driver option. Both for MCUs that don't don't support SDIO and also on MCUs that have SDIO but where SPI fits the project better.

FatFS is there as 'user defined' forall.

SDIO option is there where supported.

Why not add SPI option under FatFS?

Seems like would be pretty minor to the follow the templates used in SDIOfor SPI.

Certainly would make it easier to get an stm32 project doing FatFS on SD!

#cubemx #sdio #spi #sd-card

Note: this post was migrated and contained many threaded conversations, some content may be missing.
This topic has been closed for replies.

5 replies

Technical Moderator
October 20, 2017
Posted on October 20, 2017 at 15:29

Hello

Craven.John

I raised your request internally to CubeMx team.

All your suggestion and comments are welcome.

Kind Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".Thanks Imen
John Craven
Senior
October 20, 2017
Posted on October 20, 2017 at 16:06

That's great! I have got SDIO working, but never bulletproof, and getting started on a breadboard or with breakouts is pretty dodgy to impossible. As a new STM32 user, my biggest frustration, has been getting SD and file IO going in my projects! Seems i am not alone. At least one new SDIO/fatfs thread pops up every week, Pretty much all the same, can't get it working without spending lot on proper pcb trace design.

I follow a couple open source projects, based on F3/F4/F7, and they all use SPI for SD/fatfs with zero issues. PCBs are simple. The SD card access is bulletproof. It seems it would be much simpler getting going with SPI. Sure there is may be a sacrifice on read/write rates, but full 4bit SDIO rates of 10MB/s are not always required.

When i look at my whole STM32 and CubeMX experience to date, and i could add one thing to cubemx, it would be a checkbox for FatFS/SPI, and simple SD card access on breadboard or with breakout, that worked as good as the many SPI device breakouts i have and use without any issues.

Seems the cubemx generated files for SDIO/FatFS, don't require many changes to support an SPI option.

Certainly, given the number of users on here with SDIO issues, i figure a many would rather have slower SPI SD access, than none or headaches with unreliable fast SDIO.

Anyways, thx for passing it on! I hope it get into CubeMX soon.

Tesla DeLorean
Guru
February 7, 2018
Posted on February 07, 2018 at 23:33

Always been successful with SDIO, both with wire-wrap and schmart wire implementation, and a couple of assorted boards I've worked on, or ported code too.

https://community.st.com/0D50X00009XkYXdSAN

https://community.st.com/0D50X00009XkZe6SAF

Currently got both an SPI and SDMMC implementation working on a NUCLEO-L476RG, the SPI is a bit of a sloth, which is why I usually avoid it. Also had to dig some bugs out of the adafruit_sd implementation.

https://community.st.com/0D50X00009XkgXzSAJ

http://www.st.com/en/evaluation-tools/nucleo-l476rg.html

0690X00000609dfQAA.png

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
John Craven
Senior
November 30, 2017
Posted on November 30, 2017 at 03:57

Until STM adds SPI based SD/FatFS, this may help some user get started.

I stumbled on a Demo project in the ST32CubeMX firmware specifically for Nucleo F3 boards.

The project uses the Adafruit 1.8' TFT shield (which includes SPI SD and a joystick).

Project is located at 'STM32Cube_FW_F3_V1.8.0\Projects\STM32F3XXXX-Nucleo\Demonstrations\Adafruit_LCD_1_8_SD_Joystick'

Project loads a series of images for SD and displays them. 

After way too many frustrating hours of trying to get reliable SDIO/SD/FatFS working, this worked demo worked in a couple minutes with zero hassles.The project is a great template for SPI/SD/FatFS.

Hope it helps others who just want SD/FatFS to be simple!

pinballsp
Associate
December 9, 2017
Posted on December 09, 2017 at 15:17

I am also very interested in SD / SPI / FatFS. I do not understand why it is not available for some time in Cubemx, it is a basic and essential device.

With SDIO I had problems, some time ago I made a design, with Cubemx SDIO / FatFS and it only worked with SD cards of the Kingston brand and another little-known brand that I do not remember now, with the rest of the brands it did not work with any (for example, Sandisk).

So I decided to do the following design with SD for SPI, but for my surprise Cubemx does not support it, and searching for Google there is very little information, and no example ready to try and use.

I hope that soon SD is available for SPI in Cubemx, or if in the meantime someone could provide a practical example with a source that works, I would appreciate it.

Tesla DeLorean
Guru
December 9, 2017
Posted on December 09, 2017 at 15:29

Probably because support is such a headache?

Most Cube releases include an SPI/SD implementation

\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
pinballsp
Associate
December 9, 2017
Posted on December 09, 2017 at 20:26

I saw those sources, but it seems a low level access, read / write data blocks, do not access with Fatfs to read / write files on a FAT / FAT32 SD card. I suppose that the user must implement it in some source file of Fatfs, diskio.c or similar, but at this moment I do not have the knowledge to do it.

I'm looking for, just an SD / SPI example with Fatfs to read and write to files. I thought it would be easier to find something like that, but for now it is impossible.

Taylor Welsh
Associate II
November 22, 2018

i found kiwih's drivers very useful, it's an easy drop in implementation for existing CubeMX projects.

https://github.com/kiwih/cubemx-mmc-sd-card

Taylor Welsh
Associate II
November 22, 2018

i found kiwih's drivers very useful, it's an easy drop in implementation for existing CubeMX projects.

https://github.com/kiwih/cubemx-mmc-sd-card