Rev. 0.1 9/12 Copyright © 2012 by Silico n Laboratories AN694
AN694
WRITING TO FLASH FROM FIRMWARE ON SiM3XXXX DEVICES
1. Introduction
This application note applies to the SiM3Cxxx, SiM3Uxxx, and SiM3Lxxx device families. The Flash memory on all
Silicon Labs MCU devices is readable and writable from application code. This capability allows user software to
store values, such as calibration constants or system parameters, to the Flash and to implement a boot-loading
feature in which user firmware can be updated in-system from a remote site. The Flash that is not used by
application code can be treated like an EEPROM, thus negating the need to connect an external EEPROM to the
device.
This document starts with the basics of accessing Flash from application code on any device, including device-
specific details. Then, it discusses advanced routines that can be developed from the basic routines. Finally, it
describes precautions to take when writing or erasing Flash. Example code fo r the basic routines for all d evices is
installed with the Precision32 SDK, which can be dow nloa de d from www.silabs.com/32bit-software.
2. Key Points
The voltage supply monitor must be en abled in the VMONn module during Flash write and erase
operations.
The voltage supply monitor must be enabled as a reset source in the RSTSRCn module during Flash write
and erase operations.
Note:Any write or erase operations initiated while the voltage supply monitor is disabled or the voltage supply monitor is
disabled as a reset source will be ignored.
A Lock and Key sequence must be executed before executing a write or erase operation. The Flash
interface can be unlocked for one or multiple write or erase operations.
Writes to the WRDATA register while the Flash interface is locked or an incorrect unlock sequence will
permanently loc k the Flash interface until th e ne xt de vice res et .
Firmware should disable interrupts when writing or er asing Flash to ensure th e Flash interface accesses are
sequential in time and take the minimum time possible.
For all Flash write operations, firmware will stall unless operating from a memory space other than Flash.
Interrupts posted during a Flash write or erase operation will be held pending until the completion of the
Flash operation, after which they will be serviced in priority order.
AN694
2 Rev. 0.1
3. Flash Essentials
Different device series have many simila rities for Flash, including p age sizes, lock bit s, and the instruction s used to
read and write to Flash. The main differences are the amount of Flash available, how the voltage supply monitor is
enabled, how the voltage supply monitor is enabled as a reset source, and how registers are modified to allow
Flash writes and erases. Although the core stalls during Flash write and erase operations, peripherals (USARTn,
SARADCn, TIMERn, etc.) remain active. Interrupt s poste d during a Fla sh write or er ase operation ar e held until the
Flash operation has completed, af ter which they are serviced in priority order.
3.1. Flash Organization
The Flash memory on most devices is organized into a set of 1024-byte pages. See the Memory Organization
chapter of the device reference manual for specific information. Figures 1, 2, 3, and 4 show the Flash organization
for the SiM3Uxxx devices.
Figure 1. SiM3U16x Flash Memory Map (256 kB)
Figure 2. SiM3U15x Flash Memory Map (128 kB)
Flash
0x0000_0000
0x0003_FFFF
0x0004_0000
0x1FFF_FFFF
Reserved
Lock Word 0x0003_FFFC
Flash
0
X0000_0000
0x0003_FFFF
0x0004_0000
0x1FFF_FFFF
Reserved
Lock Word 0x0003_FFFC
Reserved
0x0001_FFFF