cancel
Showing results for 
Search instead for 
Did you mean: 

STM32N6 – USB Mass Storage over SDMMC2: Drive appears in Windows but cannot be opened

Grace_04
Associate II

Hello ST Community,

I am working on an STM32N6-based board and trying to expose an onboard SD card (SDMMC2) as a USB Mass Storage (MSC) device using FileX and ThreadX.

The intended behavior is:
When a USB Type-C cable is connected to a Windows PC, the SD card should appear as a USB removable drive with full read/write access.

Hardware / Software Setup
 MCU: STM32N6

SD interface: SDMMC2 (4-bit, polling mode)

USB: USB OTG HS (Device mode, MSC class)

RTOS: Azure RTOS ThreadX

File system: FileX

Toolchain: STM32CubeIDE

OS on host: Windows 10/11
#if (FX_STM32_SD_DMA_API == 1)  
/* the SD DMA requires a 4-byte aligned buffers */
unaligned_buffer = (UINT)(media_ptr->fx_media_driver_buffer) & 0x3;
#endif

unaligned_buffer always evaluates to 0 because the buffer is aligned, but this does not resolve the issue.

Specific Debug Observation (FX_DRIVER_BOOT_READ)
During debugging, I observed that FileX always enters FX_DRIVER_BOOT_READ, and the following code path is always executed:

case FX_DRIVER_BOOT_READ:
{ /* the boot sector is the sector zero */
status = sd_read_data(media_ptr, 0, media_ptr->fx_media_driver_sectors, unaligned_buffer);
if (status != FX_SUCCESS)
{
media_ptr->fx_media_driver_status = status; break;
}
This condition is always satisfied, and FileX does not appear to progress normally to other filesystem states.
Even though the SD read function is called, Windows is still unable to open or read the filesystem. 

2 REPLIES 2
T_Hamdi
ST Employee

hello @Grace_04 

For your STM32N6 USB MSC with SD card project, please refer to the official STM32CubeN6 example here: Ux_Device_MSC_STM32CUBEN6 .

This example fully demonstrates SDMMC, FileX, and USB MSC integration and is a reliable reference to resolve your  issue.

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.
Hamdi Teyeb
Grace_04
Associate II

Thank you for sharing the reference example.

We have already gone through the Ux_Device_MSC_STM32CUBEN6 example in detail and are following the same approach for SDMMC + FileX + USB MSC integration. Our implementation is largely based on this example code.

However, even after aligning our code with the reference project, we are still facing the issue where the USB drive is detected by Windows but cannot be opened. The drive appears correctly, but access (open/copy/paste) fails.