PostHeaderIcon R5F21324CNSP: The UART Is the Only Door Left Open

Ask an engineer how to get inside an ARM part and the answer involves a debug port, a boundary-scan chain, or a vendor tool that speaks a documented protocol over a standard connector. Ask the same question about a R5F21324CNSP flash program recovery and the answer is a serial port. Not a debug port that happens to use serial framing: an actual asynchronous serial link, two wires, and a boot routine in ROM that decides whether to listen.

That single architectural fact shapes everything about how this device is recovered. There is no scan chain to interrogate, no register map that can be read without a session, and no vendor-neutral adapter that will do the job by being plugged in. There is a conversation, and the conversation has rules.

What a boot mode actually is

The device contains a small ROM routine that runs before any user code. On a cold start it examines its pins and decides which of two lives to lead. In one, it jumps to the user’s reset vector and the product behaves normally. In the other, it stays in the ROM, listens on two pins, and implements a fixed command set for reading and writing the array.

The decision is made early, before the user’s option bytes have any influence over the serial session, but not before they have influence over whether the session is permitted at all. Those are two distinct moments and conflating them is the source of most confusion about “protected” parts.

condition at reset what the device does what the tool sees
boot pin held in the programming state ROM routine, serial session a device that answers
boot pin in the run state user reset vector a device that does not answer, ever
boot pin correct, option bytes permit the session ROM routine, full command set a normal session
boot pin correct, option bytes forbid the session ROM routine, restricted or silent a device that answers wrongly or not at all
power ramp too slow for the window undefined, often user code intermittent, non-reproducible failures

The baud rate agreement

The session begins with a measurement rather than a setting. The host sends a known pattern, usually a run of zero bits, and the device times the pulse and derives the bit period from it. This is why the first exchange is tolerant of a host whose clock is imprecise and why the second exchange is not: once the device has chosen a divisor, it expects the host to hold that rate for the rest of the session.

The failure mode is worth describing precisely because it is so often misdiagnosed. A host whose actual rate differs from its nominal rate by a few percent will complete the handshake, because the handshake measures rather than assumes, and then fail on the first data frame, because the accumulated error over a longer frame exceeds what the receiver can tolerate. The symptom is a device that “starts to respond and then stops”, which reads like a device fault and is a host clock fault.

The remedy is to measure the host’s real rate rather than trust its configured rate, and to keep the link short and the ground solid. On a bench with a USB-serial adapter and a long clip lead, the ground return path is a more common culprit than the crystal.

The adapter is not the protocol

Because the physical layer is ordinary asynchronous serial, the vendor’s programmer is a convenience rather than a requirement. A generic adapter with the right logic levels, the right pin mapping and a host program that speaks the ROM’s frames will do the same job. What the vendor tool adds is the timing discipline and the pin sequencing, which is exactly the part that is hard to get right when improvising.

layer what it needs to be what is negotiable
electrical levels matched to the device’s supply domain the specific adapter model
timing reset released with the first frame ready to send the exact tool
framing eight data bits, no parity, one stop bit, at the measured rate the host software
protocol the ROM’s command frames and checksum convention nothing
mechanical a clip that holds during the whole session the fixture design

The mechanical row is underestimated. A session that takes minutes on a clip that shifts by a fraction of a millimetre produces the intermittent failures described earlier, and the resulting report says “device unstable” when the truth is “clip moved”.

The command set is small and fixed

The ROM implements a handful of operations: query status, read a block, program a block, erase a block, and verify or set an identity. Nothing else. There is no command to read arbitrary memory outside the array, no command to inspect registers, and no command that will tell you what the option bytes contain if the option bytes forbid the session.

operation what it touches what it can tell you
status query internal state only whether the device is listening and what it last did
block read one block of the array the block’s content
block program one block of the array whether the write completed
block erase one block of the array whether the erase completed
identity set or verify the identity field whether the presented value matches

The narrowness is a feature for recovery work, because it means the device cannot be talked into doing something unexpected. It is a limitation for diagnostics, because it means the only observable is the array itself.

Why there is no JTAG alternative

This family predates the assumption that every microcontroller has a standardised test access port. Its debugging and programming path is the same serial link described above, accessed through a vendor adapter that speaks the ROM’s protocol. There is no instruction register to shift, no daisy chain to walk, and no way to observe the core’s internal state without the core’s cooperation.

That matters when a device refuses the session. On a part with a scan chain, a refusal still leaves a channel for observing pins and reading boundary registers, which can distinguish a dead device from a locked one. Here, a refusal is total: the only remaining channel is the package.

When the option bytes close the door

The option bytes live at a fixed place near the top of the map, and one of their jobs is to state whether the serial session is permitted at all. Setting that bit is the difference between a device that can be recovered with a two-wire clip and a device that has to be opened.

The distinction has a practical consequence for scheduling. A session-based recovery can be planned in hours and does not consume the device. A package-level recovery has to be planned in days, destroys the sample, and produces a result whose quality depends on how well the map was established beforehand. Knowing which one applies is worth an hour of preparation.

The mapping argument that establishes where the option bytes sit is worked through in R5F212A7SDFA flash program, and the block-level reading behaviour that governs how much of the array a session can return is covered in R5F21292SDSP locked MCU flash. For a group where the option bytes have been set against a session, the R5F21336TNFP case describes what the one-byte decision looks like from the inside.

What the session gives you

A completed R5F21324CNSP flash program recovery over the serial link yields the array contents, block by block, with the device’s own acknowledgements as the only verification. That acknowledgement is weaker than a checksum computed on the host, so the host should compute one anyway and keep both records.

The session also yields something less obvious: a statement about the device’s configuration. If the session opened without difficulty, the option bytes were permissive, which tells the customer that their production flow did not enable the protection the part offers. If it required a specific identity, the identity is now known. Either way, the recovery result includes a fact about the customer’s process that they did not ask for and generally need.

Comments are closed.