tagprobe TODO
Fix the boot option bytes of a virgin STM32U375
A new STM32U375, straight from the factory, has its option bytes set so that it does not boot from flash. A tag built on one can be programmed correctly and still never run the image. Writing the option bytes fixes it, and no manual step should be needed. There are two routes; the first needs no host change.
Route 1, preferred: the firmware fixes its own option bytes
Every U375 tag image runs a startup routine that sets nSWBOOT0 = 0 and
nBOOT0 = 1 in FLASH->OPTR when they are not already so, then launches an
option-byte load. This works on a virgin part because the programmers never
reset into the image: after programming, program() in
src/lib.rs loads SP and PC from the flash vector table and
runs, so the image starts whatever the boot selection says. The register and
bit names used below are those of the U375 header in this tree
(FLASH->CR, SR, KEYR, OPTKEYR, OPTR).
A sketch was given on 2026-10-31. Before adopting it:
- Run it first. Put it at the top of
main(), beforepState, clocks or devices are touched.OBL_LAUNCHresets the part, so anything done before it is thrown away. On the next boot the check finds the bits set and does nothing more, so the write happens once per board. - Add the checks the sketch leaves out. Wait for
SR.BSYto clear before starting. Clear stale error flags inSRbeforeOPTSTRT. ReadOPTWERRand the other error bits afterBSYclears, and give up withoutOBL_LAUNCHif any is set. Bound theBSYwait. - The reset it causes. The option-byte load is a system reset, so the
backup registers, and with them
pState, survive it. Check that the boot path's reset-cause handling treats theOBLRSTFflag as harmless. - TrustZone stays off. The non-secure
CRcan make this change only whileTZEN = 0, as the bench tags read today (debugging a tag). - U375 only. The L4 tags have different boot rules and their own handling
of
PEMPTY(release procedure). - Verify on hardware. Program a virgin U375 board, power-cycle it, and
check it boots the image with
tag-test. Then readOPTRback to confirm the write happened once and not on every boot.
Route 2: the programmers write the option bytes
If route 1 is not taken, the host does it:
- Detect it. probe-rs can read the option bytes. Read them at connect, for a U375 target, and decide from them whether the boot selection needs changing. Leave a part that is already right untouched.
- Write them. Changing an option byte needs the flash and option unlock
sequences and an option-byte load. That may need a small SRAM-resident
program injected and run on the target, in the way
embedded/loadersruns its loaders. - Where it applies.
tag-flash program, and Tag Programmer's Program, which share this library. Say in each tool's output when the option bytes were changed. - Confirm the bits first. Take the boot-selection fields and their factory
values from the U3 reference manual and from a virgin part's read-back,
not from the L4, whose
nSWBOOT0andnBOOT0behave differently (release procedure, onPEMPTY). - Verify on hardware. Program a virgin U375 board, power-cycle it, and
check it boots the image with
tag-test.
Recorded 2026-10-31.