cancel
Showing results for 
Search instead for 
Did you mean: 

Using FatFs to access SD Card and USB Mass Storage Device

Andrew Hazelton
Associate III
Posted on October 18, 2017 at 05:57

Compiler:           IAR Workbench v8.11.3

Middleware�s:   FatFs & STM32_USB_Host

Hardware:          STM32746G Discovery Board

HAL Version:      V1.8.0

Demo Projects:   C:\STM32Cube_FW_F7_V1.8.0\Projects\STM32746G-Discovery\Applications\USB_Host\MSC_Standalone  AND  C:\STM32Cube_FW_F7_V1.8.0\Projects\STM32746G-Discovery\Applications\FatFs\FatFs_uSD

Project:

I have merged together the below two STM32Cube_FW_F7_V1.8.0 Discovery Applications into the one project (attached):

1)  MSC_

Standalone � USB host mass storage class demo project.

2)  FatFs_uSD � File system using micro SD card.

My goal is to use the FatFs to open both the USB memory stick and the micro SD card. Then to transfer a .txt file from the USB memory stick to the micro SD card.

Problem:

All of the functions f_open(), f_read(), f_write() and f_close() will only work on the first storage device (SD or USB) that you use the FATFS_LinkDriver() and f_mount() on. How do you tell the hardware drivers disk_read() and disk_write() which storage device (SD or USB) you intend to use when you call the f_open() function?

If you have already used the FATFS_LinkDriver() and f_mount() function to link the micro SD card, do you then have to use the FATFS_UnLinkDriver() function to unlink the hardware SD drivers before you can then link the USB Host drivers?

I have already set �_VOLUMES   2� in ffconf.h

Attachment: 

Please un-zip the attached project into the below directory:

C:\STM32Cube_FW_F7_V1.8.0\Projects\STM32746G-Discovery\Applications\USB_Host

#fatfs #usb-mass-storage-device #sd-card
1 ACCEPTED SOLUTION

Accepted Solutions
bbee
Associate III
Posted on October 19, 2017 at 07:34

See

http://elm-chan.org/fsw/ff/doc/filename.html

 

You can pass the drive number in the path name or change the default drive with f_chdrive.

When you use both, a SD drive and a USB drive then you have to link each drive to its driver using FATFS_LinkDriver. In that case you should have two Diskio_drvTypeDef instances (one for SD and one for USB) and it is possible to access both drives without to use unlink and link again.

View solution in original post

5 REPLIES 5
bbee
Associate III
Posted on October 19, 2017 at 07:34

See

http://elm-chan.org/fsw/ff/doc/filename.html

 

You can pass the drive number in the path name or change the default drive with f_chdrive.

When you use both, a SD drive and a USB drive then you have to link each drive to its driver using FATFS_LinkDriver. In that case you should have two Diskio_drvTypeDef instances (one for SD and one for USB) and it is possible to access both drives without to use unlink and link again.

Andrew Hazelton
Associate III
Posted on October 20, 2017 at 13:19

Hi ra hummel.

Thanks for that I got it working. I re-attached the working project above if anyone wants to try it.

1)  Insert USB memory stick with a file called 'tfile.txt'. Make sure it has lots of text.

2)  Insert micro SD card into the board.

Posted on December 07, 2017 at 12:01

Hi Andrew, I have test your code and it work well but when I tried to merge it with my own application, it doesn't work. So I am wondering what you have modified in the librairies to get it work?

Thanks

Posted on December 08, 2017 at 12:55

Hi Gregoire,

I have not made any changes to any of the libraries. What hardware are you using?

Can you share working code​