PostHeaderIcon R5F21336TNFP: One Byte at the Top of the Map Decides the Rest

A R5F21336TNFP MCU flash program job that begins with a device refusing to respond is rarely a device with a broken array. It is usually a device whose configuration was set to refuse, by someone who had a good reason at the time and did not consider that the unit would one day need to be read.

The configuration in question occupies an extremely small amount of memory. On this family it sits near the top of the map, immediately below the region where the special-page vectors live, and it is evaluated at a point in the boot sequence that precedes every command the outside world can issue. It is, functionally, the first thing the device decides.

Where the decision is stored

The option byte region is small enough to describe by its position rather than its size: it occupies the last programmed location or two before the top vector block. That position is not arbitrary. Putting it at the top means it moves with capacity, so the same offset holds the configuration on every member of the group regardless of how much flash the part carries.

location content evaluated when affects
low fixed vectors reset and interrupt entry points immediately after reset where execution goes
code region the application when called nothing about access
option bytes configuration, including access permission before the first command whether a session exists at all
top vector block special-page vectors on the relevant interrupt nothing about access

Reading the table from the bottom up gives the boot order in reverse. The device consults the option bytes early precisely because they determine what kind of device it is going to be for the rest of the power cycle.

Why the decision precedes the first command

The sequencing is a design statement. If the device accepted commands and then applied a filter to the results, a bug in the filter would leak the array a fragment at a time. By deciding at boot, the device never has to trust its own filtering logic, because the logic only runs when the outcome is already known.

This is good for the customer and awkward for recovery. It means a refusing device is refusing cleanly: the array has not been touched, no partial state has been created, and the refusal carries no information beyond itself. It also means there is no sequence of commands that will gradually reveal more, because every command is behind the same gate.

What the byte contains, conceptually

The region is best understood as a set of independent switches rather than a single lock. Each switch governs a behaviour: whether the serial session is permitted, whether the array can be written through the session, whether the device’s own code can rewrite flash at runtime, and how the device behaves at startup with respect to the watchdog and the clock.

switch when on when off
serial session permitted the ROM listens and answers the ROM stays silent
session write permitted programming and erase available read-only session
self-programming permitted the application can rewrite flash the application cannot
startup behaviour the device follows one power-on path it follows the other

The switches are written once, at production, and thereafter they are just data in the array. Changing them requires exactly the same access that they are designed to prevent, which is the elegant part of the design and the frustrating part of the job.

The default state is permissive

Almost every device that arrives for recovery has the permissive default, because the default is what the part ships with and because production lines rarely change it. A customer who sets the protection byte is a customer who thought about it, and that thought usually came from a contract manufacturer or an end customer asking for it.

The practical consequence is that “locked” in an email usually does not mean the option byte is set. It means the identity bytes are personalised, or that the person writing the email has assumed the worst. The diagnostic order should be identity first, because it is cheaper to test, and option bytes second.

Configured is not the same as damaged

The two states look identical from the outside: the device does not answer. They are treated very differently by the person holding it, and confusing them has a cost.

A configured device is intact. Its array is unmodified, its package is undamaged, and it will run normally if powered in a circuit. A damaged device may or may not still run, and the damage may be in the array, in the clock, or in the supply. The first deserves a session once the gate is opened. The second deserves an investigation before anything is attempted.

The test that separates them requires no tools beyond a known-good circuit: put the device back in a working product, or in a fixture built for the purpose, and see whether it runs. A device that runs is configured, not damaged. A device that does not run has a problem that a session would not have fixed anyway.

This test is skipped more often than it should be, and the cost of skipping it is a device that gets decapsulated when a two-wire session would have sufficed.

Reading the option bytes when the option bytes forbid reading

The circularity is real but not absolute. Three routes exist, and they differ in cost rather than in principle.

The first is a device from the same production batch that was never protected. Its option bytes are the factory default, which tells you what the protected unit would have contained before the byte was changed, and that is often enough to plan the recovery.

The second is the customer’s own programming file. Production tooling writes the option bytes as part of the image, so the value is in the archive even when the device will not disclose it.

The third is the physical route, and it is the only one that reads the actual byte from the actual device. It is also the only one that should be described as breaking protection rather than as recovering a device.

route what it establishes what it costs
an unprotected sibling unit the default value a phone call
the production image the value that was programmed a file request
the device itself, physically the value that is actually there a destroyed sample

What the customer learns about their own flow

A recovery report that states “the option byte was at its default value” is telling the customer something about their manufacturing process. Either the protection was never enabled, in which case their intellectual property has been exposed on every unit they ever shipped, or it was enabled on a different batch, in which case their documentation and their production are out of step.

Neither conclusion is comfortable, and both are more useful than the binary file. The neighbouring articles cover the adjacent mechanics: R5F21324CNSP flash program recovery describes the serial session that this byte governs, and R5F212AASDFP memory data covers the identity check that runs alongside it. Where the byte has been left permissive and the array is simply difficult to read, R5F21292SDSP deals with the block-level behaviour.

Comments are closed.