C8051F300/1/2/3/4/5
94
Rev. 2.9
10.4. Flash Write and Erase Guidelines
Any system which contains routines which write or erase Flash memory from software involves some risk
that the write or erase routines will execute unintentionally if the CPU is operating outside its specified
operating range of V
DD
, system clock frequency, or temperature. This accidental execution of Flash modi-
fying code can result in alteration of Flash memory contents causing a system failure that is only recover-
able by re-Flashing the code in the device.
The following guidelines are recommended for any system which contains routines which write or erase
Flash from code.
10.4.1. V
DD
Maintenance and the V
DD
monitor
1.
If the system power supply is subject to voltage or current "spikes," add sufficient transient
protection devices to the power supply to ensure that the supply voltages listed in the Absolute
Maximum Ratings table are not exceeded.
2.
Make certain that the minimum V
DD
rise time specification of 1 ms is met. If the system cannot
meet this rise time specification, then add an external V
DD
brownout circuit to the RST pin of
the device that holds the device in reset until V
DD
reaches 2.7 V and re-asserts RST if V
DD
drops below 2.7 V.
3.
Enable the on-chip V
DD
monitor and enable the V
DD
monitor as a reset source as early in code
as possible. This should be the first set of instructions executed after the Reset Vector. For 'C'-
based systems, this will involve modifying the startup code added by the 'C' compiler. See your
compiler documentation for more details. Make certain that there are no delays in software
between enabling the V
DD
monitor and enabling the V
DD
monitor as a reset source. Code
examples showing this can be found in “AN201: Writing to Flash from Firmware", available
from the Silicon Laboratories web site.
4.
As an added precaution, explicitly enable the V
DD
monitor and enable the V
DD
monitor as a
reset source inside the functions that write and erase Flash memory. The V
DD
monitor enable
instructions should be placed just after the instruction to set PSWE to a '1', but before the
Flash write or erase operation instruction.
5.
Make certain that all writes to the RSTSRC (Reset Sources) register use direct assignment
operators and explicitly DO NOT use the bit-wise operators (such as AND or OR). For exam-
ple, "RSTSRC = 0x02" is correct. "RSTSRC |= 0x02" is incorrect.
6.
Make certain that all writes to the RSTSRC register explicitly set the PORSF bit to a '1'. Areas
to check are initialization code which enables other reset sources, such as the Missing Clock
Detector or Comparator, for example, and instructions which force a Software Reset. A global
search on "RSTSRC" can quickly verify this.
10.4.2. PSWE Maintenance
7.
Reduce the number of places in code where the PSWE bit (b0 in PSCTL) is set to a '1'. There
should be exactly one routine in code that sets PSWE to a '1' to write Flash bytes and one rou-
tine in code that sets PSWE and PSEE both to a '1' to erase Flash pages.
8.
Minimize the number of variable accesses while PSWE is set to a '1'. Handle pointer address
updates and loop variable maintenance outside the "PSWE = 1; ... PSWE = 0;" area. Code
examples showing this can be found in
AN201, "Writing to Flash from Firmware"
, available
from the Silicon Laboratories web site.
9.
Disable interrupts prior to setting PSWE to a '1' and leave them disabled until after PSWE has
been reset to '0'. Any interrupts posted during the Flash write or erase operation will be ser-
Summary of Contents for C8051F300
Page 2: ...C8051F300 1 2 3 4 5 2 Rev 2 9 NOTES ...
Page 6: ...C8051F300 1 2 3 4 5 6 Rev 2 9 NOTES ...
Page 48: ...C8051F300 1 2 3 4 5 48 Rev 2 9 NOTES ...
Page 56: ...C8051F300 1 2 3 4 5 56 Rev 2 9 NOTES ...
Page 82: ...C8051F300 1 2 3 4 5 82 Rev 2 9 NOTES ...
Page 88: ...C8051F300 1 2 3 4 5 88 Rev 2 9 NOTES ...
Page 96: ...C8051F300 1 2 3 4 5 96 Rev 2 9 NOTES ...
Page 130: ...C8051F300 1 2 3 4 5 130 Rev 2 9 NOTES ...
Page 172: ...C8051F300 1 2 3 4 5 172 Rev 2 9 NOTES ...