cancel
Showing results for 
Search instead for 
Did you mean: 

initialize FatFS with SPI In stm32cubeMX

sashaa
Associate II
Posted on March 10, 2015 at 21:34

Hi,

I want to read/write data to SD card via SPI. is it possible to initialize the FatFS module to work with SPI interface in cubeMX tool?

The SD card option in the FatFS middleware is available only when I am enabling the SDIO peripheral.

I am using STM32F4-DISCOVERY board and STM32CubeMX ver. 4.6

Thanks

#stm32cubemx #stm32 #spi #fatfs #sd #sdio
9 REPLIES 9
Mnemocron
Associate III
Posted on June 09, 2016 at 07:37

Exatly what I've been up to the last week. And I haven't figured it out yet.

If anyone knows how to interface SPI SD cards with STM32, please answer.

I am using STM32F4-Discovery (STM32F407), Keil uVision 5 and STM32CubeMX 1.0 (4.12.0).

Till date, I tried:

- translating the Arduino SD libraries (C++) to work with HAL_SPI_x() funtions

  gave up this one, because everything is deeply wired to the Arduino environment

- implementing the ElmChan FatFs library on my own

  didn't work, or at least it threw no errors, but still didn't work

- implementing the TM libraries from http://stm32f4-discovery.net/

  I don't get how to implement these correctly, ended up like the one above

  or with several L6218e errors from the linker

slimen
Senior
Posted on June 09, 2016 at 11:06

Hi,

I suggest you to use the last version of CubeMx v4.15 andhave a look to this example using most of the features offered by FatFs toconfigure a microSD drive:

STM32Cube_FW_F1_V1.4.0\Projects\STM3210C_EVAL\Applications\FatFs\FatFs_uSD

You'll still have to own the integration with this application which can help you as an implementation example and get inspiration to achieve you goal.

You can refer to this

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a//my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F4%20Discovery%20-%20interfacing%20SD%20card%20with%20SPI%20%20FatFS&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3C...

it may be helpful for you.

Regards

Taylor Welsh
Associate II

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

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

MWATS
Associate II

This guys works for SPI, integrated into user io..

Uses SPI in place of SDIO.

https://github.com/eleciawhite/STM32Cube/blob/master/STM32Cube_FW_F3_V1.3.0/Drivers/BSP/Adafruit_Shield/stm32_adafruit_sd.c

or in a project for L4 nucleo as example

https://bitbucket.org/mkwats/stm32_sd_spi/src/master/

Hi, new to the forums. Maybe someone can help me here. I am also new to ST/CubeMX. I have a quick little project I am trying to put togther, and thought I could just uses this cubemx-mmc-sd-card you mention, but I don't understand how I take it from a dev board, to a different MCU "easily". CubeMX is not intuative on this. If I go back to board/mcu selection it's restarting the project. Do I import? I did that, but resulted in import errors, and generating code there is a ton missing (of course, it also crashed the first try so...). Anyway, any help is appreciated. I just need to use SPI to an sd card in the most basic way. I was hoping to use CubeMX to generate the guts, then read/write some files. I have some GPIO interrupts etc. already running that I need to trigger on.

Maybe I am better of just doing it from scratch?

Thanks in advance.

Jay

The HAL has Nucleo based SPI examples, using the AdaFruit shield code in the HAL/BSP code trees.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks. I have found some things. The issue I am having is I am not using a dev board. We created a board and plopped an F030C8 on it. Maybe that's not the best processor for this application. Anyway, using cubeMX seemed like the way to go, but I can't seem to figure out the "easy" transition to my MCU from within CubeMX. I am going to try it from scratch and use the examples a reference only.

Thanks.

Send a schematic and code... hard to decipher where the issue is. Dev board vs chip makes no difference in cubemx. Do you have the chip working at all, ie can flash a led?