2025-09-29 4:35 AM - last edited on 2025-09-29 4:40 AM by mƎALLEm
Hello, I am working on a project that uses both SD card and USB interface with FatFs.
For SD card, I am using FatFs User Defined mode.
For USB, I am using FatFs USB Disk mode.
The issue I am facing is:
When I call f_mount() for the SD card using disk_open("0:"); and later try to use USB disk, there is a conflict/collision with f_mount.
It looks like the two FatFs configurations are interfering with each other.
My question:
How can I properly configure FatFs to use both SD card (user defined) and USB disk together without conflicts?
Is there a way to isolate or separately handle f_mount for each disk (e.g., "0:" for SD and "1:" for USB) so that they don’t collide?
Environment:
MCU: STM32H750VBT6
Middleware: FatFs + USB Host MSC
IDE: STM32CubeIDE
Any suggestions or working examples would be very helpful.
2025-09-29 5:07 AM - edited 2025-09-29 5:23 AM
Hi,
>Is there a way to isolate or separately handle f_mount for each disk (e.g., "0:" for SD and "1:" for USB)
Right, as on any PC , the drives have to get different names.
I use on my audio player 2 SDcards and USBstick , with fatfs.
And to manage the devices ->
extern char SDPath[], USBHPath[]; /* SD disk logical drive path */
char SDfile[255], USBfile[255], path[255], filepath[255]; // SD disk file
FATFS SDfs, SD2fs, USBfs; // file system
mount sd is easy:
/*## Register the file system object to the FatFs module ##############*/
fresult = f_mount(&SDfs, (TCHAR const*)SDPath, 1); // SD card mount
the USB is more tricky ... :)
if(Appli_state == APPLICATION_READY && usb_status == 0) // USB stick ready->
{
printf("USB stick -> mount \n"); // show start
retUSBH = f_mount(&USBfs, (TCHAR const*)USBHPath, 1); // mount...?
if (retUSBH==0) usb_status = 1; // mount ok. // mounted ok.
}
...as you have to wait for app_ready-state and then mount, but only once (so i made my usb_status global variable, to set the current state ; and reset it, if stick is unplugged etc.)
device gets 0: , 1: ...
-> read Mr. Chan's doku of fatfs. https://elm-chan.org/fsw/ff/
2025-09-29 5:27 AM