
173
8246B–AVR–09/11
ATtiny2313A/4313
19. Self-Programming
19.1
Features
Self-Programming Enables MCU to Erase, Write and Reprogram Application Memory
Efficient Read-Modify-Write Support
Lock Bits Allow Application Memory to Be Securely Closed for Further Access
19.2
Overview
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.
19.3
Lock Bits
19.4
Self-Programming the Flash
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:
1.
Either, fill the buffer before a Page Erase:
a.
Fill temporary page buffer
b.
Perform a Page Erase
c.
Perform a Page Write
2.
Or, fill the buffer after Page Erase:
a.
Perform a Page Erase
b.
Fill temporary page buffer
c.
Perform a Page Write
If only a part of the page needs to be changed, the rest of the page must be stored (for example
in the temporary page buffer) before the erase, and then be re-written.
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.
The SPM instruction is disabled by default but it can be enabled by programming the SELFPR-
GEN fuse (to “0”).
19.4.1
Addressing the Flash During Self-Programming
The Z-pointer is used to address the SPM commands.
Bit
151413121110
9
8
ZH (R31)
Z15
Z14
Z13
Z12
Z11
Z10
Z9
Z8
ZL (R30)
Z7Z6Z5Z4Z3Z2Z1
Z0
765
43210