Skip to main content
Visitor II
November 21, 2025
Question

How to Share SD Card Between FileX and USB MSC in Azure RTOS

  • November 21, 2025
  • 2 replies
  • 150 views

I am working on an STM32 + Azure RTOS project where I need to access the same SD card in two different modes:

  1. When the microcontroller accesses the SD card directly, I use FileX with an SDIO/SPI driver.

  2. 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?

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    November 21, 2025

    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

    Technical Moderator
    December 15, 2025

    hello @vaibhavivele 
    just asking about any feedback, Did the reply provided help you solve your problem?
    Gyessine