From 14d7c1147fc7485920460e99498ca26489e3ccbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?MrSm=C3=B6r?= <66489839+MrSmoer@users.noreply.github.com> Date: Mon, 10 Nov 2025 19:25:25 +0100 Subject: [PATCH] Fix: Ignore lower z bits when erasing flash for page-alignment Previously it was possible to erase the size of a page not page aligend. Documentation of atmega328 and atmega2560 states that for the erase operation the lower bits of z are ignored. (I guess it wouldn't make sense to not erase page aligned as well :) --- simavr/sim/avr_flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simavr/sim/avr_flash.c b/simavr/sim/avr_flash.c index 0d67787e..ec5b8aeb 100644 --- a/simavr/sim/avr_flash.c +++ b/simavr/sim/avr_flash.c @@ -127,7 +127,7 @@ avr_flash_ioctl( avr_cycle_timer_cancel(avr, avr_progen_clear, p); if (avr_regbit_get(avr, p->pgers)) { - z &= ~1; + z &= ~(p->spm_pagesize - 1); AVR_LOG(avr, LOG_TRACE, "FLASH: Erasing page %04x (%d)\n", (z / p->spm_pagesize), p->spm_pagesize); for (int i = 0; i < p->spm_pagesize; i++) avr->flash[z++] = 0xff;