Skip to content

Fix atmega328pb reset_flags/signature/fuse never being wired up - #602

Merged
gatk555 merged 1 commit into
buserror:masterfrom
chschu:bugfix/mega328pb-reset-flags-include-order
Nov 2, 2026
Merged

gatk555 merged 1 commit into
buserror:masterfrom
chschu:bugfix/mega328pb-reset-flags-include-order

Conversation

@chschu

@chschu chschu commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Currently, sim_mega328pb.c includes sim_core_declare.h before avr/iom328pb.h, so DEFAULT_CORE's #ifdef SIGNATURE_0 check is false for this MCU. reset_flags (and signature/fuse/lockbits) end up zero-initialized instead of wired to MCUSR, so avr_reset() never preserves PORF/EXTRF/BORF across a reset on atmega328pb.

This breaks any simulated bootloader handoff relying on EXTRF surviving a watchdog-triggered reset (optiboot only clears WDRF if EXTRF is also set). This can cause an endless reset loop.

The same bug class has been fixed in f10736a for a lot of other cores; sim_mega328pb.c was added later and missed that fix.

This PR reorders the includes, thereby fixing the reset_flags (and signature/fuse/lockbits) wiring for atmega328pb.

@gatk555
gatk555 merged commit cb4aa60 into buserror:master Nov 2, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants