ATmega32PA: The EEPROM That Outlives the Flash Erase
On an AVR there are three separate memories: flash for code, SRAM for working data, and EEPROM for anything that has to survive a power cycle. They are separate arrays with separate erase mechanisms, and that separation becomes the most important fact on the bench the moment the flash is locked.
Because the rule for locked AVR flash is unforgiving: the only documented path out of lock mode 2 or 3 is a chip erase, and chip erase takes the flash with it. The EEPROM, however, has a fuse that can exempt it. Whether that fuse is set determines whether a locked part still holds recoverable information after the only operation that could open it.
Three memories, three rule sets
| Memory | Erased by chip erase | Erased by page erase | Survives power loss | Readable when flash locked |
|---|---|---|---|---|
| Flash | yes | yes | yes | no, in mode 2 or 3 |
| EEPROM | only if EESAVE allows | yes, by address | yes | no, in mode 2 or 3 |
| SRAM | n/a, volatile | n/a | no | n/a |
The fourth column is the one people forget. The lock bits gate the EEPROM read commands as well as the flash read commands, so a locked part does not hand over its EEPROM over the programming interface either. The EESAVE fuse does not make the EEPROM readable while locked; it only decides whether the contents still exist after the erase that removes the lock.
That distinction is the whole subject. EESAVE is not an access control. It is a survival control.
What EESAVE does, precisely
The fuse is active-low like most AVR fuses: programmed means zero means enabled. With EESAVE enabled, a chip erase clears the flash and leaves the EEPROM intact. With it disabled — the default — chip erase clears both.
Why would a designer enable it? Because a lot of products keep calibration constants, serial numbers, run-hour counters, or network addresses in EEPROM and want a firmware update not to wipe them. It is a common and sensible choice, and it is made for reasons that have nothing to do with protection. That is exactly why it is worth checking: it is set for operational convenience, not defensively, so it is often left in the helpful state.
The recovery sequence this enables
When a part is locked and EESAVE is enabled, an erase-then-read cycle produces something rather than nothing:
- Read the fuse bytes and the lock byte. Confirm the lock state and confirm EESAVE.
- Perform a chip erase. The lock bits return to unlocked, the flash is blank, the EEPROM is preserved.
- Read the EEPROM through the now-permitted read commands.
- Reconstruct what the EEPROM tells you about the product: constants, keys, counters, sometimes whole configuration tables.
What you get is not the firmware. It is the data the firmware operated on. For a device whose behaviour is largely determined by calibration values, that can be most of the commercially interesting content — and it is obtained without any invasive step.
When EESAVE is disabled, the same sequence returns a blank part. Erase, read, nothing. That outcome is definitive, and knowing it early saves a great deal of pointless effort.
Why the EEPROM often matters more than the code
Consider what an ATmega32PA-based product typically stores outside its flash. Measurement offsets. A unit serial. A cumulative usage counter. A device-specific key used to authenticate a sensor or a cartridge. A table of limits that differs per customer.
None of that is in the flash image, and all of it is in the EEPROM. A flash dump tells you the algorithm; the EEPROM tells you the unit. Depending on the question being asked, the second is worth more.
There is a corollary worth stating plainly: a product that keeps its authentication key in EEPROM and enables EESAVE has made a decision that its key should survive a firmware update, which also means it survives the erase that would otherwise be the barrier.
EEPROM endurance and what it means for a read
The EEPROM array is rated for a finite number of write cycles per byte, typically in the hundred-thousand range. That is irrelevant to reading — reads do not wear it — but it matters for interpretation. A counter byte near its maximum looks like corruption; a block of FF in a region that should hold a table usually means the firmware never wrote there rather than that the data was lost.
Also worth knowing: EEPROM writes are slow, in the millisecond range per byte, and the CPU is halted or the write is polled. If a device is powered down mid-write, individual bytes can be left in an indeterminate state. Real dumps contain that damage, and distinguishing it from deliberate values requires knowing which addresses the firmware actually initialises.
Reading EEPROM on a part that is not locked
If the lock bits are open, the EEPROM read is trivial and no erase is needed. It is worth doing before anything invasive, because the EEPROM frequently reveals whether the flash is worth pursuing: a version string, a build date, a product code. Identity recovered from EEPROM often answers the customer’s question without touching the program memory at all.
The order of operations that wastes the least work is therefore always the same. Signature, fuses, lock byte, EEPROM. Four reads, all cheap, all non-destructive. Only after those does the question of the flash arise.
Related notes
- ATmega16PA and the picoPower revision — the sibling die and its electrical margins.
- ATmega8A lock modes — why mode 2 forces an erase in the first place.
- ATmega644 and page-level behaviour — the flash side of the same three-memory model.
FAQ
Can EEPROM be read while the flash is locked? No. Lock mode 2 and 3 disable EEPROM read commands along with flash read commands. EESAVE changes what survives an erase, not what is readable before one.
Does EESAVE survive the chip erase that it protects against? Yes. The fuse bytes are not part of the flash array being erased, so the setting persists and continues to apply.
Is a blank EEPROM after erase proof that EESAVE was off? It is strong evidence. A part that returns all FF across the whole EEPROM after a chip erase was almost certainly erased with EESAVE disabled — but confirm against the fuse read taken before the erase, which is why reading fuses first matters.
Does the EEPROM contain the program? No. It contains data. On some products the data is more valuable than the program, but they are separate containers with separate contents.
Conclusion
Chip erase is the only door out of AVR lock mode 2 and 3, and it destroys the flash on the way through. EESAVE is the one fuse that lets something survive that door. Checking it costs one fuse read and changes the entire plan: with it set, an erase yields recoverable data; with it clear, the erase yields nothing and the answer arrives early.