PIC32 Internl Flash

Flash Storage

fsave
fclear
   

The main storage is the SD Card using the FAT16 file system. Subroutines, programs and data are stored here. In addition to this subroutines can be stored in Flash memory, this can effectively extend the keywords to suit a particular application. This is particularly useful when dealing with microcontrollers as it is not possible to create a keyword for every conceivable register configuration.

The Flash is used to store the firmware and operating system so what is left over is for the user and this is partly controlled by the system constant SYS_FLASH_END. The most information about what is and what is not available is in the plug-in article that makes extensive use of the user Flash.

fsave
fsave <options> [file name]
fsave all
fsave sd file1

Flash Save: is used to save programs to the flash memory area. The ‘all’ option will save the current program in RAM to flash. The ‘sd’ option will save a program stored on the SD Card to flash. See also the keyword 'fexists' which can be used in conjunction with this keyword.

As an example of using this word, a program may rely on functions to exist in Flash so how do you know if there there and what do you do about it if they are not? The technique is to use fexists() to see if the function exists, if not then load it from the SD Card.

if fexists(bvt_init)=0 then
    print "loading main.bas into flash"
    fsave sd main
endif

In the above code snippet the running program 'knows' that bvt_init is a function in a set of 'standard' routines for the application. If it cannot be found then fsave is used to get the program 'main' and load all of its functions into Flash.

fclear
fclear [all][upper][lower]

 

This will erase the Flash memory where specified.

flash diagram

All will clear the cyan and green (two lower) blocks from SYS_FLASH-START to Physical end of Flash. This will be 72 pages of memory on a PIC32 with 512k of Flash. A Page is 4096 bytes, the actual number of pages may vary from release to release.

Upper will clear the area from SYS_FLASH_END to Physical end of Flash and is normally 36 pages, the green block.

Lower will clear the Flash from SYS_FLASH_START to SYS_FLASH_END and will also normally be 36 pages, the cyan block.

See system defaults for more information about SYS_FLASH_START/END. There is also a quantity of information in the Plug-In article.