Posts Tagged ‘break ic source flash’
ATtiny45: Three Parts, One Pinout, and a Dump Length That Tells Them Apart
Three part numbers, one eight-pin body, one pinout, one peripheral list. A designer who runs short of program space in an ATtiny25 moves to an ATtiny45 without touching the board, and a designer who runs short again moves to an ATtiny85 the same way. The BOM changes, the copper does not. That convenience is the reason a recovery on this family begins with a question that has nothing to do with reading: which of the three is physically in the socket.
The answer is not on the silkscreen in any reliable way. It is in the signature, in the initialisation code, and in how the programming interface behaves when asked for more words than the part contains.
What actually differs between the three
The core is the same AVR eight-bit machine across all three, and the peripheral set is close to identical: an eight-bit timer with PWM, a second eight-bit timer, a four-channel ten-bit converter, an analogue comparator, a universal serial interface, and the same six usable I/O pins on the eight-pin package.
| ATtiny25 | ATtiny45 | ATtiny85 | |
|---|---|---|---|
| flash | 2 KB | 4 KB | 8 KB |
| SRAM | 128 B | 256 B | 512 B |
| EEPROM | 128 B | 256 B | 512 B |
| words of flash | 1024 | 2048 | 4096 |
| pinout | 8-pin | 8-pin | 8-pin |
Everything that changes is a quantity. Nothing that changes is a feature. That is exactly the situation in which a swapped part goes unnoticed for a year and then surfaces during a recovery, when the image comes back the wrong length and nobody can say whether the read failed or the part is simply smaller than the drawing says.
Why the dump length is the first test, and why it is not enough
The interface is asked for a word count. On a 4 KB member the correct answer is 2048 words. Ask the same interface for 4096 words from a 2 KB member and one of three things happens, depending on the adapter: it wraps and returns the first 1024 words a second time, it returns 0xFF for everything past the end, or it reports a verify failure partway through. All three look like a fault to somebody who has not seen the pattern before, and only the first is diagnostic, because a wrap is a fingerprint.
A wrap is easy to detect and worth checking for explicitly. Compare the second half of the buffer against the first. Identical halves on a part that should not be able to produce them means the read exceeded the array, which means the part is smaller than assumed. That single comparison resolves a surprising number of «the dump is corrupt» cases without any further work.
0xFF past the end is the useless answer, because erased flash is also 0xFF. A tail of 0xFF is equally consistent with a small part, an unprogrammed region of a large part, and an adapter that failed silently and filled its buffer with the erased value. The pattern carries no information on its own.
The stack pointer initialisation as an identifier
Here is the test that does work, and it comes from the code rather than the interface. Every AVR program built with a normal toolchain starts by loading the stack pointer with the top of SRAM. That value is a constant compiled into the image, and it differs between the three members because their SRAM differs: a 128-byte part, a 256-byte part and a 512-byte part do not share a RAMEND.
So the first few instructions of a valid image contain an immediate that identifies the member. Load it out, look at the value, compare against the three possible RAMEND figures, and the question «which part is this» is answered from the image itself. It costs one minute and it does not depend on the adapter, the cable or the operator.
The same logic works in reverse, which is where it earns its keep. If the initialisation constant says 256 bytes of SRAM and the BOM says ATtiny85, the image did not come from the part the customer believes is on the board. That happens more often than it should, usually because a prototype was reworked and the documentation was not.
Reading order that avoids rework
The sequence that keeps a job from being repeated:
| step | what it establishes | cost of skipping |
|---|---|---|
| read the signature | the interface works at all, and the family | hours spent on a wiring fault blamed on protection |
| read the word count the part should have | expected image length | a wrap mistaken for corruption |
| check for a repeated half | whether the part is smaller than assumed | a wrong part number in the report |
| extract the stack pointer constant | which member, independently | a report that contradicts the BOM |
| read the full array | the image | — |
The first two steps take under a minute and settle the majority of disputes about whether a read succeeded.
Lock bits on this family
The lock bits here are the two-bit arrangement common to the small AVR parts: one setting disables further programming of the flash and EEPROM while leaving verification available, the next disables verification as well. The distinction matters because the first state still permits a read through the ordinary interface, and a customer who reports a «locked» part is often describing the first state rather than the second.
The erase that clears those bits also clears the flash array. There is no state in which the protection is removed and the contents survive, so a request framed as «unlock it and keep the code» has no solution at the interface level. The contents have to come from the silicon.
What the deliverable contains
A complete job on this family returns the flash image as an Intel HEX file with the correct length for the identified member, a disassembly annotated with the peripheral addresses actually referenced, the EEPROM contents as a separate file because it is a separate address space, the fuse and lock state as read, and a short note recording the signature and the stack pointer constant that established the identity. The last item is not padding. It is the evidence that the image belongs to the part the report names.
Where the sibling with more flash needs the same treatment, ATtiny85 software recovery continues with the cases that only appear at 8 KB. The smallest member’s pin constraints are covered in ATtiny25 flash recovery, and the low-voltage variant’s electrical limits in ATtiny45V program recovery.
FAQ
Can the three be told apart without reading the code? Yes, from the signature, which the interface reports on request and which does not consume flash addresses. The stack pointer constant is the independent second opinion.
Is a dump that ends in 0xFF incomplete? Not necessarily. Erased flash reads as 0xFF, so a tail of 0xFF is consistent with several different situations and proves nothing either way.
Does a locked part still respond to the interface? It responds, and it refuses the specific operations the lock state disables. Silence is a wiring or level problem, not a protection problem.
Conclusion
On a pin-compatible family the part number is a claim and the image is the evidence. The signature says which family answered, the requested word count says whether the interface respected the array boundary, and the stack pointer constant says which member the code was built for. Three cheap checks, in that order, and the expensive ambiguity is gone before any work begins.
ATtiny84: What a Complete Image Looks Like on a Fully Used Array
Small families are built by putting several memory sizes in the same package, and the smaller members occupy only part of the address map. That leaves an unimplemented tail which reads as FF — a harmless artefact once recognised, and a persistent source of confusion before it is.
This member is the largest of the fourteen-pin group, so its array is fully populated. There is no unimplemented tail. Every address in the map corresponds to real cells, which means a large FF region is now a claim about content rather than about the die.
The map, and why it matters
| Region | Content | Consequence of a gap |
|---|---|---|
| Vector table | Reset and interrupt entries | Device cannot be running the code you think |
| Start-up | Clock and peripheral configuration | Behaviour differs from the source you reconstruct |
| Application | The bulk of the logic | Missing functions, unresolvable calls |
| Tail | FF if the build is smaller than the part |
Normal, not a fault |
The fourth row is the one that changes meaning on a fully populated part. On a smaller sibling, FF at the top is expected. Here, FF at the top means the build did not use the space, which is common and worth stating explicitly in a report so that nobody later interprets it as truncation.
Four checks that establish completeness
The end-of-file marker. In a hex file, a missing terminator means truncation. Cheap to check, and it catches a partial write of the file itself rather than a partial read of the device.
The instruction encoding at the boundary. A file padded to a round length ends in FF, which is not a valid instruction. A file that ends in valid-looking code is telling you the real length is shorter than the file.
The vector table’s shape. On this family the reset vector is a jump, and the interrupt vectors follow at a fixed spacing. A table whose entries decode as valid jumps is aligned; a table that decodes as garbage is off by a byte or two.
Page-level double reads. Every page read twice, compared. A page that differs between passes was read at an inadequate margin, and its content is a hypothesis rather than data.
The four are independent, which is why doing all four is worth the few minutes. Each catches a different class of error, and a file that passes all four is defensible.
Why this family has no boot section
There is no self-programming path on these parts: no boot section, no boot lock bits, no SPM-based field update. The entire protection model is the two general lock bits.
That simplification is genuinely useful. There is no second container to reason about, no boot reset fuse to check, and no possibility that part of the program is privileged code in a separate region. The questions collapse to: is the array readable, and if not, what does the erase cost.
It also means a device cannot update itself. Any field update happens through the programming interface, which is why products built on this family tend to have a header on the board.
Lock state and what it changes
The four-state encoding applies as it does everywhere in the family: unlocked, mode 1 blocking programming, mode 2 and 3 blocking verification as well. In mode 1 the array is readable and the protection only prevents reflashing — a distinction worth making, because “protected” is often assumed to mean “unreadable” and does not.
For a device in mode 2, the only documented operation that opens it is the chip erase, which clears the array. There is no partial path, no page-level unlock, and no interface that behaves differently.
Reading the part properly
Power at the design rail, measured at the socket. Read signature and fuses before memory, because a part configured for a crystal that is not fitted will not run and therefore will not answer. Read the array in pages, twice each. Disassemble the vector table and confirm the reset vector lands where the code begins.
That sequence is unremarkable and it is also the one that produces a file nobody has to re-examine later. On a small, fully populated array the whole thing takes a few minutes, and the alternative — discovering three weeks later that the image was never verified — costs considerably more.
Related notes
- ATtiny44 and the debug interface — an observational alternative to a static read.
- ATtiny24 and high-voltage entry — what to do when the serial port is closed.
- ATtiny44V and clock fuses — the fuse that makes a good part look dead.
FAQ
Is FF at the end of the image a fault? On a fully populated part it means the build did not use the space. That is normal and should be stated in the report.
Does this part support a bootloader? No. There is no boot section and no self-programming path.
Can a mode 1 part be read? Yes. Mode 1 blocks programming, not verification.
Why check the vector table instead of the whole file? Because it is the only region with a known structure that fails visibly when misaligned.
Conclusion
Completeness is a claim that has to be tested, not assumed from file size. On a fully used array the tests are the terminator, the boundary encoding, the vector table, and page-level double reads — four independent checks that together turn a plausible file into a verified one.