atmega323l ATMEL Corporation, atmega323l Datasheet - Page 179

no-image

atmega323l

Manufacturer Part Number
atmega323l
Description
Atmega323 8-bit Avr Microcontroller With 32k Bytes Of In-system Programmable Flash
Manufacturer
ATMEL Corporation
Datasheet
Entering the Boot Loader
Program
Capabilities of the Boot
Loader
Self-programming the
Flash
Performing Page Erase by
SPM
Fill the Temporary Buffer
(Page Load)
1457G–AVR–09/03
The SPM instruction can access the entire Flash, but can only be executed from the
Boot Loader Flash section. If no Boot Loader capability is needed, the entire Flash is
available for application code. Entering the Boot Loader takes place by a jump or call
from the application program. This may be initiated by some trigger such as a command
received via USART or SPI interface, for example. Alternatively, the Boot Reset Fuse
can be programmed so that the Reset Vector is pointing to the Boot Flash start address
after a reset. In this case, the Boot Loader is started after a reset. After the application
code is loaded, the program can start executing the application code. Note that the
fuses cannot be changed by the MCU itself. This means that once the Boot Reset Fuse
is programmed, the Reset Vector will always point to the Boot Loader Reset and the
fuse can only be changed through the Serial or Parallel Programming interface.
Table 60. Boot Reset Fuse
The program code within the Boot Loader section has the capability 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.
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 general
Read/Write Lock (Lock bit 1) does not control reading nor 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 filling the temporary page buffer one word at a time using SPM, and
then executing page write. If only part of the page needs to be changed, the other parts
must be stored (for example in internal SRAM) before the erase, and then be rewritten.
The temporary page buffer can be accessed in a random sequence. It is essential that
the page address used in both the page erase and page write operation is addressing
the same page. See “Assembly code example for a Boot Loader” on page 185 for an
assembly code example.
To execute Page Erase, set up the address in the Z-pointer, write “00011” to the five
LSB in SPMCR and execute SPM within four clock cycles after writing SPMCR. The
data in R1 and R0 is ignored. The page address must be written to Z14:Z7. Other bits in
the Z-pointer will be ignored during this operation. It is recommended that the interrupts
are disabled during the Page Erase operation.
To write an instruction word, set up the address in the Z-pointer and data in R1:R0, write
“00001” to the five LSB in SPMCR and execute SPM within four clock cycles after writ-
ing SPMCR. The content of Z6:Z1 is used to address the data in the temporary buffer.
Z14:Z7 must point to the page that is supposed to be written.
BOOTRST
0
1
Reset Address
Reset Vector = Application Reset (address $0000)
Reset Vector = Boot Loader Reset (see Table 59)
ATmega323(L)
179

Related parts for atmega323l