started working on AtMega8515 module C1.
This commit is contained in:
81
avr/modules/flash/flash1pmega.asm
Normal file
81
avr/modules/flash/flash1pmega.asm
Normal file
@@ -0,0 +1,81 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2025 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
; * This file is part of the project "AqHome". *
|
||||
; * Please see toplevel file COPYING of that project for license details. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
.equ FLASH_PAGESIZE = (PAGESIZE*2)
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data
|
||||
|
||||
.dseg
|
||||
|
||||
flashPageStart: .byte 2
|
||||
flashPageBuffer: .byte FLASH_PAGESIZE
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; flash1pMegaWritePage
|
||||
;
|
||||
; Interrupts must be disabled!
|
||||
;
|
||||
; @clobbers r0, r1, r20, r24, r25, X, Z
|
||||
|
||||
flash1pMegaWritePage:
|
||||
lds zl, flashPageStart
|
||||
lds zh, flashPageStart+1
|
||||
; copy from SDRAM into MCUs temporary page buffer
|
||||
ldi xl, LOW(flashPageBuffer)
|
||||
ldi xh, HIGH(flashPageBuffer)
|
||||
ldi r24, LOW(PAGESIZE)
|
||||
flash1pMegaWritePages_loop:
|
||||
ld r0, X+ ; read source data from buffer (low)
|
||||
ld r1, X+ ; read source data from buffer (high)
|
||||
ldi r20, (1<<SPMEN) ; enable next SPM, write R1:R0 into temp page buffer
|
||||
rcall flashDoSpm ; (R16)
|
||||
adiw zh:zl, 2
|
||||
dec r24
|
||||
brne flash1pMegaWritePages_loop
|
||||
|
||||
subi zl, LOW(PAGESIZE*2) ; point back to begin of page
|
||||
sbci zh, HIGH(PAGESIZE*2)
|
||||
; transfer data from temporary page buffer into FLASH memory
|
||||
ldi r20, (1<<PGWRT) + (1<<SPMEN) ; enable next SPM, write page (R1/R0 ignored)
|
||||
rcall flashDoSpm ; (R16)
|
||||
|
||||
rcall flash1pMegaEnableRWW
|
||||
;flash1pMegaWritePages_endLoop:
|
||||
; in r20, SPMCR
|
||||
; sbrc r20, RWWSB
|
||||
; rjmp flash1pMegaWritePages_endLoop
|
||||
; ldi r20, (1<<RWWSRE) | (1<<SPMEN) ; reenable RWW
|
||||
; rcall flashDoSpm ; (R16)
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
flash1pMegaEnableRWW:
|
||||
ldi r20, (1<<RWWSRE) | (1<<SPMEN) ; reenable RWW
|
||||
rcall flashDoSpm ; (R16)
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
.equ flashWritePage = flash1pMegaWritePage
|
||||
|
||||
|
||||
Reference in New Issue
Block a user