Skip to content

Commit e77a8b6

Browse files
authored
Fix: Ignore lower z bits when erasing flash for page-alignment (#565)
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 :)
1 parent 845f7f3 commit e77a8b6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

simavr/sim/avr_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ avr_flash_ioctl(
127127
avr_cycle_timer_cancel(avr, avr_progen_clear, p);
128128

129129
if (avr_regbit_get(avr, p->pgers)) {
130-
z &= ~1;
130+
z &= ~(p->spm_pagesize - 1);
131131
AVR_LOG(avr, LOG_TRACE, "FLASH: Erasing page %04x (%d)\n", (z / p->spm_pagesize), p->spm_pagesize);
132132
for (int i = 0; i < p->spm_pagesize; i++)
133133
avr->flash[z++] = 0xff;

0 commit comments

Comments
 (0)