-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
I'm playing with an AVR64DD32 chip, and I want to store data in the flash memory runtime. I started looking at the program space utilities, but I soon realized it is a read-only library. I started mixing the memcpy() functuin with ccp_write_spm, and I came up with this one:
#include <avr/io.h>
#define dest_hi r25
#define dest_lo r24
#define src_hi r23
#define src_lo r22
#define len_hi r21
#define len_lo r20
#ifndef CCP_SPM_gc
#define CCP_SPM_gc 0x9D /* SPM Instruction Protection */
#endif
#ifndef NVMCTRL_CMD_FLWR_gc
#define NVMCTRL_CMD_FLWR_gc 0x02
#endif
.global flash_memcpy
.type flash_memcpy, @function
flash_memcpy:
movw r30, src_lo
movw r26, dest_lo
movw r28, len_lo
; Set SPM to magic value
ldi r18, CCP_SPM_gc
ldi r19, NVMCTRL_CMD_FLWR_gc
out CCP, r18
sts NVMCTRL_CTRLA, r19
.L_memcpy_loop:
ld r0, Z+
st X+, r0
sbiw r28, 0x01
brne .-8
I haven't tested this yet. It assumes that the written memory area is mapped to the data space.
My question is that would it be possible to include this in the avr-libc once this code stabilizes?
Metadata
Metadata
Assignees
Labels
No labels