UG-498
ADuCM320 Hardware Reference Manual
Rev. C | Page 188 of 196
Trial Run Mode
After user code is entered, the code checks whether a trial run or a normal run should be performed. A trial run is indicated if the active
Key1 is less than the other Key1’. In a trial run, the old code first checks that the new program image is functioning correctly. The trial run
starts in the old program image and performs initial checks, such as CRCs and other checks that the user deems necessary, on the new
program image. The trial run can then continue by switching to the new image using Bit 3 of MMR FEECON1. It is recommended that
the code that performs the switching be at a fixed location in Flash Page0 and be the same in all revisions. The code following the
switching point should include sufficient identical code so that the CPU pipeline plus the flash lookahead buffers contain the expected
code after switching. The user must also clear the memory cache to prevent old code from executing after the switch.
The trial run should also copy all necessary data from the old NVR to the new NVR. After the new flash blocks are shown to be correct,
the user code must write 0 to Key2’ of the new flash block to mark the block as good. The user code can then initiate normal operation.
Alternatively, a software reset can be issued, and then the device enters normal mode in the new program image.
A reset may occur during a trial run, for instance, due to power loss or during a watchdog event due to program hanging or a deliberate
software reset. In this case, a trial run restarts in the old code, and then the trial run code decides how to proceed.
Normal Mode
The user code must check whether a trial run or a normal run should be performed. A normal run is indicated if the active Key1 is larger
than the other Key1. During normal operation, the MDIO master can send download information to the active user code so that new
code is written to the other program image. Such a download must also write the new Key1’ with a value of one more than the active
Key1. The new Key2’ must be left erased as 0xFFs. After the download, the part must be reset to allow a trial run to occur.
Typical Sequence
A typical sequence is shown in Table 290.
On a new device, the initial code can be downloaded via SW JTAG if P2.3 is held high during a reset; otherwise, the kernel enters its own
downloader because there is no valid key. At the end of the download to Flash 0, Key1 is set to 1 and Key2 is set to 0.
After a reset, normal code is run from Flash 0 because its Key1 is greater than Key1’ (0xFFs = −1) and its Key2 is 0. User code can receive
MDIO frames instructing it to download code to Flash 1, which results in the new Key2’ being erased and 2 being written to the new Key1’.
After a reset, the kernel activates Flash 0 for a trial run on the new code because Key2’ of Flash 1 is 0xFFs. If the trial run passes, then the
user code sets Key2 to 0 and issues a software reset.
After a reset, the kernel selects Flash 1 because its Key1 is still larger than the other Key1 and the active Key2 is 0. User code can receive
MDIO frames instructing it to download code, including copying the NVR data block, to Flash 0, which results in Key2 being erased and
3 being written to Key1.
Changeover back to Flash 0 is then similar to the change to Flash 1.
Table 290. Example Block Switching Sequence
Number of Software
Download
Key2 of
Flash 0
Key1 of
Flash 0
Key2 of
Flash 1
Key1 of
Flash 1
Status
Reset
Required?
Not applicable
0xFFFFFFFF 0xFFFFFFFF 0xFFFFFFFF 0xFFFFFFFF Initial startup
1
0
1
0xFFFFFFFF 0xFFFFFFFF Kernel has downloaded Code1 to Flash 0
Yes
1
0
1
0xFFFFFFFF 0xFFFFFFFF Code1 normal execution in Flash 0
No
2
0
1
0xFFFFFFFF 2
Code1 has downloaded Code2 to Flash 1
Yes
2
0
1
0xFFFFFFFF 2
Code1 starts a trial run on Code2 in Flash 1 No
2
0
1
0
2
Code2 trial run complete
Yes
2
0
1
0
2
Code 2 normal execution in Flash 1
No
3
0xFFFFFFFF 3
0
2
Code2 has downloaded Code3 to Flash 0
Yes
3
0xFFFFFFFF 3
0
2
Code2 starts trial run on Code3 in Flash 0
No
3
0
3
0
2
Code3 trial mode complete
Yes
3
0
3
0
2
Code3 normal execution in Flash 0
No
4
0
3
0xFFFFFFFF 4
Code3 has downloaded Code4 to Flash 1
Yes
4
0
3
0xFFFFFFFF 4
Code3 starts a trial run on Code4 in Flash 1 No
4
0
3
0
4
Code 4 trial mode complete
Yes
4
0
3
0
4
Code4 normal execution in Flash 1
No
…
…
…
…