17.6.4 In Application Programming (IAP) Feature
The IAP feature is a function located in ROM that can be called by any software application.
When called, this function sends the desired FLASH command to the EEFC and waits for the Flash to be ready (looping while the FRDY bit is not set in the MC_FSR register).
Since this function is executed from ROM, this allows Flash programming (such as sector write) to be done by code running in Flash.
The IAP function entry point is retrieved by reading the NMI vector in ROM (0x00800008).
This function takes two arguments as parameters:
- the index of the Flash bank to be programmed: 0 for EEFC0, 1 for EEFC1. For devices with only one bank, this parameter has no effect and can be either 0 or 1, only EEFC0 will be accessed.
- the command to be sent to the EEFC Command register.
This function returns the value of the EEFC_FSR register.
An example of IAP software code follows:
// Example: How to write data in page 200 of the flash
memory using ROM IAP function
flash_page_num = 200
flash_cmd = 0
flash_status = 0
eefc_index = 0 (0 for EEFC0, 1 for EEFC1)
// Initialize the function pointer (retrieve function
address from NMI vector)*/
iap_function_address = 0x00800008
// Fill the Flash page buffer at address 200 with the data
to be written
for i=0, i < page_size, i++ do
flash_sector_200_address[i] = your_data[i]
// Prepare the command to be sent to the EEFC Command
register: key, page number and write command
flash_cmd = (0x5A << 24) | (flash_page_num << 8)
| flash_write_command;
// Call the IAP function with the right parameters and
retrieve the status in flash_status after completion
flash_status = iap_function (eefc_index,
flash_cmd);