Connecting a FileX Instance (Ramdisk) to USB MSD Mass storage device

Hi!

I'm trying to create a FAT virtual ram disk and share it between FileX and USB Mass Storage Device.

The concept is: the firmware will create a text file with some settings in it. If the user wants to change them, he'll just have to plug a PC through the USB, open the text file, modify the desired setting and save it.

I've managed to create the ram disk, format it, create a file, write in it, close, open again, read, etc. from the code. Everything works fine.

I've managed to link the MSD device to this ram disk by implementing the callback functions (code pasted below).

The behavior I have now is quite strange:

  • If I plug the PC I see the drive and the file, but the content is wrong. If I wrote "ABC" from the firmware, I see ".   " in the PC.
  • If I modify the file in the PC, e.g. writing "HELLO", I can save and open again successfully from the PC. I see "HELLO" in it.
  • But when after that, I read it from the firmware, I see again the original content "ABC".

It seems that FileX and Windows are "pointing" to different places in the FAT image.

Has someone managed to do something similar? Can you help me and check the code and screenshots below?

 

Thanks!

 

// The USBX Device Mass Storage Media Read Function Callback.
UINT ux_device_msc_media_read (VOID * storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG * media_status)
{


UINT status;
UINT iblock;
SSP_PARAMETER_NOT_USED(storage);
SSP_PARAMETER_NOT_USED(lun);
SSP_PARAMETER_NOT_USED(media_status);

g_sf_block_media_ram0.p_api->read(g_sf_block_media_ram0.p_ctrl,(uint8_t *)data_pointer, lba, number_blocks);

return (UX_SUCCESS);

}

 

// The USBX Device Mass Storage Media Write Function Callback.

UINT ux_device_msc_media_write (VOID * storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG * media_status)
{

UINT iblock;

SSP_PARAMETER_NOT_USED(storage);
SSP_PARAMETER_NOT_USED(lun);
SSP_PARAMETER_NOT_USED(media_status);

g_sf_block_media_ram0.p_api->write(g_sf_block_media_ram0.p_ctrl,(uint8_t *)data_pointer, lba, number_blocks);
return (UX_SUCCESS);

}

 

 

  • Hello -

    I looked at implementing something like this a few years back. Your symptoms sound like what we ran into, so perhaps things are still the same: Two devices cannot share a single FAT. Each device thinks it owns the FAT and will likely be working off of a cached copy in its local RAM. You must ensure that only one device has the medium open at any given time.

    Or, you must implement NFS (Network File Sharing). Perhaps there is a NetX module for that, so it may be straightforward.

    Regards,
    -steve
  • In reply to steve:

    Hi Steve,

    Yes, it seems that both MSD and FileX are accessing to some different RAM areas so your theory of cached copy makes sense.
    My device has ethernet and USB connectivity. My idea is to set up some parameters such as IP, gateway, etc through a text file on the MSD. It sounds simple, I believe it must be somehow feasible with synergy libraries...

    Many thanks for your feedback :)

    Joan