FUNCTION WRITE ( FlashAddr, Source, subsectorsize )
Source = arrayname | stringname
subsectorsize = 256* | 512 | 1024 | 2048 | 4096 | 8192* in bytes
WRITE copies data into the Flash memory space shared with the user code Flash space. Generally space above 0x4000 is available, but there is no protection for writing over your program. Flash is organized in sectors, 4K in ARMmite, ARMexpressLITE, 8K sectors in the ARMexpress, the ARMweb has a mix of 4K and 32K sectors. (details in the NXP User Manual).
For firmware versions 8.00 to 8.35, you must disable INTERRUPTs before calling WRITE and reenable them after the call.
Writing consists of erasing the whole sector and then writing a subsector or all.
Erases will erase the entire sector.
subsectorsize portions may be written (ARMexpress allows up to 8K but not 256). FlashAddr must be aligned to subsectorsize .
Data is copied from a string or array to the Flash. Only fixed subsectorsize sizes are allowed. This function does not look for 0 terminators when a string is the source.
The way the Flash operates, is that sectors are erased which sets all the bits to 1, or &HFFFFFFFF. When you write into a sector, bits can be changed to 0, they can not be written back to 1. Only sectors (4K, 8K or 32K) can be erased, and all bits in the sector are effected. Writes operate on subsector which can be as small as 256 bytes.
On reset an internal variable which indicates which sector was written to last is set to 0. Any call to WRITE will check the sector corresponding to the FlashAddr. If the sector is different than the last sector written, then this sector will be erased, else if it is the same then the erase does not occur.
This works for the most common use of writing to Flash, which is to start at the low end and work up.
As of firmware version 8.20 you can override this erase algorithm by setting the low 2 bits of FlashAddr.
These routines call the IAP routines for write, erase and prep commands. More details in the user manual for the corresponding CPU.
0 is returned on success, Non-zero error code when there is an error refer to IAP section in CPU user manual for definitions .