2025-11-20 9:25 PM
I am working on an STM32 + Azure RTOS project where I need to access the same SD card in two different modes:
When the microcontroller accesses the SD card directly, I use FileX with an SDIO/SPI driver.
When the SD card is connected to a PC via USB, I use USB MSC (Mass Storage Class) so that the PC can read/write the card.
Individually, both functions work perfectly:
FileX can read/write SD card when MCU is accessing it
USB MSC works when PC is connected
However, when I try to support both modes simultaneously, the SD card fails to work correctly.
There is no reference example from ST or Microsoft showing how to share the SD card between FileX and USB MSC at runtime.
My main question:
How can I properly share the same SD card between FileX (MCU access) and USB MSC (PC access) in Azure RTOS, ensuring that both do not access the file system at the same time? Is there an official method, mutex mechanism, media lock, or recommended design pattern for this scenario?
2025-11-21 2:26 AM
hello @vaibhavivele
Well, developing the solution might be challenging since there is no direct existing example to base yourself on it.
However, I think it's achievable. The key lies in developing a switching mechanism to interface the SD card without issues.
You will need to create a mechanism that properly and smoothly deinitialize FileX and initialize USB MSC, and vice versa. You can use the following function to deinitialize the MSC:
_ux_device_class_storage_uninitialize(UX_SLAVE_CLASS_COMMAND *command);
To deinitialize the FileX functions, use the following:
fx_media_close(&media);
fx_media_unmount(&media);
fx_stm32_sd_deinit(instance);
You can also check this thread, as it may help you because it discusses a similar topic.
BR
Gyessine
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.