From f3630835f2a89bf93771d3193557f2abc1d7cb4d Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 4 Feb 2023 00:56:59 +0100 Subject: [PATCH] Utils: added code to write FLASH (bot tested, yet). --- avr/utils.asm | 107 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/avr/utils.asm b/avr/utils.asm index ab70c33..60f361b 100644 --- a/avr/utils.asm +++ b/avr/utils.asm @@ -1,6 +1,7 @@ +; --------------------------------------------------------------------------- ; Utils_WaitNanoSecs waittime_in_ns , cyles_already_used , waitcount_register ; ; cycles already used will be subtracted from the delay @@ -42,7 +43,7 @@ -; *************************************************************************** +; --------------------------------------------------------------------------- ; Utils_FillSram ; ; IN: @@ -66,7 +67,7 @@ Utils_FillSram_end: -; *************************************************************************** +; --------------------------------------------------------------------------- ; Increment a 32 bit counter at the address given by X. ; IN: ; - X: Address of the 4 byte counter (1. byte is LSB) @@ -93,7 +94,7 @@ Utils_IncrementCounter32: -; *************************************************************************** +; --------------------------------------------------------------------------- ; Increment a 16 bit counter at the address given by X. ; IN: ; - X: Address of the 2 byte counter (1. byte is LSB) @@ -115,7 +116,7 @@ Utils_IncrementCounter16: -; *************************************************************************** +; --------------------------------------------------------------------------- ; Utils_ReadEeprom ; ; Read a byte from EEPROM (see example in ATtiny24/44/84 manual p.19). @@ -137,7 +138,7 @@ Utils_ReadEeprom: -; *************************************************************************** +; --------------------------------------------------------------------------- ; Utils_WriteEeprom ; ; Write a byte to EEPROM (see example in ATtiny24/44/84 manual p.18). @@ -166,3 +167,99 @@ Utils_WriteEeprom: +; --------------------------------------------------------------------------- +; Utils_ReadFlashPageIntoPageBuffer +; +; +; IN: +; - Z: Address to read from (byte address as for LPM!) +; OUT: +; - nothing +; MODIFIED REGISTERS: R0, R1, R15, R16, R20, R24, R25, Z + +Utils_ReadFlashPageIntoPageBuffer: + in r15, SREG + cli + ldi r24, LOW(PAGESIZE*2) + ldi r25, HIGH(PAGESIZE*2) +Utils_ReadFlashPageIntoPageBuffer_loop: + lpm r0, Z+ ; read source data from FLASH (low) + lpm r1, Z ; read source data from FLASH (high) + sbiw ZH:ZL, 1 ; rewind Z address for following SPM + ldi r20, (1<