Skip to main content
Associate
September 29, 2025
Solved

Conflict when using FatFs with SD card (user-defined) and USB disk

  • September 29, 2025
  • 1 reply
  • 256 views

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.


 

Best answer by AScha.3

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/

 

1 reply

AScha.3
AScha.3Best answer
Super User
September 29, 2025

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/

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate
September 29, 2025
HI
I can't understand what is your concept . Can you explain it brief? i already used this drive separation method . So kindly explain what are you trying to say .