Skip to main content
PLy.1
Associate
Dec 5, 2022 3:50 PM UTC
Solved

STM32L4 SPI SD Card with FATfs and USB MSC

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?

This topic has been closed for replies.
NW.2
NW.2Best answer
Associate II
Dec 6, 2022 10:27 AM UTC

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

7 replies

Tesla DeLorean
Guru
Dec 5, 2022 4:47 PM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
PLy.1
PLy.1Author
Associate
Dec 5, 2022 9:10 PM UTC

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

​

NW.2
NW.2Best answer
Associate II
Dec 6, 2022 10:27 AM UTC

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

PLy.1
PLy.1Author
Associate
Dec 6, 2022 11:24 AM UTC

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
Dec 6, 2022 12:46 PM UTC

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