STM32F101CB: Programming the Copy, Then Closing It
Duplication reads as a symmetric operation: take the content from one device and put it in another. It is not symmetric. The source is read once and the destination is written many times, under a constraint the source never imposed, because the destination has to end up in a state that forbids further writing.
That final state is what makes the procedure delicate. A protected device cannot be written. Writing requires opening it, and opening it erases it. Any work left undone at the moment the protection is applied is work that can only be redone from the beginning.
The state machine of a destination device
Every destination passes through the same four states, and the transitions are one-way in practice.
| State | Writable | Erasable | How you leave it |
|---|---|---|---|
| Blank, unprotected | Yes | Yes | Program it |
| Programmed, unprotected | Yes, within erased pages | Yes | Protect it, or erase and start again |
| Programmed, protected | No | Only by erasing everything | Nothing, permanently |
| Protected and damaged | No | Only by erasing everything | Discard the part |
The third row is the trap. A device that is programmed, protected and found to be wrong cannot be corrected. It can only be erased completely and programmed again from a blank state, which costs a full cycle and, on a production line, costs the fixture time that was budgeted for a single pass.
Why verification must precede protection
The obvious answer is that verification is cheaper before than after. The real reason is that the failure modes differ in kind.
Before protection, a failed verification is a repair: erase the affected page, rewrite it, verify again. After protection, a failed verification is a rejection: the device cannot be repaired, only reprocessed from blank.
That asymmetry is why the sequence is fixed:
- Erase the destination completely and confirm the erase, not merely issue it.
- Program the code region from the lowest address upward.
- Program the vector table, whether it lives in the code region or a separate page.
- Read back the full array and compare against the source image.
- Program the option bytes, including the protection setting.
- Cycle power and confirm the device starts.
Step four is the gate. Step five should be a separate operation that a person decides to run, not the last line of an automated script. A script that programs and protects in one pass gives no opportunity to notice a comparison mismatch.
The option byte step
The option bytes are a separate page with their own erase and program cycle, and the protection field is one byte within them. Two behaviours matter.
Writing the protection field takes effect on the next reset, not immediately. A device that has been programmed and protected still answers reads until it is reset, which can produce a confusing test result if the check is made too early.
Changing the protection field from the protected value back to the open value erases the array. That is the mechanism that makes the earlier states one-way, and it is worth verifying on a scrap device once so that the behaviour is known rather than assumed.
Reading back correctly
A readback comparison is only meaningful if it accounts for the parts of the array that are legitimately different.
Three regions differ between a source and a well-made duplicate:
- the option bytes, if the source was protected and the destination was just programmed,
- any region the source left erased, which the destination also leaves erased but which may read differently if the destination was not fully erased,
- any unit-specific field that the duplication process is supposed to change.
Excluding those three from the comparison and comparing everything else byte for byte is the standard. Comparing the whole array and treating every difference as an error produces so many false alarms that real errors get lost.
Batch work and the fixture
Production duplication adds a dimension that single-unit work does not have: the fixture. Three properties decide whether a batch run succeeds.
Power sequencing. The devices must be supplied in a defined order and held in reset until the fixture is ready. A device that starts executing before its programmer has taken control will run whatever the last operation left in it.
Isolation. Each position on the fixture must be electrically isolated during programming, or the programming signals of one position appear on the pins of another. On a multi-position fixture this is the most common cause of position-dependent failures.
Reset control. Each device needs an independent reset, because the protection change requires a reset to take effect and the verification needs to happen before it.
| Fixture property | Failure it prevents |
|---|---|
| Defined power sequence | Device running before the programmer is ready |
| Per-position isolation | Cross-talk between positions during programming |
| Independent reset | Protection applying before verification |
| Per-position current limit | A damaged device taking the whole rail down |
What makes a duplicate correct
Beyond the bytes, three properties define a usable duplicate:
It runs. Not merely that the verification passed, but that the device reaches its application after a power cycle with the protection applied.
It behaves. Outputs match the source under the same inputs, which on this family usually means checking the serial traffic and the timing of the first few operations rather than the whole program.
It is identifiable. Any unit-specific value the product reports is different from the source, so that the two cannot be confused in a log or on a network.
The third property is the one most often omitted, and it is the one that causes incidents after delivery rather than during testing.
Related reading
- STM32F101RB and what the label does not tell you — read the identity before planning a batch.
- STM32F101C4 and the cost of the irreversible step — the same constraint at a density where it matters more.
- STM32F103CB and verifying an image before it is written — the checks worth running on the source first.
FAQ
Can a protected device be reprogrammed without erasing? No. Opening it erases the array.
When does the protection setting take effect? On the next reset, not at the moment of writing.
Should programming and protection be one script? Better as two. The verification gate deserves a decision.
Why does one fixture position fail repeatedly? Usually lack of isolation or a shared reset line.
Conclusion
Duplication on this device is a sequence problem. Write while open, verify completely, protect last, reset, and confirm the device runs. The bytes are the easy part; the ordering is what separates a working batch from a shelf of bricks.