2026-02-20 2:37 AM - last edited on 2026-02-20 3:05 AM by mƎALLEm
Hi, i want to use STM32U385RG (NUCLEO-U385RG-Q) to read and write files on SD using SDMMC (1 bit mode) interface, with FileX in standalone mode. I've successfully tested Fx_File_Edit_Standalone (SRAM) example and SD_ReadWrite_DMA (1 bit mode) example.
Following my MX_FileX_Process function:
VOID MX_FileX_Process(VOID)
{
UINT status;
ULONG bytes_read;
CHAR read_buffer[32];
CHAR data[] = "This is FileX working on STM32";
/* Start application */
printf("FileX Edit Standalone Application Start.\n");
/* Open the sram_disk driver. */
status = fx_media_open(&sram_disk, "STM32_SDIO_DISK", fx_stm32_sd_driver, (VOID *)FX_NULL, (VOID *) fx_sd_media_memory, sizeof(fx_sd_media_memory));
/* Check the media open status. */
if (status != FX_SUCCESS)
{
Error_Handler();
}
printf("SD card opened.\n");
/* Create a file called STM32.TXT in the root directory. */
status = fx_file_create(&sram_disk, "STM32.TXT");
/* Check the create status. */
if (status != FX_SUCCESS)
{
/* Check for an already created status. This is expected on the
second pass of this loop! */
if (status != FX_ALREADY_CREATED)
{
/* Create error, call error handler. */
Error_Handler();
}
}
/* Open the test file. */
status = fx_file_open(&sram_disk, &fx_file, "STM32.TXT", FX_OPEN_FOR_WRITE);
/* Check the file open status. */
if (status != FX_SUCCESS)
{
/* Error opening file, call error handler. */
Error_Handler();
}
/* Seek to the beginning of the test file. */
status = fx_file_seek(&fx_file, 0);
/* Check the file seek status. */
if (status != FX_SUCCESS)
{
/* Error performing file seek, call error handler. */
Error_Handler();
}
printf("Writing data into the file. \n");
/* Write a string to the test file. */
status = fx_file_write(&fx_file, data, sizeof(data));
/* Check the file write status. */
if (status != FX_SUCCESS)
{
/* Error writing to a file, call error handler. */
Error_Handler();
}
/* Close the test file. */
status = fx_file_close(&fx_file);
/* Check the file close status. */
if (status != FX_SUCCESS)
{
/* Error closing the file, call error handler. */
Error_Handler();
}
status = fx_media_flush(&sram_disk);
/* Check the media flush status. */
if (status != FX_SUCCESS)
{
/* Error closing the file, call error handler. */
Error_Handler();
}
/* Open the test file. */
status = fx_file_open(&sram_disk, &fx_file, "STM32.TXT", FX_OPEN_FOR_READ);
/* Check the file open status. */
if (status != FX_SUCCESS)
{
/* Error opening file, call error handler. */
Error_Handler();
}
/* Seek to the beginning of the test file. */
status = fx_file_seek(&fx_file, 0);
/* Check the file seek status. */
if (status != FX_SUCCESS)
{
/* Error performing file seek, call error handler. */
Error_Handler();
}
/* Read the first 28 bytes of the test file. */
status = fx_file_read(&fx_file, read_buffer, sizeof(data), &bytes_read);
/* Check the file read status. */
if ((status != FX_SUCCESS) || (bytes_read != sizeof(data)))
{
/* Error reading file, call error handler. */
Error_Handler();
}
/* Close the test file. */
status = fx_file_close(&fx_file);
/* Check the file close status. */
if (status != FX_SUCCESS)
{
/* Error closing the file, call error handler. */
Error_Handler();
}
/* Close the media. */
status = fx_media_close(&sram_disk);
/* Check the media close status. */
if (status != FX_SUCCESS)
{
/* Error closing the media, call error handler. */
Error_Handler();
}
printf("Data successfully written.\n");
/* Infinite loop */
while (1)
{
/* Toggle GREEN LED to indicate status */
HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);
HAL_Delay(500);
}
}
The code fail on fx_media_open returning Error_Handler after 10 seconds timeout.
What is the problem?
Thank you
2026-02-24 1:47 AM
Hello @alessandromauro
Before calling fx_media_open(), try formatting the SD card with fx_media_format(). This ensures the card has a valid FileX/FAT file system and can prevent the timeout you’re seeing if the media is unformatted or corrupted.
2026-02-24 7:32 AM
Hello .@Saket_Om, thank you for the answer I formatted the SD card (and checked it again) before connecting them with nucleo, the result is the same.
Comparaing Fx_File_Edit_Standalone (SDMMC1) example for STM32U575I-EV with Fx_File_Edit_Standalone (SRAM) exaple for NUCLEO-U385RG-Q I've noticed that in the first example, I can enable the interrupt for SDMMC1 (NVIC Settings tab) while in the second example the NVIC Settings tab doesn't exist in SDMMC1 configuration. Could this be the problem?
Thank you.
2026-03-06 5:39 AM
Hello @alessandromauro ,
During debugging, could you please share the exact return status from fx_media_open() (the error value) before Error_Handler is called?
Regards,
Maher