Bootloader Differences
hi all,
i trying understand bootloaders, contains , how go writing one.
can clear of doubts have when started exploring same?
1. why there 2 folders named arduino-usbdfu , arduino-usbserial in arduino firmwares folder? different in 2 versions?
2. in arduino uno or mega, understanding, onboard atmega16u2 chip usb serial conversion between pc , atmega328 or atmega2560 chip. or else too?
if that, why there again 2 different bootloading files of atmega16u2 of mega , uno(arduino-usbserial-mega.hex , arduino-usbserial-uno.hex in arduino-usbserial folder)? why chip dependent?
3. there tutorial or writeup somewhere on how go writing arduino bootloader(for new chip) because know process?
thanking guys in advance
i trying understand bootloaders, contains , how go writing one.
can clear of doubts have when started exploring same?
1. why there 2 folders named arduino-usbdfu , arduino-usbserial in arduino firmwares folder? different in 2 versions?
2. in arduino uno or mega, understanding, onboard atmega16u2 chip usb serial conversion between pc , atmega328 or atmega2560 chip. or else too?
if that, why there again 2 different bootloading files of atmega16u2 of mega , uno(arduino-usbserial-mega.hex , arduino-usbserial-uno.hex in arduino-usbserial folder)? why chip dependent?
3. there tutorial or writeup somewhere on how go writing arduino bootloader(for new chip) because know process?
thanking guys in advance
quote
3. there tutorial or writeup somewhere on how go writing arduino bootloader(for new chip) because know process?look @ datasheet part want use. atmel has sample code bootloader in datasheets have seen.
for example, in 328p:
code: [select]
27.8.13 simple assembly code example boot loader
;-the routine writes 1 page of data ram flash
; first data location in ram pointed y pointer
; first data location in flash pointed z-pointer
;-error handling not included
;-the routine must placed inside boot space
; (at least do_spm sub routine). code inside nrww section can
; read during self-programming (page erase , page write).
;-registers used: r0, r1, temp1 (r16), temp2 (r17), looplo (r24),
; loophi (r25), spmcrval (r20)
; storing , restoring of registers not included in routine
; register usage can optimized @ expense of code size
;-it assumed either interrupt table moved boot
; loader section or interrupts disabled.
.equ pagesizeb = pagesize*2 ;pagesizeb page size in bytes, not words
.org smallbootstart
write_page:
; page erase
ldi spmcrval, (1<<pgers) | (1<<spmen)
call do_spm
; re-enable rww section
ldi spmcrval, (1<<rwwsre) | (1<<spmen)
call do_spm
; transfer data ram flash page buffer
ldi looplo, low(pagesizeb) ;init loop variable
ldi loophi, high(pagesizeb) ;not required 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 pagesizeb<=256
brne wrloop
; execute page write
subi zl, low(pagesizeb) ;restore pointer
sbci zh, high(pagesizeb) ;not required pagesizeb<=256
ldi spmcrval, (1<<pgwrt) | (1<<spmen)
call do_spm
; re-enable rww section
ldi spmcrval, (1<<rwwsre) | (1<<spmen)
call do_spm
; read , check, optional
ldi looplo, low(pagesizeb) ;init loop variable
ldi loophi, high(pagesizeb) ;not required pagesizeb<=256
subi yl, low(pagesizeb) ;restore pointer
sbci yh, high(pagesizeb)
rdloop:
lpm r0, z+
ld r1, y+
cpse r0, r1
jmp error
sbiw loophi:looplo, 1 ;use subi pagesizeb<=256
brne rdloop
; return rww section
; verify rww section safe read
return:
in temp1, spmcsr
sbrs temp1, rwwsb ; if rwwsb set, rww section not ready yet
ret
; re-enable rww section
ldi spmcrval, (1<<rwwsre) | (1<<spmen)
call do_spm
rjmp return
do_spm:
; check 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 no eeprom write access present
wait_ee:
sbic eecr, eepe
rjmp wait_ee
; spm timed sequence
out spmcsr, spmcrval
spm
; restore sreg (to enable interrupts if enabled)
out sreg, temp2
ret
you need isp programmer access memory via spi pins install bootloader, , set fuses clock type using, brownout levels, etc. if want use besides factory programming.
Arduino Forum > Using Arduino > Microcontrollers > Bootloader Differences
arduino
Comments
Post a Comment