2018-04-08 11:55 AM
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
http://elm-chan.org/fsw/ff/00index_e.html
).The manual of ST (UM1721 also in the appendix) gives already first hints, how the functions have to be added:
[...]
&sharpif _USE_WRITE == 1
mynewdisk_write,
&sharpendif /* _USE_WRITE == 1 */
/*------------------------ Initialize a Drive ---------------------------*/
DSTATUS mynewdisk_initialize (void)
{
Stat = STA_NOINIT;
// write your own code here to initialize the drive
Stat &= ~STA_NOINIT;
return Stat;
}
/*------------------------- Get Disk Status -----------------------------*/
DSTATUS mynewdisk_status (void)
{
Stat = STA_NOINIT;
// 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
#fat #fat_fs #sd-card- #sd-acces #spi-communication #stm32l4-spiSolved! Go to Solution.
2018-04-08 12:12 PM
The DISKIO.C layer of FATFS expects you to provide routines to read/write multiple blocks from the underlying block storage device (HD, USBSTOR/MSC, SDCard, etc). Usually the functionality for the specific interface is managed below this.
An SPI layer supporting SD, SDHC and SDXC cards can be found here
STM32Cube_FW_L4_V1.11.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c
STM32Cube_FW_L4_V1.11.0\Projects\NUCLEO-L496ZG\Demonstrations\Adafruit_LCD_1_8_SD_Joystick\Src\sd_diskio.c
There is a multi-sector bug in this code, but it is fixable. The bigger problem is the inherent slowness of such implementations.
https://community.st.com/0D50X00009XkgXzSAJ
For an 16 GB SDHC card the SD/MMC code would need to support the appropriate command set, so other web examples of this may not do that. The adafruit code should be good for cards >200GB
2018-04-08 12:12 PM
The DISKIO.C layer of FATFS expects you to provide routines to read/write multiple blocks from the underlying block storage device (HD, USBSTOR/MSC, SDCard, etc). Usually the functionality for the specific interface is managed below this.
An SPI layer supporting SD, SDHC and SDXC cards can be found here
STM32Cube_FW_L4_V1.11.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c
STM32Cube_FW_L4_V1.11.0\Projects\NUCLEO-L496ZG\Demonstrations\Adafruit_LCD_1_8_SD_Joystick\Src\sd_diskio.c
There is a multi-sector bug in this code, but it is fixable. The bigger problem is the inherent slowness of such implementations.
https://community.st.com/0D50X00009XkgXzSAJ
For an 16 GB SDHC card the SD/MMC code would need to support the appropriate command set, so other web examples of this may not do that. The adafruit code should be good for cards >200GB