This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5528: Filesystem causing issue while copying or deleting the data

Part Number: MSP430F5528
Other Parts Discussed in Thread: MSP430F5529

Hello,

I am using some memory of the flash as a filesystem and storing some data in file system to use it in run time. Following are the cases which are erasing or corrupting the flashed firmware and I need to flash the firmware again.

  1. when I delete the file from the filesystem (happen sometimes).
  2. when I copy the more data in filesystem then its size allocated (happen always).

Please provide solution to prevent this situation for above cases.

Regards,

Rohit

  • This isn't much to go on.

    It sounds as though you're using the MSP430 internal ("program") flash for your file system. What is the origin of the file system code? How are you using it in your application?
  • I have taken reference from TI developer package for filesystem code. Used same as the example given in this package.

    In application, I am storing some files having configurations of slave devices in filesystem and opening, reading the configurations and closing these files.

  • Hello Rohit,

    We'll assume that you're referring to the "M1_FileSystemEmulation" code example for MSC (Mass Storage) device.

    According to Section 8.6 in the USB Developers Package Programmer's Guide, "the application should take care not to allow both itself and the USB host to access the medium at the same time. The host often keeps a cached version of the volume in its own memory that becomes out of sync with the one on the USB device. For this reason, it’s best to avoid accessing the volume from the MCU application while the device is connected to a host over USB." Perhaps this is why you're observing corrupted data.

    For the size limitation issue, the medium can be the MCU's internal memory (very limited storage) or an external device (allows much larger storage) that's accessible via an externally-facing interface (e.g. SPI, I2C, parallel memory, etc.). A popular open-source software solution for the FAT storage is FatFs. Many of the MSC application examples include an MSP430 port of FatFs. The M1 example works around the need for file system software by using “file system emulation”. This approach solves the problem of the application finding files, by restricting where the host can put files. However, it imposes limits on the host with respect to how many files can be stored, and where. Please refer to Chapter 8 in the USB Developers Package Programmer's Guide for more details.

    Regards,

    James

    MSP Customer Applications

  • Yes Jame, I am using the same example code. Thank you for your inputs.

    How can I prevent accessing the filesystem by itself and the medium at the same time?

    For example, In my application after power up, MSP first reads the configurations from the files(from its filesystem) and configures the slave devices. So what I need to do is, I need to prevent the filesystem to detect/communicate to the host machine until configuration of the slave devices are done. Am I right?

    Is there any API which is communicating the host device? So that I can code like only after completion of all the configurations, it come to the picture.

    The detection of the filesystem can be affected by the USB driver of the host system?

    Please let me know your suggestions.

    Thank you.

  • I'm trying to understand what these slave devices are and how they are connected. From what you've described, it sounds like the MSP430F5529 is plugged into the host device via its USB port but I'm confused how the slaved devices are connected. Can you provide a basic block diagram with the various devices and interfaces?

    Rohit Kotak said:

    How can I prevent accessing the filesystem by itself and the medium at the same time?

    For example, In my application after power up, MSP first reads the configurations from the files(from its filesystem) and configures the slave devices. So what I need to do is, I need to prevent the filesystem to detect/communicate to the host machine until configuration of the slave devices are done. Am I right?

    This sounds correct. You'll have to make sure your application code isn't allowing simultaneous access.

    Rohit Kotak said:

    Is there any API which is communicating the host device? So that I can code like only after completion of all the configurations, it come to the picture.

    The detection of the filesystem can be affected by the USB driver of the host system?

    Please let me know your suggestions.

    In the 'main.c' file of the M1_FileSystemEmulation code example, I suspect that you'll want to add your slave configuration code between the following two lines of code: after the file system emulation volume is initialized and before the USB initialization.

    USBMSC_initFSE(); // Initialize the file system emulation volume
    USB_setup(TRUE, TRUE); // Init USB & events; if a host is present, connect

    Regards,

    James

    MSP Customer Applications

  • You can try a couple of things so that you don't access the filesystem via the application once it is configured and synced up to the host.  Maybe you can configure your slave devices before calling the 'USBMSC-initFSE()' function call.  The core and clocks will be up till this point but the filesystem will not have been initialized yet.

    If that does not work then you can try disconnecting and disabling USB while it is active.  So in your code when you want to configure your slave devices (assuming that you are doing this once enumeration has occurred), you can call the following functions in the order listed to disconnect USB:

    USB_disconnect()

    USB_disable()

    Then when you are ready to reconnect to the host you can call the following functions:

    USB_reset()

    USB_connect()

    Regards,

    Arthi

  • Thanks for your responses.

    Following is my observation which may be the root cause of this issue:

    I am using "M1_FileSystemEmulation" example for my development. The only change I made is, I reduced the size of my file system. I did that by reducing the array size of storageVol[] in storageVolume.c file. Currently I have used 0x7900 size of this array(60kb). In default example it is 0xA200(81kb) which covers whole FLASH2 for file system.

    But, In my case the remaining memory of FLASH2 is used as code memory.

    Now, when I use example code M1_FileSystemEmulation, the storage drive of 60kb is generated(in host system) and so I am able to copy maximum 60kb of data in that storage partition and things are working fine. But if I change array size from 0xA200 to 0x7900, then also the storage drive of 60kb is generated(in host system) and if I copy more data than 38kb, firmware crashes.

    To reduce the filesystem size I have changed only array size, am I missing something? what other change is required to export only 38kb to the host system as a storage drive?

    Regards,
    Rohit
  • So when you changed the size of the storageVol array in storageVolume.c file did you also change the length of FLASH2 in lnk_msp430f5529.cmd linker command file? FLASH2 length should be set to 0xF200. Then you also need to designate a section of memory in linker command file for the rest of the FLASH you are using for other things. So maybe you can designate a section called FLASH3 and set its length to 0x5200. Also specify this area in the SECTIONS part of lnk_msp430f5529.cmd file.

    Regards,
    Arthi Bhat
  • Thanks Arthi for your quick response. Above solution worked for me and I am able to use 60kb of the filesystem.

    I used FLASH3 as MYDRIVE in M1.cmd and used FLASH2 and FLASH3  as per your suggestion in linker file.(I updated linker file under MEMORY for FLASH2 and FLASH3. What is expected under SECTIONS for FLASH3?)

    But I observed that I am able to use 60kb always. I changed FLASH3 to 48kb( FLASH2: 0x10000 to 0x18400, FLASH3: 0x18400 to 0x24400 and array size to 0x6000) but still I can use 60kb of flash as filesystem. I able to store up to 60kb of data. Where the data is being stored? How can I export only memory of the FLASH3 as filesystem?

    With no change in "M1_FileSystemEmulation" example, Full FLASH2 is used as filesystem which is of 81kb but here also only 60kb is exported as filesystem.

    Still I think I am missing something.

    Thanks again for above solution..!!

    Regards,

    Rohit

  • Hello Rohit,

    In the default 'lnk_msp430f5529.cmd' linker file, FLASH2 starts at the large memory point (0x10000) which is greater than 64KB and extends to the upper Main memory limit. In 'storageVolume.c', there's a pragma that links the "storageVol" array to "MYDRIVE". In the 'M1.cmd' linker file, "MYDRIVE" is placed in FLASH2. Based on MEMORY and SECTIONS defined in the 'lnk_msp430f5529.cmd' file, code may also be placed in FLASH2 around the array.

    Keep in mind that when you change these files you'll need to rebuild the project(s).

    Regards,

    James

    MSP Customer Applications

**Attention** This is a public forum