48и. Production flashing: fixtures and bed-of-nails testers, firmware protection (RDP, WRP, option bytes, unique ID), serial numbers and the log
In 48ж the firmware was written by a standalone box, in 48з by an adapter with a script. Both sections answer the question "what to flash with". The question here is different: how to put flashing on a production line so that a hundred boards an hour come out identical, protected, with a unique number and with a log line for each.
This section covers: test pads and the bed-of-nails fixture; the sequence of operations on one board — from the power check to the log line; option bytes and protection (RDP, WRP, BOR); the unique chip ID, the serial number and binding keys to it; the log; how to recover a board stuck in RDP level 1; a Python throughput model for one to four fixtures; pitfalls.
What is not repeated here: the internals of a standalone programmer and SWIM — 48ж; adapters, command-line tools and a simple script with a serial number — 48з; why RDP level 1 on F1 does not protect the firmware from extraction — 11в; the SWD protocol and connecting under reset from the inside — 35д.
Sources (topics only, no retelling of the text): ST reference manuals for STM32F1, F4 and L4 (the sections on option bytes, read and write protection, the unique ID), the STM32CubeProgrammer manual (option byte commands), ST board design recommendations for the debug connector, general in-circuit test practice. Operation times are model assumptions, not measurements.
Terms used in the documentation
Term Meaning test point, test pad a contact pad for a fixture needle bed of nails fixture a needle fixture, the "bed of nails" pogo pin, spring-loaded probe a spring-loaded needle tooling holes, keying locating holes and protection against wrong placement WRP on bootloader and serial page write protection of the bootloader and the serial number page brown-out reset level (BOR) the reset threshold on a supply drop unique device ID (UID, 96 bits) the factory unique number of the chip serial number in OTP a serial number in the one-time programmable area first-pass yield the share of good boards on the first pass traceability log the traceability log
48и.1 Pads and the fixture
In production nobody plugs a cable with a connector into the board: it is slow, and a connector takes space. Instead, test pads are routed on the bottom side of the board, and the board is placed into a fixture with spring-loaded needles. The operator closes the lid — the needles press on the pads, the station flashes and tests, the lid opens.
Which pads are needed. SWDIO, SWCLK, NRST, GND, target power, plus lines for the functional test: the firmware UART, a couple of GPIO pins, supply test points after the regulator. Ground goes to two or three pads — a needle has resistance, and a single ground needle shifts levels under the board current.
Size and pitch. A needle pad is round, about 1 mm in diameter, without solder mask and without a via; the pitch between pads is at least 2.54 mm, more is better. Pads go on one side of the board and away from tall components: the needle needs straight access.
Locating and mistake-proofing. The board has two tooling holes in different corners, the fixture has pins for them. Holes of different diameter or an asymmetric layout prevent placing the board rotated — that is the keying. On a panel (several boards in one blank) the whole panel is located.
Resistance and wear. A spring-loaded needle is not a wire: the contact is tens of milliohms, and it grows as the tip wears and the pad gets contaminated with flux. Needle life is on the order of hundreds of thousands of presses, but with dirty boards it is shorter. A sign of wear is a growing number of "no connection" failures and a voltage drop on the power needle. Needles are replaced by a press counter, not after a failure: the station keeps the counter itself.
Target power from the fixture. The station supplies power through a current limiter and measures it first. A short circuit on the board shows up in the current within the first hundreds of milliseconds — the board goes straight to reject, without a flashing attempt. The reference voltage for the adapter (VTref, 48з.5) is taken from the same target power pad.
48и.2 The sequence of operations on one board
Every step is a check that can fail. If a step fails, the board goes to reject with the step code, not as "broke somewhere".
- Power check. Apply power with a current limit, measure the current and the voltage after the regulator. Outside the window — fail.
- Connect under reset. The adapter holds NRST, connects and halts the core before the first instruction (48з.5). A new board is blank, but a board on a repeat pass may have received firmware that disables SWD.
- ID check. Read DBGMCU_IDCODE and the Flash size. If the wrong chip or a substitute was soldered, the station learns it before writing.
- Erase, program, verify. Full erase, image write, verification by reading back or by CRC. The station computes the image checksum in advance and writes it to the log.
- Option bytes. BOR, the watchdog, WRP and at the very end — RDP (48и.3). The order matters: after RDP level 1 the adapter can no longer read the Flash.
- UID. Read the 96-bit unique ID of the chip (48и.4).
- Serial number and key. Write to OTP or a dedicated page.
- Functional test. Reset, the firmware starts, answers over UART with its version, its UID and the self-test result; the station checks the pins.
- Log line. One line per attempt, successful or not.
The list shows the logic of the checks, not a mandatory write order: if the serial number and key go into Flash that WRP and RDP will close, steps 6 and 7 are done before those bytes are written. The station script does it this way: UID and number right after the image is verified, option bytes last before the test.
48и.3 Option bytes: RDP, WRP, BOR
Option bytes are a separate area that the chip reads on reset. Writing to it is a separate procedure and takes effect after an option byte reload or a reset.
RDP level 0 — no protection, everything is readable. Not suitable for production.
RDP level 1 — the adapter connects but cannot read the Flash; running from RAM and the bootloader cannot read it either. It can be removed: going to level 0 erases the whole Flash. The board stays alive and can be reflashed — that is the main advantage of this level. How reliably it protects against extraction on particular series is a separate story, in 11в.
RDP level 2 — debugging is disabled forever, the option bytes can no longer be changed. There is no way back: no reflashing, no analysis of returns, no firmware update other than through your own bootloader. A bug in the image after level 2 turns the batch into scrap. Level 2 is set only if: the update bootloader is proven, the image passed the functional test on this very board, and losing diagnostics of returns is accepted deliberately. F1 has no level 2 at all.
A practical rule: the pilot batch and the first series — level 1; level 2 — when the product is stable and there is an over-the-air update or your own bootloader.
WRP — protection of pages or sectors against write and erase. It is set on the bootloader and on the page with the serial number and key so that a bug in the firmware or an update does not overwrite them. WRP is removed by writing the option bytes, so it is protection against accidents, not against an attacker.
BOR — the reset threshold on a supply drop. The default value is often low; for a 3.3 V board that writes Flash at run time the threshold is raised so that the core does not execute code or write Flash on a sagging supply. F1 has no configurable threshold.
Write order: BOR, watchdog and WRP first, verify by reading, and
RDP only last. In CubeProgrammer this is the -ob command with a list of
fields, for example -ob RDP=0xBB for level 1 — the exact field names and
values differ between series and require checking against the reference
manual and --help of the installed version.
48и.4 UID, serial number and keys
UID. STM32 has a 96-bit unique ID: three 32-bit words written at the factory. The address depends on the series (on F1 it is 0x1FFFF7E8, on F4 0x1FFF7A10, on L4 0x1FFF7590 — check against the reference manual). Inside are the die coordinates on the wafer, the wafer number and the lot. It is not a random number: neighbouring dies differ in few bits, and the UID is not a secret — anyone with firmware or a debugger can read it.
Serial number. Your own, human-friendly, sequential: it is printed on the label and read out over the phone. The UID is no good for that — it is long and inconvenient. The station issues the serial number, and the log keeps the "serial number ↔ UID" link.
Where to store it. There are two places:
- The OTP area — F4, L4 and many other series have one-time-programmable blocks with their own lock bit. What is written is not erased even by a full Flash erase — the number survives reflashing. F1 has no OTP.
- A dedicated Flash page — the last page or sector, closed by WRP. It is erased by a full erase, so when a return is reflashed the number is taken from the log by UID and written again.
Binding keys to the UID. If a secret is written into the board (an encryption key or a server authentication key), it must be unique to each board. A typical scheme: the board key is derived from a common factory secret and the UID (for example, an HMAC of the UID), and the server derives the same key from the UID. At start the firmware checks the stored data against its UID and refuses to work if they do not match: a Flash copy on another chip without the key of that chip is useless. The factory secret lives only in the station or on the issuing server and never gets into the image or the log.
48и.5 The log
The log is the only memory of production. It answers the questions "which firmware is in this return", "how many rejects at step 4 this week" and "who flashed the batch".
One line per attempt — CSV or a database, it does not matter:
time,station,operator,uid,serial,image,image_crc,step,result
2026-11-24T10:15:02,ST2,op07,0034001E3138510D35383236,10421,fw-1.4.2,0x5A3C91E0,9,PASS
2026-11-24T10:15:40,ST2,op07,0026002B3138510D35383236,,fw-1.4.2,0x5A3C91E0,4,FAIL_VERIFY
What matters:
- the log holds the number of the failed step, not just "FAIL": a reject at step 1 is assembly, at step 4 — the fixture or the chip, at step 8 — the circuit;
- the image CRC, not just the file name: a name can be overwritten, a CRC cannot;
- a serial number is issued only on PASS, otherwise there are gaps in the numbering;
- the line is written and flushed to disk before the operator opens the lid;
- keys and the factory secret are never in the log.
48и.6 A board stuck in RDP level 1
A typical situation: a board with RDP 1 came back from the field, or the station set RDP before writing the serial number. The adapter connects but cannot read or write the Flash.
Recovery procedure:
- Connect under reset — otherwise the firmware may disable SWD in time.
- Write RDP level 0 (
-ob RDP=0xAAin CubeProgrammer). The chip erases the whole Flash and after the option byte reload it is open. - Run the normal 48и.2 cycle again. The serial number in the Flash page is erased — take it from the log by UID instead of issuing a new one. A number in OTP has survived.
If the connection fails even under reset, the factory bootloader remains (48д): on most series it can remove read protection. Nothing can be recovered at level 2.
48и.7 Throughput: fixtures and the operator
Time per board is the machine time of the station plus the operator time: open
the lid, take the board out, put a new one in, close. The model48i.py model
adds up the per-step assumptions:
| Step | Time |
|---|---|
| power check | 1.0 s |
| connect under reset and ID | 0.5 s |
| erase, program, verify | 6.0 s |
| option bytes | 1.5 s |
| UID, serial number, key | 1.0 s |
| functional test | 8.0 s |
| log line | 0.2 s |
| total machine time | 18.2 s |
Board swap — 15 s, first-pass yield — 97 %. One fixture: 18.2 s of machine plus 15 s of operator, 33.2 s per board. While a fixture works, the operator can serve another one — the model assumes one operator for N fixtures, an 8-hour shift:
| Fixtures | Cycle | Boards per hour | Good per hour | Operator load | Good per shift |
|---|---|---|---|---|---|
| 1 | 33.2 s | 108 | 105 | 45 % | 841 |
| 2 | 33.2 s | 216 | 210 | 90 % | 1682 |
| 3 | 45.0 s | 240 | 232 | 100 % | 1862 |
| 4 | 60.0 s | 240 | 232 | 100 % | 1862 |
Conclusion: the second fixture almost doubles the output (108 → 216 boards per hour), while the third and fourth add nothing — the operator is the limit: 240 boards per hour is 3600 s divided by a 15 s swap. Beyond that, what helps is not more fixtures but a faster swap (a panel of several boards per lid press, a second operator) or shorter machine time — the functional test here takes longer than flashing.
48и.8 Pitfalls
"No connection" failures grow towards the end of the shift. Flux on the pads and needle wear. Scheduled fixture cleaning and a press counter.
The board flashed but is silent in the functional test. The option bytes differ from the reference (watchdog, BOR, boot selection); compare them with a reference board.
RDP was set before the serial number. Writing the number into protected Flash is impossible; recover the board via 48и.6. The step order is hard-coded in the station script, not kept in the operator's memory.
Duplicate serial numbers. Two stations issue numbers independently. Numbers come from one server, or each station has its own range.
The serial number disappeared after a full erase. It was in a Flash page, not in OTP. Restore it by UID from the log.
The UID was used as a key. The UID is not a secret — a key derived from the UID alone can be forged. A factory secret is needed (48и.4).
The board was placed rotated — and burnt. No keying; make the tooling holes asymmetric.
A batch with a bug went out at level 2. Level 2 is set only after the functional test on the same board and with a working update path.
48и.9 Summary
- Instead of a connector — needle pads: SWDIO, SWCLK, NRST, power, several grounds and test lines; tooling holes against wrong placement.
- Needles wear out: a press counter and cleaning, not replacement after failure.
- The chain per board: power → connect under reset → ID → program and verify → UID → number and key → option bytes (RDP last) → test → log; a failure carries the step number.
- RDP 1 is reversible with an erase, RDP 2 is forever; WRP protects against accidents, BOR against writes on a sagging supply.
- The 96-bit UID is not a secret; the board key comes from a factory secret and the UID.
- One operator with a 15 s swap hits 240 boards per hour: the second fixture gives 216, the third adds nothing.
Next: section 48к "Recovering a bricked board" — what to do when a board stops answering the programmer: SWD disabled, sleep, RDP, wrong option bytes.