110
ATmega161(L)
1228B–09/01
Note:
1. “1” means unprogrammed, “0” means programmed
Capabilities of the Boot
Loader
The program code within the Boot Loader section has the ability to read from and write
into the entire Flash, including the Boot Loader Memory. This allows the user to update
both the Application code and the Boot Loader code that handles the software update.
The Boot Loader can thus even modify itself, and it can also erase itself from the code if
the feature is not needed anymore. Special care must be taken if the user allows the
Boot Loader section to be updated by leaving Boot Lock bit11 unprogrammed. An acci-
dental write to the Boot Loader itself can corrupt the entire Boot Loader, and further
software updates might be impossible. If it is not needed to change the Boot Loader
software itself, it is recommended that the Boot Lock bit 11 be programmed to protect
the Boot Loader software from software changes.
Self-programming the
Flash
Programming of the Flash is executed one page at a time. The Flash page must be
erased first for correct programming. The general Write Lock (Lock Bit 2) does not con-
trol the programming of the Flash memory by SPM instruction. Similarly, the Read/Write
Lock (Lock Bit 1) does not control reading or writing by LPM/SPM, if it is attempted.
The program memory can only be updated page-by-page, not word by word. One page
is 128 bytes (64 words). The program memory will be modified by first performing page
erase, then by filling the temporary page buffer one word at a time using SPM, and then
by executing page write. If only part of the page needs to be changed, the other parts
must be stored (for example, in the temporary page buffer) before the erase, and then
be rewritten. The temporary page buffer can be accessed in a random sequence. The
CPU is halted both during page erase and during page write and the SPMEN bit in the
SPMCR register will be auto-cleared. For future compatibility, however, it is recom-
mended that the user software verify that the SPMEN bit is cleared before starting a new
page erase, page write, or before writing the Lock Bits command (see code examples
below). It is essential that the page address used in both the page erase and page write
operation is addressing the same page.
Setting the Boot Loader Lock
Bits by SPM
To set the Boot Loader Lock bits, write the desired data to R0, write “1001” to SPMCR,
and execute SPM within four clock cycles after writing SPMCR. The only accessible
Lock bits are the Boot Lock bits that may prevent the Application Code and Boot Loader
sections from any software update by the MCU. See Table 37 and Table 38 for how the
different settings of the Boot Loader bits affect the Flash access.
If bit5 - bit2 in R0 is cleared (zero), the corresponding Boot Lock bit will be programmed
if an SPM instruction is executed within four cycles after BLBSET and SPMEN are set in
SPMCR.
Performing Page Erase by
SPM
To execute a page erase, set up the address in the Z-pointer, write “0011” to SPMCR,
and execute SPM within four clock cycles after writing SPMCR. The data in R1 and R0
are ignored. The page address must be written to Z13:Z7. Other bits in the Z-pointer will
be ignored during this operation.
Table 39.
Boot Reset Fuse, BOOTRST
BOOTRST
Reset Address
1
Reset Vector = Application Reset (address $0000)
0
Reset Vector = Boot Loader Reset (address $1E00)
Bit
7
6
5
4
3
2
1
0
–
–
BLB12
BLB11
BLB02
BLB01
–
–
R0