cancel
Showing results for 
Search instead for 
Did you mean: 

USBX device storage class + filex

CButz.1
Associate III

I want to make a Filesystem with FileX and use the usbx device storage class to get access to the files. I successfully created a FileX filesystem on ram. I found the examples Ux_Device_MSC, this uses the sd card for the file system.

In ux_device_msc.c i have to implement the Status Read and Write commands comming from usb to acces my filesystem.

/* Format the NOR flash as FAT */
	status =  fx_media_format(&sram_disk,
							  fx_stm32_sram_driver,   		// Driver entry
							  (VOID*)LX_SRAM_DRIVER_ID, 	// Device info pointer
							  (UCHAR*)media_memory,         // Media buffer pointer
							  sizeof(media_memory),         // Media buffer size
							  "SRAM DISK",             		// Volume Name
							  1,                            // Number of FATs
							  32,                           // Directory Entries
							  0,                            // Hidden sectors
							  FX_SRAM_DISK_SIZE/512,      	// Total sectors
							  512,                          // Sector size
							  8,                            // Sectors per cluster
							  1,                            // Heads
							  1);                           // Sectors per track

Currently im using this for read and write, but windows tells me i have to format it, but it should already be a filesystem and second formatting fails.

UINT STORAGE_Read(VOID *storage, ULONG lun, UCHAR *data_pointer,
                  ULONG number_blocks, ULONG lba, ULONG *media_status)
{
  UINT status = 0U;
 
  sram_disk.fx_media_driver_request = FX_DRIVER_READ;
  sram_disk.fx_media_driver_logical_sector = lba;
  sram_disk.fx_media_driver_sectors = number_blocks;
 
  fx_stm32_sram_driver(&sram_disk);
 
  memcpy(data_pointer, sram_disk.fx_media_driver_buffer, number_blocks);
 
  return (status);
}
 
UINT STORAGE_Write(VOID *storage, ULONG lun, UCHAR *data_pointer,
                   ULONG number_blocks, ULONG lba, ULONG *media_status)
{
  UINT status = 0U;
 
  sram_disk.fx_media_driver_request = FX_DRIVER_WRITE;
  sram_disk.fx_media_driver_logical_sector = lba;
  sram_disk.fx_media_driver_sectors = number_blocks;
 
  fx_stm32_sram_driver(&sram_disk);
 
  memcpy(sram_disk.fx_media_driver_buffer, data_pointer, number_blocks);
 
  return (status);
}

1 ACCEPTED SOLUTION

Accepted Solutions
mohamed.ayed
ST Employee

Hi @CButz.1​ ,

You can refer to usbx_device_mass_storage sample IAR / STM32CubeIDE wihch show USBX Device Mass Storage with SRAM.

Regards.

View solution in original post

1 REPLY 1
mohamed.ayed
ST Employee

Hi @CButz.1​ ,

You can refer to usbx_device_mass_storage sample IAR / STM32CubeIDE wihch show USBX Device Mass Storage with SRAM.

Regards.