Skip to main content
Explorer
December 5, 2022
Solved

STM32L4 SPI SD Card with FATfs and USB MSC

  • December 5, 2022
  • 2 replies
  • 6014 views

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.
    Best answer by NW.2

    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

    2 replies

    Graduate II
    December 5, 2022

    What's going to fit in 8KB ?

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

    PLy.1Author
    Explorer
    December 5, 2022

    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.2Answer
    Explorer
    December 6, 2022

    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.1Author
    Explorer
    December 6, 2022

    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?

    Explorer
    December 6, 2022

    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