ADuCM320 Hardware Reference Manual
UG-498
Rev. C | Page 187 of 196
Flash Block Partitioning
In the MDIO dual program image configuration, the Program Image A in Flash 0 and the NVR Data Block A in Flash 1 should be used
together or, alternatively, the Program Image B in Flash 1 and the NVR Data Block B in Flash 0 should be used together. Because the data
and code are in different flash blocks, the code can continue executing in the active program image while flash operations are performed
on the associated NVR data flash block. Only one combination should be used at a time, which is known as the active combination. The
other combination can be updated with new code if required, and by means of the block switching described, code can be made to
execute from the new code. In the unswitched mode, Flash Block 0 is mapped from 0 to 0x1FFFF and Flash Block 1 is mapped from
0x20000 to 0x3FFFF. In the switched mode, Flash Block 1 is mapped from 0 to 0x1FFFF and Flash Block 0 is mapped from 0x20000 to
0x3FFFF. Code should be built to run in the address range 0 to 0x1FFFF and should only be run in this range. A mechanism is provided
in the kernel to run from the appropriate flash block after any reset. This is described in the subsequent subsections of the MDIO section.
For a complete understanding, see Table 291, Figure 38, and Table 290 for additional information.
Program Image
The choice of which blocks are used is determined by the kernel and based on keys placed at the top of the two 120 kB program image
blocks. There are six modes of operation:
•
Debug mode
•
Downloader mode (no valid code)
•
Normal running from Program Image A (Flash 0)
•
Trial run from Program Image A (Flash 0)
•
Normal running from Program Image B (Flash 1)
•
Trial run from Program Image B (Flash 1)
Each of these modes can be entered only via a reset. Every reset causes the kernel to run, and the kernel chooses the appropriate mode
according to keys in the program images.
Each program image contains two keys.
For the active program image, Key1 at Address 0x1DFE0 has a numeric value that indicates the update number. The higher the Key1
value, the more recent the update.
Key2 at Address 0x1DFE8 is used to manage trial runs. A value of 0xFFFFFFFF (erased) indicates a new download. When trial run has
passed, this must be indicated by changing the value to 0.
Key1’ of the other program image is at 0x3DFE0. Key2’ of the other program image is at 0x3DFE8.
The user program space CRCs can be stored at 0x1DFFC for Flash 0 and at 0x3DFFC for Flash 1. The CRC is not required as part of the
block selection mechanism but should be included for increased robustness. The user code can check this CRC periodically.
Note that the keys are placed just below the 120 kB boundary, which is assumed to be the top of the program space. There is no technical
reason why some code cannot be placed above this boundary or why some data cannot be placed below this boundary.
Debug Mode
If after a reset the kernel determines that the download pin (P2.3) is high, the kernel enters user code regardless of the keys. This mode is
intended for debugging only
Choosing the Active Block
After any reset, the kernel chooses the active program image.
Figure 38 is the flowchart for choosing the active program image.
Initially, the kernel assumes that the program image with the larger Key1 is to be made active. If the associated Key2 is not 0, this code has
not passed the trial run and should not yet be used. Instead, the kernel investigates using the other program image. If the Key2’ of the
other program image is 0, that program image is chosen. Based on these decisions, the kernel then sets the active program image and exits
to user code. If neither program image has a valid Key2, the kernel enters its own download mode.