[En-Nut-Discussion] bootloader, assembler source for flash programming
Brett Abbott
Brett.Abbott at digital-telemetry.com
Thu Aug 11 20:23:52 CEST 2005
Hermann
This snippet of code replaces the assembly portion of the bootloader.
unfortunately you will have to port the C bit yourself as I dont use
that version.
Ive also cc'd the list as it is quite short.
.module flash_ICC.s
.dbfile flash_ICC.s
.area text
.even
;#define RAMPZ 0x3B
;#define SPMCR 0x68
; void SpmCommand(u_short addr, u_char function);
; SpmCommand(u_short pageAddress, u_char SPMEN_Bit)
; R16/R17 hold 1st value
; R18/T19 hold 2nd value. Low byte is first byte.
_SpmCommand::
movw r30, r16 ; First argument is page address
mov r26, r18 ; Added for ICC (r26 is volatile and
safe to change)
rjmp DoSpm
; void SpmBufferFill(u_short data, u_short adr);
; SpmBufferFill(u_short pageAddress, u_short pointerToData)
; R16/R17 hold 1st value
; R18/T19 hold 2nd value
_SpmBufferFill::
movw r30, r16 ; First argument is page address
movw r0, r18 ; Second argument is data pointer
ldi r26, 1 ; SPMEN bit - r26 is volatile and safe
to use
;#define SPMCR 0x68
DoSpm:
sts 0x68, r26 ; Store function in SPMCR - ICC use r26
as it is volatile
spm ; store program memory
WaitSpm:
;#define SPMCR 0x68
lds r26, 0x68 ; Loop until SPMEN in SPMCR is cleared -
ICC use r26 as it is volatile
sbrc r26, 0 ; ICC r26 as it is volatile
rjmp WaitSpm
ret
Cheers
Brett
--
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: Brett.Abbott at digital-telemetry.com
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860 Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------
More information about the En-Nut-Discussion
mailing list