ADuCM320 Hardware Reference Manual
UG-498
Rev. C | Page 75 of 196
SIGNATURE. ADDRESS 0x1FFFC
RESERVED. ADDRESS: 0x1FFF8
USER READ PROTECTION KEY 1. ADDRESS: 0x1FFF4
USER WRITE PROTECTION PATTERN 1 [31:0] ADDRESS: 0x1FFF0
RESERVED. ADDRESS: 0x1FFEC
USERFAAKEY1 [31:0] ADDRESS: 0x1FFE8
REST OF THE UPPERMOST PAGE IN USER SPACE
11
176-
114
Figure 15. Uppermost Page in User Flash 0 Space
Writing to Flash
Each write programs 64 bits of data.
To write to a flash location, the following sequence is required:
1.
Write the address of the flash location to FEEFLADR.
2.
Write the 64 bits of data to FEEFLDATA0 and FEEFLDATA1.
3.
Write the write command to FEECMD.
After the write command is given, the controller writes to flash. CMDDONE (FEESTA[2]) indicates that the command is completed.
In addition, note that a 64-bit location can be written to only once, unless it is erased again because a second write to the same 64-bit
location will corrupt the 8-bit ECC. With the ECC disabled, it is possible to write to a 64-bit location multiple times as long as subsequent
writes clear more bits to 0 than the previously ones because a page erase or mass erase is needed to change bits from 0 to 1. It is only
possible to write to a 64-bit twice without doing an erase and remain within
data sheet specifications. If the flash is written to
more than twice without an erase, there is the risk of corrupting data.
Do not write to flash from within interrupts because interrupts can occur at any point during normal program execution and an existing
write operation to flash could be interrupted and the flash control registers could be corrupted resulting in unexpected behavior. If an
interrupt function needs to store code to flash, the data must be stored in a queue in SRAM, and the write should be performed after the
interrupt exits. An alternative to this is to implement a mutex to ensure that two or more sections of code cannot attempt to write to flash
before all previous flash operations are completed.
Customers must have a single function that performs all the writes to flash needed by the customer application. It must only be possible to
call this function once until the function has exited. This function must be protected so that it is not possible under a fault condition for
the CPU to jump to the code and to execute random writes. One of the techniques recommended for implementing such protection is to
include code before and after the function that traps the CPU there or that jumps to a fault handler.
The flash can only be programmed and erased a number of times specified in the
data sheet before data will corrupt. If
customers need to perform more write operations than what is specified in the
data sheet, store the data using a wear
levelling scheme where the data is stored across various locations in flash over multiple pages. For example, if 64 bits of data need to be
stored and four flash pages are used, the data can be updated 128 times, and the four flash pages will only be subjected to a single
program/erase cycle. When implementing this type of wear levelling scheme, it is necessary to have a dedicated location where pointers to
the valid data is stored, where the next data is to be programmed, and a counter of the total number of writes to ensure that the flash is
not over cycled.
Erasing Flash
User code can call three flash erase commands:
MASSERASE0: This command erases the entire user Flash 0 memory. After entering the user protection key into FEEKEY, write the
MASSERASE0 command to FEECMD.
MASSERASE1: This command erases the entire user Flash 1 memory. After entering the user protection key into FEEKEY, write the
MASSERASE1 command to FEECMD.
PAGEERASE: This command erases 2 kB of flash. The page is selected by FEEADR0. After entering the user protection key into
FEEKEY, load FEEADR0 with the page address to be erased. Finally, write the page erase command to FEECMD. CMDDONE
(FEESTA[2]) indicates that the command is completed.
During a page or mass erase sequence, the flash controller and flash block consume extra current for the duration of the flash erase
sequence.