cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 SPI SD Card with FATfs and USB MSC

PLy.1
Associate II

Hi all, I am working on a custom data logging board using STM32L4 and an SD NAND (uSD card in form of an IC). Since the SD chip is a surface-mounted IC (https://www.adafruit.com/product/4899) on the board using SPI and FATfs so I want to implement USB MSC to plug and play with the files when finish logging.

I have seen a few examples and the closest is this STM32 USB MSC (Mass Storage Class) » ControllersTech but the example used SDIO mode and I am using SPI mode with FATfs to write content to SD card (based on this SD card using SPI in STM32 » ControllersTech). Can anyone with experience combine the FATfs SPI SD card with USB MSC to give me a hint for the implementation?

1 ACCEPTED SOLUTION

Accepted Solutions
NW.2
Associate II

Hello PLy,

I'm currently trying out the same thing (except that I use a sd card adapter). I've found this post here https://community.st.com/s/question/0D53W00000hRC0uSAG/modify-usbdstogeifc-to-use-sd-card-trougth-spi and the user said, he had success with it.

I on the other hand, am still struggling with everything, as I don't get the SD-Card displayed on Windows. If you happen to find success, I'd be really happy if you would share your experience.

Kind regards

NW

View solution in original post

7 REPLIES 7

What's going to fit in 8KB ?

The surface mount SD card would use an eMMC in the megabyte or gigabyte realm..

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

Hi Tesla sorry for my incorrect link (first time asking a question). What I mention above is a 512MB spi sd card https://www.adafruit.com/product/4899

There is an SPI based SD Card implementation in this BSP / Driver example

STM32Cube_FW_L4_V1.14.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c

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

Hello PLy,

I'm currently trying out the same thing (except that I use a sd card adapter). I've found this post here https://community.st.com/s/question/0D53W00000hRC0uSAG/modify-usbdstogeifc-to-use-sd-card-trougth-spi and the user said, he had success with it.

I on the other hand, am still struggling with everything, as I don't get the SD-Card displayed on Windows. If you happen to find success, I'd be really happy if you would share your experience.

Kind regards

NW

Thank you for the docs! I have found the answer below.

PLy.1
Associate II

Hello NW,

Thanks a lot for your link! I have been looking for it for days. Turn out it was pretty easy to implement on my project.

I have been able to make it work with the example!! Lucky that I use the same driver in the example from your link, it is from this Tutorial: An SD card over SPI using STM32CubeIDE and FatFS (01001000.xyz)

Now I have the board works either as a data logger or a USB stick 🙂

Are you using the same user_diskio_spi driver as stated in the example?

NW.2
Associate II

Glad that I could help!

I'm not using the user_diskio_spi from this tutorial, but a very similar one. I think I will do everything again from anew following the tutorial in your link. Might be the issue at the end, though I can't get my head around the issue.

Would you mind to share your project? Just the files for the SD Card and usbd_core_if.c are enough I suppose, just in case if I do a mistake with my own implementation for a fast check up? I'm also using stm32l4.

Kind regards

NW