STM32 Hidden Flash
Many STM32 MCUs have more flash than the datasheet, and the MCU itself, claim. ST makes one die and sells it in several flash sizes. The smaller parts appear to be the same silicon, with only the specified part of the flash tested and guaranteed.
Warning: The extra flash is not tested or guaranteed by ST. It has worked on every part tested here, but it may be marginal or faulty on some parts. It is fine for experiments and hobby projects; never rely on it in a product.
Summary
| MCU | Specified | Actual | Device ID | Same die as | Tested by |
|---|---|---|---|---|---|
| STM32F103C8 | 64 kB | 128 kB | 0x410 | STM32F103xB | Blue Pill community[1] |
| STM32L432KB | 128 kB | 256 kB | 0x435 | STM32L432KC | STM32World (below) |
| STM32F407VE | 512 kB | 1 MB | 0x413 | STM32F407VG | STM32World (below) |
| STM32H723VE | 512 kB | 1 MB | 0x483 | STM32H723VG | STM32World (below) |
| STM32F030F4 | 16 kB | 32 kB | 0x444 | STM32F030x6 | Community[2] |
| STM32G030F6 | 32 kB | 64 kB | 0x466 | STM32G030x8 | Community[3] |
| STM32G473 (256 kB version) | 256 kB | 512 kB | 0x469 | STM32G473xE | Community[4] |
| STM32C011F4 | 16 kB | 32 kB (see caveats) | 0x443 | STM32C011x6 | Community[5] |
If you test another part, please let us know.
The sections below explain why, how to test a part yourself, and the full test logs.
Video
The hidden flash put to use as staging area for a secure firmware update (see Secure Firmware Upgrade Bootloader and Application#Staging in hidden flash):
The working theory is that every STM32 which shares a die with a larger part has the flash of the largest part.
The best indicator of a shared die is the device ID: the DEV_ID field of DBGMCU_IDCODE, shown as chipid by st-info --probe. Parts with the same device ID are the same silicon, and the only difference between them is how much of the flash has been tested and what the flash size register says.
Datasheets are a good hint, as most of them cover exactly one die. If we look at the STM32G474, the datasheet covers three flash sizes, and all of them have device ID 0x469:
Most likely, these MCUs all have 512 kB of flash even if some report having less.
Not every datasheet is one die
Some datasheets cover more than one die. The STM32F030 datasheet covers four flash sizes, but three different dies:
| Part | Specified flash | Device ID |
|---|---|---|
| STM32F030x4 | 16 kB | 0x444 |
| STM32F030x6 | 32 kB | |
| STM32F030x8 | 64 kB | 0x440 |
| STM32F030xC | 256 kB | 0x442 |
An STM32F030F4 has been found to have 32 kB of flash[2], which matches the largest part with the same device ID (the STM32F030x6), not the largest part in the datasheet. So the rule is: compare with the largest part with the same device ID, not with the largest part in the datasheet.
Caveats
- Not tested by ST. ST only tests and guarantees the specified flash[2][3]. Nobody outside ST knows whether some parts are sold as the smaller version because the upper flash failed testing.
- Code may not run from it. On an STM32C011F4, the full 32 kB could be read and written, but jumping to code in the upper 16 kB caused a hard fault[5]. Data storage is the safer use.
- Tools stop at the reported size. The flash size register holds the specified size, and STM32CubeProgrammer, STM32CubeIDE and st-flash respect it. With st-flash, the size can be overridden with
--flash=. - Beware of aliasing. Writing a single word above the official size and reading it back proves nothing if the upper addresses simply mirror the lower ones. Write random data to the whole range and compare it all, as in the tests below.
Testing your own MCU
This erases the entire flash.
- Run
st-info --probeand note thechipidandflashsize. - Find the largest part with the same device ID (the reference manual has a table, or see the stlink chip configs).
- Write random data of that size, read it back and compare:
dd if=/dev/urandom of=random.bin bs=1k count=1024
st-flash --flash=1024k write random.bin 0x8000000
st-flash --flash=1024k read random2.bin 0x8000000 0x100000
md5sum random.bin random2.bin
Change count, --flash and the read size to the size you are testing. If the checksums match, the flash is there.
The flash size register (the specified size in kB) is at:
| Family | Flash size register |
|---|---|
| STM32F0 | 0x1FFF F7CC |
| STM32F1 | 0x1FFF F7E0 |
| STM32F4 | 0x1FFF 7A22 |
| STM32G0, STM32G4, STM32L4 | 0x1FFF 75E0 |
| STM32C0 | 0x1FFF 75A0 |
| STM32H72x/H73x | 0x1FF1 E880 |
Test results
STM32L432KB
The STM32L432Kx is available with two different flash sizes. The STM32L432KB has got 128 kB while the STM32L432KC has got 256 kB. I recently created a USB "key" using the STM32L432. The reason for using this specific STM32 MCU was twofold:
- It is small
- It's got a built-in 48 MHz oscillator precise enough to use USB without an external crystal
Unfortunately, while I wanted the 256 kB version, only the 128 kB version was available.
The STM32 Blue Pill boards mostly use Chinese clone MCUs but there has been a lot of writing about the original ones having 128 kB of flash rather than the 64 kB specified by the datasheet. There is even a test tool available which can test for the hidden flash.
Inspired by this, I decided to test the STM32L432KB on my own board. As per the datasheet this processor is supposed to have 128 kB of flash ranging from 0x8000000 to 0x801FFFF.
Checking device
lth@ncpws04:~/tmp$ st-info --probe Found 1 stlink programmers version: V2J45S31 serial: 066CFF3933584B3043184346 flash: 131072 (pagesize: 2048) sram: 49152 chipid: 0x435 dev-type: STM32L41x_L42x
Notice that the device reports 128 kB of flash, as expected. Chip ID 0x435 is the STM32L43x/L44x die; st-flash labels it "STM32L41x_L42x", which is a naming error in its chip configuration.
Generating test data
First step is to create a 256 kB file with random data.
lth@ncpws04:~/tmp$ dd if=/dev/urandom of=random.bin bs=1k count=256 256+0 records in 256+0 records out 262144 bytes (262 kB, 256 KiB) copied, 0.0012241 s, 214 MB/s
Writing data to MCU
The random.bin file is of a size which should only be possible to flash on STM32L432KC.
First step is to flash normally:
lth@ncpws04:~/tmp$ st-flash write random.bin 0x8000000 st-flash 1.8.0 2024-09-02T10:30:01 INFO common.c: STM32L41x_L42x: 48 KiB SRAM, 128 KiB flash in at least 2 KiB pages. file random.bin md5 checksum: 5f7ebd5c822e7408e6279445eb1444a, stlink checksum: 0x01fe53dd 2024-09-02T10:30:01 INFO common_flash.c: Attempting to write 262144 (0x40000) bytes to stm32 address: 134217728 (0x8000000) 2024-09-02T10:30:01 ERROR common_flash.c: The size exceeds the size of the flash (0x00020000 bytes available) stlink_fwrite_flash() == -1
As expected this failed. The MCU reports 128 kB of flash and we attempt to write 256 kB. We can however instruct st-flash to ignore that and attempt to write the entire file:
lth@ncpws04:~/tmp$ st-flash --flash=256k write random.bin 0x8000000 st-flash 1.8.0 2024-09-02T10:30:26 INFO common.c: STM32L41x_L42x: 48 KiB SRAM, 128 KiB flash in at least 2 KiB pages. Forcing flash size: --flash=0x00040000 file random.bin md5 checksum: 5f7ebd5c822e7408e6279445eb1444a, stlink checksum: 0x01fe53dd 2024-09-02T10:30:26 INFO common_flash.c: Attempting to write 262144 (0x40000) bytes to stm32 address: 134217728 (0x8000000) EraseFlash - Page:0x10 Size:0x800 -> Flash page at 0x8008000 erased (size: 0x800 EraseFlash - Page:0x11 Size:0x800 -> Flash page at 0x8008800 erased (size: 0x800 ... EraseFlash - Page:0x7e Size:0x800 -> Flash page at 0x803f000 erased (size: 0x800 EraseFlash - Page:0x7f Size:0x800 -> Flash page at 0x803f800 erased (size: 0x800) 2024-09-02T10:30:29 INFO flash_loader.c: Starting Flash write for F2/F4/F7/L4 2024-09-02T10:30:29 INFO flash_loader.c: Successfully loaded flash loader in sram 2024-09-02T10:30:29 INFO flash_loader.c: Clear DFSR 2024-09-02T10:30:35 INFO common_flash.c: Starting verification of write complete 2024-09-02T10:30:37 INFO common_flash.c: Flash written and verified! jolly good!
That went well, with no errors reported.
Reading data from the MCU
To be absolutely certain, read the data back into a new file:
lth@ncpws04:~/tmp$ st-flash --flash=256k read random2.bin 0x8000000 0x40000 st-flash 1.8.0 2024-09-02T10:31:51 INFO common.c: STM32L41x_L42x: 48 KiB SRAM, 128 KiB flash in at least 2 KiB pages. Forcing flash size: --flash=0x00040000 2024-09-02T10:31:51 INFO common.c: read from address 0x08000000 size 262144
No complaints!
Compare data
Finally we can verify that the data read from the MCU matches the data we wrote to the MCU:
lth@ncpws04:~/tmp$ md5sum random* 5f7ebd5c822e07408e6279445eb1444a random2.bin 5f7ebd5c822e07408e6279445eb1444a random.bin
They are identical, so it is absolutely confirmed that this particular STM32L432KB is in fact a STM32L432KC which identifies as a STM32L432KB.
STM32F407VE
The STM32F407VE is sold with 512 kB but has 1 MB, the same as the STM32F407VG. The extra 512 kB are sectors 8-11 (4 × 128 kB) from 0x0808 0000. The same test in one go:
lth@nb7:~/tmp$ st-info --probe && dd if=/dev/urandom of=random.bin bs=1k count=1024 && st-flash --flash=1024k write random.bin 0x8000000 && st-flash --flash=1024k read random2.bin 0x8000000 0x100000 && md5sum random.bin random2.bin Found 1 stlink programmers version: V2J48S35 serial: 066DFF495454657287165222 flash: 524288 (pagesize: 16384) sram: 196608 chipid: 0x413 dev-type: STM32F4x5_F4x7 1024+0 records in 1024+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00555526 s, 189 MB/s st-flash 1.8.0-121-g8c34a4e 2026-08-05T18:17:03 INFO common_legacy.c: STM32F4x5_F4x7: 192 KiB SRAM, 512 KiB flash in at least 16 KiB pages. Forcing flash size: --flash=0x00100000 file random.bin md5 checksum: dcd4cae158a72174cf828026717b6d4b, stlink checksum: 0x07f88bb5 2026-08-05T18:17:03 INFO common_flash.c: Attempting to write 1048576 (0x100000) bytes to stm32 address: 134217728 (0x8000000) EraseFlash - Sector:0x0 Size:0x4000 -> Flash page at 0x8000000 erased (size: 0x4000) EraseFlash - Sector:0x1 Size:0x4000 -> Flash page at 0x8004000 erased (size: 0x4000) EraseFlash - Sector:0x2 Size:0x4000 -> Flash page at 0x8008000 erased (size: 0x4000) EraseFlash - Sector:0x3 Size:0x4000 -> Flash page at 0x800c000 erased (size: 0x4000) EraseFlash - Sector:0x4 Size:0x10000 -> Flash page at 0x8010000 erased (size: 0x10000) EraseFlash - Sector:0x5 Size:0x20000 -> Flash page at 0x8020000 erased (size: 0x20000) EraseFlash - Sector:0x6 Size:0x20000 -> Flash page at 0x8040000 erased (size: 0x20000) EraseFlash - Sector:0x7 Size:0x20000 -> Flash page at 0x8060000 erased (size: 0x20000) EraseFlash - Sector:0x8 Size:0x20000 -> Flash page at 0x8080000 erased (size: 0x20000) EraseFlash - Sector:0x9 Size:0x20000 -> Flash page at 0x80a0000 erased (size: 0x20000) EraseFlash - Sector:0xa Size:0x20000 -> Flash page at 0x80c0000 erased (size: 0x20000) EraseFlash - Sector:0xb Size:0x20000 -> Flash page at 0x80e0000 erased (size: 0x20000) 2026-08-05T18:17:21 INFO flash_loader.c: Starting Flash write for F2/F4/F7/L4 2026-08-05T18:17:21 INFO flash_loader.c: Successfully loaded flash loader in sram 2026-08-05T18:17:21 INFO flash_loader.c: Clear DFSR 2026-08-05T18:17:21 INFO flash_loader.c: enabling 32-bit flash writes 2026-08-05T18:17:36 INFO common_flash.c: Starting verification of write complete 2026-08-05T18:17:46 INFO common_flash.c: Flash written and verified! jolly good! 2026-08-05T18:17:46 INFO common_legacy.c: Go to Thumb mode st-flash 1.8.0-121-g8c34a4e 2026-08-05T18:17:46 INFO common_legacy.c: STM32F4x5_F4x7: 192 KiB SRAM, 512 KiB flash in at least 16 KiB pages. Forcing flash size: --flash=0x00100000 2026-08-05T18:17:46 INFO common_legacy.c: read from address 0x08000000 size 1048576 dcd4cae158a72174cf828026717b6d4b random.bin dcd4cae158a72174cf828026717b6d4b random2.bin
STM32H723VE
And we got another winner in the STM32H723VE. Sold with 512 kB but have 1 MB in actuality. Worth noticing that the H7 only have 128 kB pages.
lth@ncpws04:~/tmp$ (st-info --probe && dd if=/dev/urandom of=random.bin bs=1k count=1024 && st-flash --flash=1024k write random.bin 0x8000000 && st-flash --flash=1024k read random2.bin 0x8000000 0x100000 && md5sum random.bin random2.bin) 2>&1 | tee /tmp/flash.log Found 1 stlink programmers version: V2J48S35 serial: 066DFF495454657287165222 flash: 524288 (pagesize: 131072) sram: 131072 chipid: 0x483 dev-type: STM32H72x_H73x voltage: 3237 mV 1024+0 records in 1024+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00473775 s, 221 MB/s st-flash 1.8.0-217-g5ec9d51 2026-10-25T08:06:58 INFO common_legacy.c: STM32H72x_H73x: 128 KiB SRAM, 512 KiB flash in at least 128 KiB pages. Forcing flash size: --flash=0x00100000 file random.bin md5 checksum: 7b5fa446a281b4e3641a50f1a33376ac, stlink checksum: 0x07f758e4 2026-10-25T08:06:58 INFO common_flash.c: Attempting to write 1048576 (0x100000) bytes to stm32 address: 134217728 (0x8000000) -> Flash page at 0x8000000 erased (size: 0x20000) -> Flash page at 0x8020000 erased (size: 0x20000) -> Flash page at 0x8040000 erased (size: 0x20000) -> Flash page at 0x8060000 erased (size: 0x20000) -> Flash page at 0x8080000 erased (size: 0x20000) -> Flash page at 0x80a0000 erased (size: 0x20000) -> Flash page at 0x80c0000 erased (size: 0x20000) -> Flash page at 0x80e0000 erased (size: 0x20000) 2026-10-25T08:07:05 INFO flash_loader.c: Starting Flash write for H7 64/1048576 bytes written 128/1048576 bytes written ... 1048512/1048576 bytes written 1048576/1048576 bytes written 2026-10-25T08:07:23 INFO common_flash.c: Starting verification of write complete 2026-10-25T08:07:32 INFO common_flash.c: Flash written and verified! jolly good! 2026-10-25T08:07:32 INFO common_legacy.c: Go to Thumb mode st-flash 1.8.0-217-g5ec9d51 2026-10-25T08:07:32 INFO common_legacy.c: STM32H72x_H73x: 128 KiB SRAM, 512 KiB flash in at least 128 KiB pages. Forcing flash size: --flash=0x00100000 2026-10-25T08:07:32 INFO common_legacy.c: read from address 0x08000000 size 1048576 7b5fa446a281b4e3641a50f1a33376ac random.bin 7b5fa446a281b4e3641a50f1a33376ac random2.bin
References
- ↑ STM32F103C8 Diagnostics, Mecrisp Stellaris documentation, and STM32F103C8T6 flash memory size, ST Community.
- ↑ 2.0 2.1 2.2 STM32F030F4 with 32K of flash?, ST Community, and STM32F030 observations, Hardware by design.
- ↑ 3.0 3.1 STM32G030F6P6 says 32kBytes flash but practical test says 64kB, ST Community.
- ↑ My STM32G473 has wrong flash size?, ST Community.
- ↑ 5.0 5.1 STM32C011F4 FLASH size 32kB?, ST Community.
Miscellaneous Links
- STM32L432 Datasheet
- Bluepill Diagnostics Tool
- stlink chip configurations (device IDs and flash size registers)