Visitor II
Nov 8, 2026 9:07 PM UTC
Question
STM32_Programmer_CLI can't flash secure flash on a provisioned/closed STM32H5 after DA unlock ("Fail to read NVM Size")
- 0 replies
- 213 views
Hi all,
I’m working with a provisioned STM32H533 (TZEN=1, DA unlocked with `per=eh`). I ran into a problem where `STM32_Programmer_CLI` v2.23.0 fails to program secure flash. It prints `Fail to read NVM Size`, then reports `File download complete` and exits with code 0. The actual data in secure flash doesn't change.
But the same command works fine in the Open state:
STM32_Programmer_CLI -c port=SWD mode=HotPlug ap=1 -vb 3 \
-w sec_flash_demo_s.elf -w sec_flash_demo_ns.elf -rstHere are some more details:
Setup
- STM32CubeProgrammer v2.23.0 (STM32CubeCLT 1.22.0), Ubuntu
- NUCLEO-H533RE, on-board ST-LINK (FW V3J17M10)
- Firmware based on the STM32CubeH5 V1.7.0 `NUCLEO-H533RE/STiROT_Appli_TrustZone` example
- TZEN=1, product state Provisioned (same result in Closed)
- DA unlocked with ST's sample DA keypair & certificate, `per=eh`
I attached the full log attached. I think the issues are:
1. The secure flash erase command goes through the non-secure controller (0x40022xxx):
w ap 1 @0x40022028 0x00000004 bytes Data 0x00000024 (NSCR = SER|STRT)
r ap 1 @0x40022020 0x00000004 bytes Data 0x00020000 (NSSR = WRPERR)- I think it should be writing through the secure flash controller (0x50022xxx):
- `NSKEYR` (0x40022004) should be `SECKEYR` (0x50022008)
- `NSSR` (0x40022020) should be `SECSR` (0x50022024)
- `NSCR` (0x40022028) should be `SECCR` (0x5002202C)
- `NSCCR` (0x40022030) should be `SECCCR` (0x50022034)
2. The program step sets `LOCK` (0x1) in `SECCR`, not `PG` (0x2). (Every quad-word write sets `PGSERR`):
w ap 1 @0x5002202C 0x00000004 bytes Data 0x00000001 (SECCR = LOCK)
w ap 1 @0x0C000000 0x00000010 bytes Data 0x464C457F
r ap 1 @0x50022024 0x00000004 bytes Data 0x00040000 (SECSR = PGSERR) The attached `flash_closed.py` is a workaround that I came up with. It uses pyOCD to erase & program through the controller that owns each address, per RM0481, and works on the same board in the same DA session:
./flash_closed.py -t stm32h533retx sec_flash_demo_s.elf sec_flash_demo_ns.elf
So that's a suitable short-term fix for me. Long-term, are updates needed to `STM32_Programmer_CLI` to write to the correct flash controller and set the correct SECCR bit?
