ST72F321R9 Locked Memory File: S19, Intel HEX, or Raw
A ST72F321R9 locked memory file is the phrase customers use for the thing they want back, and it hides a decision that gets made badly more often than any technical choice in the job. The decision is which container to deliver the bytes in, and it is made badly because it looks cosmetic. It is not cosmetic. The container is the only part of the delivery that carries address information, and without address information the bytes are not a memory file at all.
This article is about the three containers in common use for parts like this, what each one guarantees, and why the choice should be made from the customer’s toolchain backwards rather than from habit.
The file is part of the deliverable
There is a persistent assumption that the recovery ends when the bytes are correct. It does not. The recovery ends when someone can load the result into a programmer, or a disassembler, or a comparison tool, and have it land where it belongs.
That last clause — where it belongs — is entirely the container’s job. Raw bytes have no opinion about their own address. A disassembler handed raw bytes has to be told a base, and if the base is wrong the output looks plausible and is wrong everywhere.
| container | carries addresses | carries a checksum | carries a start address |
|---|---|---|---|
| raw binary | no | no | no |
| Intel HEX | yes, per record | yes, per record | sometimes, via a type-05 record |
| Motorola S19 | yes, per record | yes, per record | yes, via S7/S8/S9 |
| binary plus sidecar | no, but documented | in the sidecar | in the sidecar |
Three formats, three philosophies
Intel HEX records everything as text lines beginning with a colon, each carrying a length, an address, a record type, the data and a checksum. It was designed for a world where memory was addressed in 16 bits and files were transmitted over serial links that could corrupt them, so every line is independently verifiable and independently recoverable.
S-record format does the same job with a different vocabulary: a leading S, a record type that encodes the address width, a byte count, the address, the data and a checksum. Its advantage is that the record type states the address width explicitly, so a reader knows immediately whether it is dealing with 16, 24 or 32-bit addressing.
Raw binary says nothing and trusts the reader completely. It is the fastest to load, the smallest on disk, and the only one that becomes unreadable when it is separated from its documentation.
What a 16-bit address space does to S19
The device in question addresses 64 KB. Every valid address fits in sixteen bits, including the vector table at the very top, because 0xFFE0 is still a sixteen-bit number.
That makes S1 records — the sixteen-bit data record — a perfect fit, and it makes the S9 termination record the correct choice, because S9 explicitly means “this file used sixteen-bit addressing”. A file that uses S2 or S3 records for this device is not wrong, but it is carrying information that does not exist and it will confuse a simple loader.
| record | address width | appropriate here |
|---|---|---|
| S0 | none, header text | yes, as a comment |
| S1 | 16 bit | yes, the main content |
| S2 | 24 bit | unnecessary |
| S3 | 32 bit | unnecessary |
| S5 | none, record count | yes, useful sanity check |
| S9 | 16 bit termination | yes, correct terminator |
The S5 record is worth keeping for a reason that has nothing to do with the device. It states how many data records the file should contain, so a truncated file can be detected without comparing against a reference. For a recovered image, where the reference may not exist, that self-check is valuable.
Checksums: detecting versus proving
Both text formats carry a per-record checksum, and both are computed as a simple arithmetic sum with a complement, differing only in which complement. Neither is cryptographic, and neither proves anything about the device. What they do is catch transcription and transmission errors, which is exactly what they were designed for.
| format | checksum rule | catches | does not catch |
|---|---|---|---|
| Intel HEX | two’s complement of the byte sum | a corrupted line | a whole file of the wrong content |
| S-record | one’s complement of the byte sum | a corrupted line | a whole file of the wrong content |
| raw binary | none | nothing | everything |
The distinction matters when a customer reports that a delivered file “fails the checksum”. If the tool is checking per-record checksums, the file is corrupt in transit. If the tool is comparing a computed hash against a value the customer expects, the file may be perfectly well-formed and simply not match what they expected, which is a completely different conversation.
Why the base address is the fragile part
Everything above is mechanical. The fragile element is the mapping between the first byte of the file and the address it belongs to.
On this family the flash ends at 0xFFFF and begins at an address determined by capacity, so the base is not zero and not a round number that anyone would guess. A raw file delivered without its base, or an S-record whose addresses were generated relative to zero rather than relative to the map, will load into the wrong place and produce a device that does not run.
The failure is quiet. The bytes are right, the length is right, the checksum over the file is right, and the device is bricked because the reset vector ended up at 0x00FE instead of 0xFFFE.
Choosing a format for the customer’s toolchain
The right question is not “which is best” but “what will open it”. A production programmer usually accepts all three. A disassembler usually prefers raw plus a base. A comparison tool usually wants raw. A customer’s archive usually stores whatever their original compiler emitted, which for a part of this vintage is very likely S19.
| recipient | format that works with least friction |
|---|---|
| production programmer | S19 or Intel HEX, both fine |
| disassembler or analysis tool | raw binary plus a documented base |
| automated comparison against a known build | raw binary |
| customer archive matching their original build flow | whichever their toolchain emitted |
Asking which one they want takes one email. Guessing takes one support cycle, and support cycles on this kind of job tend to end with a request for a second delivery.
The sidecar that makes raw safe
When raw binary is the right answer, the safety comes from a short companion text file containing four lines: the base address, the length in bytes, the checksum of the whole image, and the contents of the vector table with the reset vector called out.
That last item is what turns a blob into a verifiable artefact. Anyone can check that their recovered vector table matches the one in the sidecar, and if it does not, they know immediately that either the base is wrong or the file is not the one they think it is.
The base-address argument itself is worked through in ST72F32AJ1 flash memory binary, and the length-mismatch question that customers raise when the file does not match the datasheet capacity is covered in ST72F325S6 embedded flash binary file. Where the question moves from the container to the tool that produced it, ST72F325R9 flash memory software readout picks up the thread.
What a complete delivery contains
Four things, and they are cheap. The image in the requested format. The map that makes it interpretable: base, length, vector table. A statement of how it was obtained, so the recipient knows whether to trust it absolutely or conditionally. And a per-block read status, so that any region of lower confidence is identifiable rather than averaged into a single “complete” claim.
A file without the other three is not a deliverable. It is a bet that the recipient will not need to ask any questions, and on a job where the device has already been through a protection bypass, that bet rarely pays.