ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 02.06.2025
Просмотров: 3625
Скачиваний: 0
ATmega8(L) |
|||||||
Assembly Code Example for a Boot Loader” on page 216 for an assembly code |
|||||||
example. |
|||||||
Performing Page Erase by |
To execute page erase, set up the address in the Z-pointer, write “X0000011” to |
||||||
SPM |
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 PCPAGE in the Z-register. |
|||||||
Other bits in the Z-pointer will be ignored during this operation. |
|||||||
• Page Erase to the RWW section: The NRWW section can be read during the page |
|||||||
erase. |
|||||||
• Page Erase to the NRWW section: The CPU is halted during the operation. |
|||||||
Filling the Temporary Buffer |
To write an instruction word, set up the address in the Z-pointer and data in R1:R0, write |
||||||
(Page Loading) |
“00000001” to SPMCR and execute SPM within four clock cycles after writing SPMCR. |
||||||
The content of PCWORD in the Z-register is used to address the data in the temporary |
|||||||
page buffer. The temporary buffer will auto-erase after a page write operation or by writ- |
|||||||
ing the RWWSRE bit in SPMCR. It is also erased after a System Reset. Note that it is |
|||||||
not possible to write more than one time to each address without erasing the temporary |
|||||||
buffer. |
|||||||
Note: If the EEPROM is written in the middle of an SPM page Load operation, all data loaded |
|||||||
will be lost. |
|||||||
Performing a Page Write |
To execute page write, set up the address in the Z-pointer, write “X0000101” to 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 PCPAGE. Other bits in the Z-pointer |
|||||||
must be written to zero during this operation. |
|||||||
• Page Write to the RWW section: The NRWW section can be read during the page |
|||||||
write. |
|||||||
• Page Write to the NRWW section: The CPU is halted during the operation. |
|||||||
Using the SPM Interrupt |
If the SPM interrupt is enabled, the SPM interrupt will generate a constant interrupt |
||||||
when the SPMEN bit in SPMCR is cleared. This means that the interrupt can be used |
|||||||
instead of polling the SPMCR Register in software. When using the SPM interrupt, the |
|||||||
Interrupt Vectors should be moved to the BLS section to avoid that an interrupt is |
|||||||
accessing the RWW section when it is blocked for reading. How to move the interrupts |
|||||||
is described in “Interrupts” on page 44. |
|||||||
Consideration While Updating |
Special care must be taken if the user allows the Boot Loader section to be updated by |
||||||
BLS |
leaving Boot Lock bit11 unprogrammed. An accidental write to the Boot Loader itself can |
||||||
corrupt the entire Boot Loader, and further software updates might be impossible. If it is |
|||||||
not necessary to change the Boot Loader software itself, it is recommended to program |
|||||||
the Boot Lock bit11 to protect the Boot Loader software from any internal software |
|||||||
changes. |
|||||||
Prevent Reading the RWW |
During Self-Programming (either page erase or page write), the RWW section is always |
||||||
Section During Self- |
blocked for reading. The user software itself must prevent that this section is addressed |
||||||
Programming |
during the self programming operation. The RWWSB in the SPMCR will be set as long |
||||||
as the RWW section is busy. During Self-Programming the Interrupt Vector table should |
|||||||
be moved to the BLS as described in “Interrupts” on page 44, or the interrupts must be |
|||||||
disabled. Before addressing the RWW section after the programming is completed, the |
|||||||
user software must clear the RWWSB by writing the RWWSRE. See “Simple Assembly |
|||||||
Code Example for a Boot Loader” on page 216 for an example. |
|||||||
213 |
|||||||
2486O–AVR–10/04 |
|||||||
ATmega8(L)
Preventing Flash Corruption During periods of low VCC, the Flash program can be corrupted because the supply voltage is too low for the CPU and the Flash to operate properly. These issues are the same as for board level systems using the Flash, and the same design solutions should be applied.
A Flash program corruption can be caused by two situations when the voltage is too low. First, a regular write sequence to the Flash requires a minimum voltage to operate correctly. Secondly, the CPU itself can execute instructions incorrectly, if the supply voltage for executing instructions is too low.
Flash corruption can easily be avoided by following these design recommendations (one is sufficient):
1.If there is no need for a Boot Loader update in the system, program the Boot Loader Lock Bits to prevent any Boot Loader software updates.
2.Keep the AVR RESET active (low) during periods of insufficient power supply voltage. This can be done by enabling the internal Brown-out Detector (BOD) if
the operating voltage matches the detection level. If not, an external low VCC Reset Protection circuit can be used. If a reset occurs while a write operation is in progress, the write operation will be completed provided that the power supply voltage is sufficient.
3.Keep the AVR core in Power-down sleep mode during periods of low VCC. This will prevent the CPU from attempting to decode and execute instructions, effectively protecting the SPMCR Register and thus the Flash from unintentional writes.
Programming Time for Flash The calibrated RC Oscillator is used to time Flash accesses. Table 81 shows the typical
when using SPM |
programming time for Flash accesses from the CPU. |
||
Table 81. SPM Programming Time |
|||
Symbol |
Min Programming Time |
Max Programming Time |
|
Flash write (page erase, page write, |
3.7 ms |
4.5 ms |
|
and write Lock Bits by SPM) |
|||
215
2486O–AVR–10/04
ATmega8(L)
sbiw |
loophi:looplo, 1 |
;use subi for PAGESIZEB<=256 |
brne |
Rdloop |
;return to RWW section
;verify that RWW section is safe to read Return:
in temp1, SPMCR
sbrs |
temp1, RWWSB |
; If RWWSB is set, the RWW section is |
not ready yet |
||
ret |
||
; re-enable the RWW section |
||
ldi |
spmcrval, (1<<RWWSRE) | (1<<SPMEN) |
|
rcallDo_spm |
||
rjmp |
Return |
|
Do_spm:
;check for previous SPM complete Wait_spm:
in temp1, SPMCR sbrc temp1, SPMEN rjmp Wait_spm
;input: spmcrval determines SPM action
;disable interrupts if enabled, store status in temp2, SREG
cli
;check that no EEPROM write access is present Wait_ee:
sbic EECR, EEWE rjmp Wait_ee
;SPM timed sequence
out SPMCR, spmcrval spm
; restore SREG (to enable interrupts if originally enabled) out SREG, temp2
ret
ATmega8 Boot Loader |
In Table 82 through Table 84, the parameters used in the description of the self pro- |
|||||||
Parameters |
gramming are given. |
|||||||
Table 82. Boot Size Configuration |
||||||||
Boot Reset |
||||||||
Boot |
Address |
|||||||
Application |
Loader |
End |
(Start Boot |
|||||
Boot |
Flash |
Flash |
Application |
Loader |
||||
BOOTSZ1 |
BOOTSZ0 |
Size |
Pages |
Section |
Section |
Section |
Section) |
|
1 |
1 |
128 |
4 |
0x000 - |
0xF80 - |
0xF7F |
0xF80 |
|
words |
0xF7F |
0xFFF |
||||||
1 |
0 |
256 |
8 |
0x000 - |
0xF00 - |
0xEFF |
0xF00 |
|
words |
0xEFF |
0xFFF |
||||||
0 |
1 |
512 |
16 |
0x000 - |
0xE00 - |
0xDFF |
0xE00 |
|
words |
0xDFF |
0xFFF |
||||||
0 |
0 |
1024 |
32 |
0x000 - |
0xC00 - |
0xBFF |
0xC00 |
|
words |
0xBFF |
0xFFF |
||||||
217
2486O–AVR–10/04