AnsweredAssumed Answered

How to edit low level disk i/o for FatFS+SPI?

Question asked by Peter Stein on Apr 8, 2018
Latest reply on Apr 8, 2018 by Clive One

Dear ST community,

I am currently working on being able to control a micro SD card via SPI and FatFS. Now to my initial situation. I have already generated a project via STCubeMX. The project information can be found in the appendix "SDCard.pdf". I am working with a STM32L475VG (BL475-IOT01A). I have already tested the SPI connection with a second controller. This works fine. The SD card has been connected as shown below: (CS -> NSS ?)

Now I have some difficulties with controlling this card (Samsung Micro SD card 16GB SDHC). CubeMX shows the option "user-defined" under FatFs. According to Chan's description, I have to implement the low level disk I / O functions on my own. "The low level device control module is not part of FatFs module and it needs to be provided by implementer" ( chapter Media Access Interface). The manual of ST (UM1721 also in the appendix) gives already first hints, how the functions have to be added:



#if _USE_WRITE == 1
#endif /* _USE_WRITE == 1 */
/*------------------------ Initialize a Drive ---------------------------*/
DSTATUS mynewdisk_initialize (void)
// write your own code here to initialize the drive
Stat &= ~STA_NOINIT;
return Stat;
/*------------------------- Get Disk Status -----------------------------*/
DSTATUS mynewdisk_status (void)
// write your own code here
return Stat;
These are the functions:

  • Initialize a Drive
  • Read Sector (s)
  • Write Sector (s)
  • Get Disk Status
  • Miscellaneous Functions


Now back to my specific questions
- How exactly do I have to implement these functions?
- Does the SD card control with the commands of the SD specification take place here?
- Are there already examples of the STM32L4 series for FatFs with SPI? Unfortunately there are none in the repository of the STM32L4.

I hope you can give me some initial ideas on how to implement this. I have to say that i despair
Many Thanks

Best regards