Skip to main content
Associate II
October 9, 2025
Solved

How to use fx_media_format and fx_media_open ?

  • October 9, 2025
  • 1 reply
  • 304 views

Hello,

I am trying to set up FileX with USBX, but my computer recognizes a disk drive but does not see any volume.
Can you help me determine whether I am using the fx_media_format and fx_media_open functions correctly, given that they do not return any errors?

 

 UINT ret = FX_SUCCESS;
 /* USER CODE BEGIN MX_FileX_Init */
 UINT RETT = lx_stm32_nor_custom_driver_initialize(&nor_flash);

 /* USER CODE END MX_FileX_Init */

 /* Initialize FileX. */
 fx_system_initialize();

 /* USER CODE BEGIN MX_FileX_Init 1*/

 /* Format the NOR flash as FAT */
	 status = fx_media_format(&nor_flash_disk,
	 fx_stm32_levelx_nor_driver, // Driver entry
	 (VOID*)&nor_flash, // Device info pointer (VOID*)NOR_CUSTOM_DRIVER_ID
								(UCHAR*)media_memory, // Media buffer pointer
	 sizeof(media_memory), // Media buffer size
	 "NOR_FLASH_DISK", // Volume Name
	 1, // Number of FATs
	 32, // Directory Entries
	 0, // Hidden sectors
								TOTAL_SECTOR_LOGICAL,		 // Total sectors
								SECTOR_SIZE_LOGICAL, // Sector size
	 8, // Sectors per cluster
	 1, // Heads
	 1); // Sectors per track
 /* Check if the format status */
 if (status != FX_SUCCESS)
 {
 Error_Handler();
 }

 /* Open the SPI NOR Flash disk driver. */
 //status = fx_media_open(&nor_flash_disk, "FX_LX_NOR_DISK", fx_stm32_levelx_nor_driver,(VOID*)NOR_CUSTOM_DRIVER_ID , media_memory, sizeof(media_memory));
 status = fx_media_open(&nor_flash_disk, "FX_LX_NOR_DISK", fx_stm32_levelx_nor_driver,(VOID*)NOR_CUSTOM_DRIVER_ID , media_buffer, sizeof(media_buffer));
 /* Check the media open status. */
 if (status != FX_SUCCESS)
 {
 Error_Handler();
 }

 

For Device info pointer, should i use (VOID*)&nor_flash or (VOID*)NOR_CUSTOM_DRIVER_ID ?
Can the volume name and media name be different ?

 

Best answer by T_Hamdi

Hello @RemiNao 

You must use the same pointer (either (VOID)&nor_flash* or (VOID)NOR_CUSTOM_DRIVER_ID*) in both fx_media_format  and fx_media_open because the driver requires a consistent device context to properly access and manage the media. Using different pointers can result in the volume not being recognized correctly.

 

For Device info pointer, should i use (VOID*)&nor_flash or (VOID*)NOR_CUSTOM_DRIVER_ID ?

If you are using an official ST driver (such as LevelX for NOR QSPI), you should pass (VOID)NOR_CUSTOM_DRIVER_ID* because the driver uses this ID internally to manage the device. If you are using a custom driver or your own device management, you should pass (VOID)&nor_flash*, which is a pointer to the structure holding the hardware context. its correcte .

Can the volume name and media name be different ?

yes, the volume name and the media name can be different.


you can find a relevant example here to help you in your application here: 

ST FileX NOR Flash Write/Read Example 

 

 

 

1 reply

T_Hamdi
T_HamdiBest answer
ST Employee
October 13, 2025

Hello @RemiNao 

You must use the same pointer (either (VOID)&nor_flash* or (VOID)NOR_CUSTOM_DRIVER_ID*) in both fx_media_format  and fx_media_open because the driver requires a consistent device context to properly access and manage the media. Using different pointers can result in the volume not being recognized correctly.

 

For Device info pointer, should i use (VOID*)&nor_flash or (VOID*)NOR_CUSTOM_DRIVER_ID ?

If you are using an official ST driver (such as LevelX for NOR QSPI), you should pass (VOID)NOR_CUSTOM_DRIVER_ID* because the driver uses this ID internally to manage the device. If you are using a custom driver or your own device management, you should pass (VOID)&nor_flash*, which is a pointer to the structure holding the hardware context. its correcte .

Can the volume name and media name be different ?

yes, the volume name and the media name can be different.


you can find a relevant example here to help you in your application here: 

ST FileX NOR Flash Write/Read Example 

 

 

 

"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"