Datasheet

218
ATtiny828 [DATASHEET]
8371A–AVR–08/12
21.7 Boot Loader Lock Bits
The boot loader has two separate sets of lock bits, which can be set independently. This gives the user a unique flexibility
to select different levels of protection.
The user can choose any of the following:
z Protect the entire Flash from a software update by the MCU
z Protect only the Boot Loader Flash section from a software update by the MCU
z Protect only the Application Flash section from a software update by the MCU
z Allow software update in the entire Flash.
For more details on lock bits, see “Lock Bits” on page 225.
21.7.1 Programming Boot Loader Lock Bits by SPM
To set boot loader and general lock bits:
z Write the desired data to R0. A cleared bit indicates the corresponding lock bit is to be programmed. See bit
mapping of R0 below
z Write “X0001001” to SPMCSR
z Execute SPM within four clock cycles after writing SPMCSR
During lock bit programming, the contents of R0 is treated as shown below.
During the operation, the value of Z-pointer is ignored, but for future compatibility it is recommended to load the Z-pointer
with 0x0001 (same as used for reading the lock bits). For future compatibility, it is also recommended to set bits 7 and 6
in R0 to “1” when writing the Lock bits.
When programming the Lock bits the entire Flash can be read during the operation.
See Table 87 on page 226 and Table 88 on page 226 for how different settings of the boot loader lock bits affect Flash
access. See “Lock Bits” on page 225 for lock bit layout.
21.7.2 Updating the BLS
Special care must be taken if boot lock bit BLB11 is left unprogrammed, allowing the BLS to be updated. An accidental
write to the BLS can corrupt the entire boot loader, making further software updates impossible. If boot loader software
does not need to be updated, it is recommended to program boot lock bit BLB11 to protect the BLS from being changed
by software.
21.8 Self-Programming the Flash
The device provides a self-programming mechanism for downloading and uploading program code by the MCU itself.
Self-Programming can use any available data interface and associated protocol to read code and write (program) that
code into program memory.
Program memory is updated in a page by page fashion. Before programming a page with the data stored in the
temporary page buffer, the page must be erased. The temporary page buffer is filled one word at a time using SPM and
the buffer can be filled either before the Page Erase command or between a Page Erase and a Page Write operation:
Bit 76543210
R0 1 1 BLB12 BLB11 BLB02 BLB01 LB2 LB1