cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMx fatfs sd via SPI

glukxy
Associate
Posted on October 29, 2016 at 10:41

Hi,

I'm trying to use CubeMX to work with the SD through SPI. In the search of this forum I found a lot of answers on how to work with SD for SPI. Unfortunately I do not find them useful. It would be ideal to find an example of implementation user_defined.c, user_defined.h. If everything is so obvious why I have never seen simple example of implementation? I use STM32L151, therefore do not offer SDIO.

Is

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a//my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/user_diskio.c%20and%20diskio.c&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=275

code correct?

#no-hablo-hal #spi-sd-cubemx-hal-fatfs-stm32l1x
4 REPLIES 4
Posted on October 29, 2016 at 18:45

There is a reason a lot of us don't use HAL/CubeMX nor support it here...

There seems to be an endless parade of people having problems with SD Cards using SPI/SDIO. It is a complicated protocol, and a lot of people have zero competence in the mass storage and file system space, so if it doesn't work out-of-the-box it is going to be very hard to fix/debug. I would not trust the code provided by h.rick, he copied it from someone else, it didn't work for him, and he didn't have the skills to fix it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 29, 2016 at 18:56

One of dozens of threads started on the topic.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/SD%20can%27t%20read%20write&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/AllItems.aspx&currentviews=17]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM32Java%2fSD%20can%27t%20read%20write&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&TopicsView=https%3A%2F%2Fmy%2Est%2Ecom%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Java%2FAllItems%2Easpx¤tviews=17

You'd also want to look at the code and SPI connectivity you have on the board now. Is the connector wired up properly? Can you review the data with a scope or analyzer? Are you getting reasonable responses via SPI and the card?

There are a whole array of reasons why things fail, and it's hard to guess the specific reason from the level of information provided.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Geoffrey1
Associate III
Posted on November 09, 2016 at 13:25

SD over SPI is challenging.  Here are some examples for the F3 using cubeMX including

FAT/SD over SPI, and one allowing the host to access a spi connected SD card over USB.

https://github.com/geoffreymbrown/stm32cubef3-examples

I won't defend the code quality -- these are just examples I threw together when trying to learn how to use CubeMX and the new HAL libraries -- but they'll at least give you a starting point.

I do use traditional GCC/make/binutils, so some of the extra stuff is just to make this work with CubeMX generated projects.

In my experience, you need to be proficient with GDB and have access to a logic analyzer

(the Saleae Logic works well), in order to get SD over SPI working.

Geoffrey

Posted on November 10, 2016 at 06:26

For the Nucleo-F091rc and the Adafruit shield ID802 exist inside the CubeMX code examples from Adafruit how to use SDcards with SPI.

See UM1787 / en.DM00122017.pdf for more details.

https://www.adafruit.com/products/802

Did not try it by myself, because the Adafruit shield is somehow expensive and the display is really small. But for the SDcard it may be a solution. Using SDcards with SDIO / SDMMC with CubeMX is very easy (with Nucleo-144 STM32F746) so i did not spend any time for the SPI mode.

Best regards,

Markus.