• AVR Freaks

Hot!Internal Flash MSD USB Demo with a PIC18F47J53 PIM - how to work with files?

Author
AlexVelchev
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2018/08/27 00:54:37
  • Location: 0
  • Status: offline
2019/09/19 07:12:03 (permalink)
0

Internal Flash MSD USB Demo with a PIC18F47J53 PIM - how to work with files?

Hi all, 
Long time user, first time poster here. 

I'm running the latest Microchip Libraries for Applications (MLA) - 2018_11_26 USB Device MSD Demo and I'm trying to wrap my head around a couple of things. 

First of all - how do I create, open and read files in the internal flash? I consulted the "help_mla_fileio" manual, but it seems all the functions for working with files are for SD Card usage. Furthermore, even though I see the definitions in the "fileio.h", when I try to call for example 
FILEIO_Initialize();
 , the compiler fails to build it. 

So, for example - how should I go about if I want to upload a file to the MSD and then read from it? 
Or - if I want to record incoming serial data to a file?

Any hints would be very appreciated!

I'm using latest MLA with the PIC18F47J53 PIM. MPLAB 5.25 and XC 1.40. 

Thanks!
#1

3 Replies Related Threads

    mbrowning
    USNA79
    • Total Posts : 1535
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: Internal Flash MSD USB Demo with a PIC18F47J53 PIM - how to work with files? 2019/09/19 09:06:41 (permalink)
    +1 (1)
    Do you realize that writing/erasing internal flash blocks code operation during the write/erase cycle? That's 2.8ms per 64 byte write, and 33ms for 1024 block erase. And only 10K erase/write cycles is guaranteed per cell.
     
    Trying to create a file system using internal memory seems a poor design decision, and doesn't seem possible while doing real-time processing (like running the USB stack).

    Go Navy! Beat Army!
    #2
    AlexVelchev
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2018/08/27 00:54:37
    • Location: 0
    • Status: offline
    Re: Internal Flash MSD USB Demo with a PIC18F47J53 PIM - how to work with files? 2019/09/20 02:22:22 (permalink)
    0
    mbrowning
    Do you realize that writing/erasing internal flash blocks code operation during the write/erase cycle? That's 2.8ms per 64 byte write, and 33ms for 1024 block erase. And only 10K erase/write cycles is guaranteed per cell.
     
    Trying to create a file system using internal memory seems a poor design decision, and doesn't seem possible while doing real-time processing (like running the USB stack).



    Hi, thanks for the reply. 

    Obviously it's not a great design choice, but I'm more trying to wrap my head around how it works, rather than make a solid design effort. Given the devtools I have at my disposal (PICDEM PIC18 Explorer and PIC18F47J53 PIM) I can't really easily interface to an SD Card. I was thinking to use an external Flash (SST) eventually, but I want to be comfortable with the API before I write any driver code. (Unless I can easily modify the existing SD-SPI driver to work with a Serial Flash). 

    Regardless, I should be able to work with files in the Internal Flash. Suppose I want to upload a file to the MSD and then the MCU reads it and performs some task etc. Common sense dictates this *should* be possible, otherwise it seems the demo is entirely unusable except to give an overview of the USB stack involved. 



    #3
    AlexVelchev
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2018/08/27 00:54:37
    • Location: 0
    • Status: offline
    Re: Internal Flash MSD USB Demo with a PIC18F47J53 PIM - how to work with files? 2019/10/15 00:35:32 (permalink)
    0
    After digging around, I'm finally able to answer my own question in case anybody ever needs this info. 

    First of all, the user needs to declare an instance of the FILEIO_DRIVE_CONFIG_STRUCT and tie it to the functions that interface to the Internal Flash (it's the same for using the FILEIO library with an SD card or a custom media). 


    const FILEIO_DRIVE_CONFIG myDriveConfig = {
        (FILEIO_DRIVER_IOInitialize)&FILEIO_InternalFlash_InitIO, // I/O Initialization function
        (FILEIO_DRIVER_MediaDetect) &FILEIO_InternalFlash_MediaDetect, // Media Detection function
        (FILEIO_DRIVER_MediaInitialize) &FILEIO_InternalFlash_MediaInitialize, // Media Initialization function
        (FILEIO_DRIVER_MediaDeinitialize) &FILEIO_InternalFlash_MediaInitialize, // Media Deinitialization function.
        (FILEIO_DRIVER_SectorRead) &FILEIO_InternalFlash_SectorRead, // Function to read a sector of the media.
        (FILEIO_DRIVER_SectorWrite) &FILEIO_InternalFlash_SectorWrite, // Function to write a sector of the media.
        (FILEIO_DRIVER_WriteProtectStateGet) &FILEIO_InternalFlash_WriteProtectStateGet // Function to determine if the media is write-protected.
    };


    Then somewhere in the code, you have to Initialize the FILEIO library and mount the device. 

    FILEIO_Initialize();
    err = FILEIO_DriveMount('G', &myDriveConfig, &myDriveConfig);
    err = FILEIO_Open(&myFile, "FILE.TXT", FILEIO_OPEN_READ);

     
    In the FILEIO_DriveMount function the last parameter is the mediaParameters struct. This depends on the media you are using, it is declared in code for the SD demo, but doesn't exist in the InternalFlash demo. This was a piece of code that was seriously bothering me, because it wasn't well documented. I couldn't get it to build with void* as an argument, so I just used the same myDriveConfig struct as a dummy. 



    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5