I'm trying to adapt a bootloader so that it's compatible with AVR's with >64k program flash. The function for writing buffer to flash shown below.
This function works fine as long as the AVR has less than 64k flash. If it has greater the 64k it wraps and starts writing from x0000 ('page' address overflows).
I know this is because the boot_page_write address is a byte address, so the 16 bit byte address can only point up to 64k.
In the code below 'page' can only be an unit16. Is it as simple as adding a 'page' offset when it gets to 65535 and setting RAMPZ before the boot_page_write function?
/*********Atmel Studio 6 avr-gcc w/ AT90USB1286***************/
inline void write_buffer_to_flash()
const uint8_t* p = rx_buffer; //index of 257, will write whole page at once
boot_spm_busy_wait(); //wait for page erase
for (i = 0; i < SPM_PAGESIZE; i += 2)// bytes
uint16_t w = *p++; //flash divided in words
w |= (*p++) << 8;//fills LSB first and shifts
boot_page_fill(page + i, w);//fill the write buffer