Pascal
1) There is no flash initialisation required and the routines can modify any flash in the device (as long as they are not protected). The linker doesn't need to know what areas the application is working with.
2) There are various rules to be observer when writing to Flash. All flash command pass by the FTFL_FCCOB registers and an attempted write to the Flash memory directly will result in a hardware fault. Also it is necessary to write long words to the device that you use - it is not possible to write bytes. For full detaisl see the Flash Command Operationin your user's manual (Chapter 28.4.9)
The routine that you have used from the other thread is a low-level routine. If you download the uTasker project from KINETIS Project Code you will also have all higher level interfaces as described in chapter 6 of http://www.utasker.com/docs/uTasker/uTaskerFileSystem_3.PDF
These next level routines are:
Eg.
extern int fnEraseFlashSector(MEMORY_RANGE_POINTER ptrSector, MAX_FILE_LENGTH Length);
extern int fnWriteBytesFlash(MEMORY_RANGE_POINTER ucDestination, unsigned char *ucData, MAX_FILE_LENGTH Length);
extern int fnMassEraseFlash(void);
which allow simple use.
Eg. if you want to write 100 bytes at the address 0x20000 you can prepare a buffer with the required data content and write it as follows:
static unsigned char myData[100];
int i;
for (i = 0; i < sizeof(myData); i++) {
myData[i] = i;
}
fnWriteBytesFlash((MEMORY_RANGE_POINTER)0x20000, myData, sizeof(myData));
The routine handles the Flash details and allows programming on a byte basis (with some possible restrictions imposed by the HW) from the point-of-view of the application.
To delete this again
fnEraseFlashSector(((MEMORY_RANGE_POINTER)0x20000, sizeof(myData));
Note however the smallest delete size depends on the Flash sector size of the flash.
For more ease, the next level routines are file system routine so you can write data to files at a higher layer (uFileSystem) or the uParameterSystem (also discussed in the document) contains an interface that is designed specifically to handle parameter storage, retrieval and parameter modifications. It allows the user to work with a pure byte interface and also make single byte changes to the parameters (sort of EEPROM emulation) with a fail safe swap block method so that no parameters are lost in case of resets or power loss during programming.
Note also that the lower level routines also automatically handle writing to devices outside of internal Flash.
For example, if you have a 256k Flash device any writes to the range 0..256k will be written to internal flash. If you have a 1Meg serial SPI Flash connected via SPI it can be defined to be memory mapped to the range 256k..1280k so writes to this area are automatically written it it instead. It also handles writing over flash medium boundaries and the file system layer doesn't need to know the physical medium actually used. The same is true for SPI flash connected via I2C or external parallel Flash.
Finally note that if you use the uTasker project it allows the flash use to be simulated (in the VisualStudio project) so you can also step into the flash programming routines to see how it works - see the Flash interface emulation in operation (to understand how the FTFL operates). The emulation interface also check that no rules are broken when programming flash and will inform you of usage errors.
Regards
Mark