Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
AVR / datasheets / AT90USB82_162.pdf
Скачиваний:
45
Добавлен:
20.03.2015
Размер:
2.88 Mб
Скачать

Simple Assembly Code Example for a Boot Loader

228

;-the routine writes one page of data from RAM to Flash

;the first data location in RAM is pointed to by the Y pointer

;the first data location in Flash is pointed to by the Z-pointer ;-error handling is not included

;-the routine must be placed inside the Boot space

;(at least the Do_spm sub routine). Only code inside NRWW section can

;be read during Self-Programming (Page Erase and Page Write).

;-registers used: r0, r1, temp1 (r16), temp2 (r17), looplo (r24),

;loophi (r25), spmcrval (r20)

;storing and restoring of registers is not included in the routine

;register usage can be optimized at the expense of code size

;-It

is assumed that either the interrupt table is moved to the Boot

; loader section or that the interrupts are disabled.

.equ PAGESIZEB = PAGESIZE*2

;PAGESIZEB is page size in BYTES, not words

.org SMALLBOOTSTART

 

Write_page:

 

; Page Erase

 

ldi

spmcrval, (1<<PGERS) | (1<<SPMEN)

call

Do_spm

 

; re-enable the RWW section

 

ldi

spmcrval, (1<<RWWSRE) | (1<<SPMEN)

call

Do_spm

 

; transfer data from RAM to Flash page buffer

ldi

looplo, low(PAGESIZEB)

;init loop variable

ldi

loophi, high(PAGESIZEB)

;not required for PAGESIZEB<=256

Wrloop:

 

ld

r0, Y+

 

ld

r1, Y+

 

ldi

spmcrval, (1<<SPMEN)

 

call

Do_spm

 

adiw

ZH:ZL, 2

 

sbiw

loophi:looplo, 2

;use subi for PAGESIZEB<=256

brne

Wrloop

 

; execute Page Write

 

subi

ZL, low(PAGESIZEB)

;restore pointer

sbci

ZH, high(PAGESIZEB)

;not required for PAGESIZEB<=256

ldi

spmcrval, (1<<PGWRT) | (1<<SPMEN)

call

Do_spm

 

; re-enable the RWW section

 

ldi

spmcrval, (1<<RWWSRE) | (1<<SPMEN)

call

Do_spm

 

; read back and check, optional

ldi

looplo, low(PAGESIZEB)

;init loop variable

ldi

loophi, high(PAGESIZEB)

;not required for PAGESIZEB<=256

subi

YL, low(PAGESIZEB)

;restore pointer

sbci

YH, high(PAGESIZEB)

 

Rdloop:

 

elpm

r0, Z+

 

ld

r1, Y+

 

cpse

r0, r1

 

jmp

Error

 

sbiw

loophi:looplo, 1

;use subi for PAGESIZEB<=256

brne

Rdloop

 

7707A–AVR–01/07

; return to RWW section

; verify that RWW section is safe to read

Return:

 

in

temp1, SPMCSR

 

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)

call

Do_spm

 

rjmp

Return

 

Do_spm:

;check for previous SPM complete Wait_spm:

in temp1, SPMCSR 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, EEPE rjmp Wait_ee

;SPM timed sequence

out SPMCSR, spmcrval spm

; restore SREG (to enable interrupts if originally enabled) out SREG, temp2

ret

AT90USB82/162 Boot

In Table 29 through Table 31, the parameters used in the description of the Self-Programming

Loader Parameters

 

are given.

 

 

 

 

 

 

 

Table 29. Boot Size Configuration() (16k)

 

 

 

 

 

 

 

DEVICE

BOOTSZ1

BOOTSZ0

 

 

Boot Size (in bytes)

Pages

 

 

Application Flash Section

(byte address)

Boot Loader Flash Section (byte address)

End Application Section

Boot Reset Address (Start Boot Loader Section)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

1

 

512 bytes

4

 

0x0000

- 0x3DFF

 

0x3E00 - 0x3FFF

0x3DFF

0x3E00

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

16Kb

1

0

 

1024 bytes

8

 

0x0000

- 0x3BFF

 

0x3C00 - 0x3FFF

0x3BFF

0x3C00

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

1

 

2048 bytes

16

 

0x0000

- 0x37FF

 

0x3800 - 0x3FFF

0x37FF

0x3800

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

0

 

4096 bytes

32

 

0x0000

- 0x2FFF

 

0x3000 - 0x3FFF

0x2FFF

0x3000

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

1

 

512 bytes

4

 

0x0000

- 0x1DFF

 

0x1E00 - 0x1FFF

0x1DFF

0x1E00

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8Kb

1

0

 

1024 bytes

8

 

0x0000

- 0x1BFF

 

0x1C00 - 0x1FFF

0x1BFF

0x1C00

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

1

 

2048 bytes

16

 

0x0000

- 0x17FF

 

0x1800 - 0x1FFF

0x17FF

0x1800

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

0

 

4096 bytes

32

 

0x0000

- 0x0FFF

 

0x1000 - 0x1FFF

0x0FFF

0x1000

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

229

7707A–AVR–01/07

(Page size = 64 words = 128 bytes)

The different BOOTSZ Fuse configurations are shown in Figure 92.

Table 30. Read-While-Write Limit(1)

Device

Section

Pages

Address

 

 

 

 

16K

Read-While-Write section (RWW)

96

0x0000 - 0x2FFF

 

 

 

 

 

No Read-While-Write section (NRWW)

32

0x3000 - 0x3FFF

 

 

 

 

8K

Read-While-Write section (RWW)

32

0x0000 - 0x0FFF

 

 

 

 

 

No Read-While-Write section (NRWW)

32

0x1000 - 0x1FFF

 

 

 

 

Note: 1. For details about these two section, see “NRWW – No Read-While-Write Section” on page 218 and “RWW – Read-While-Write Section” on page 218.

Table 31.

Explanation of different variables used in Figure 94 and the mapping to the Z-pointer

 

 

 

Corresponding

Description(1)

Variable

 

 

Z-value

PCMSB

 

12

 

Most significant bit in the Program Counter.

 

 

 

 

(The Program Counter is 13 bits PC[12:0])

 

 

 

 

 

PAGEMSB

 

5

 

Most significant bit which is used to address

 

 

 

 

the words within one page (64 words in a

 

 

 

 

page requires six bits PC [5:0]).

 

 

 

 

 

ZPCMSB

 

 

Z13

Bit in Z-pointer that is mapped to PCMSB.

 

 

 

 

Because Z0 is not used, the ZPCMSB

 

 

 

 

equals PCMSB + 1.

 

 

 

 

ZPAGEMSB

 

Z6

Bit in Z-pointer that is mapped to PCMSB.

 

 

 

 

Because Z0 is not used, the ZPAGEMSB

 

 

 

 

equals PAGEMSB + 1.

 

 

 

 

 

PCPAGE

 

PC[12:6]

Z13:Z7

Program Counter page address: Page

 

 

 

 

select, for Page Erase and Page Write

 

 

 

 

 

PCWORD

 

PC[5:0]

Z6:Z1

Program Counter word address: Word

 

 

 

 

select, for filling temporary buffer (must be

 

 

 

 

zero during Page Write operation)

 

 

 

 

 

Note: 1.

Z0: should be zero for all SPM commands, byte select for the (E)LPM instruction.

See “Addressing the Flash During Self-Programming” on page 223 for details about the use of Z-pointer during Self-Programming.

230

7707A–AVR–01/07

Соседние файлы в папке datasheets