STM32L432Kx Flash Size

From Stm32World Wiki
Revision as of 05:18, 20 July 2021 by Lth (talk | contribs) (→‎Flashing)
Jump to navigation Jump to search
FidoKey rev. a - top view.jpg

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:

  1. It is small
  2. 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.

Testing

Generating Test Data

First step is to create a 128 kB file with random data.

lth@ncpws04:/tmp$ dd if=/dev/urandom of=random.bin bs=1k count=128
128+0 records in
128+0 records out
131072 bytes (131 kB, 128 KiB) copied, 0.00250461 s, 52.3 MB/s

Writing data to MCU

The random.bin file is of a size which can be flashed on both the STM32L432KB and STM32L432KC.

First step is to flash normal:

lth@ncpws04:/tmp$ st-flash write random.bin 0x8000000
st-flash 1.7.0-dirty
2021-07-20T12:14:31 INFO common.c: L43x/L44x: 48 KiB SRAM, 128 KiB flash in at least 2 KiB pages.
file random.bin md5 checksum: 9d3a763bd923a4c42ffe5fa434d6109, stlink checksum: 0x00ff70ec
2021-07-20T12:14:31 INFO common.c: Attempting to write 131072 (0x20000) bytes to stm32 address: 134217728 (0x8000000)
EraseFlash - Page:0x0 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08000000 erased
EraseFlash - Page:0x1 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08000800 erased
EraseFlash - Page:0x2 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08001000 erased
EraseFlash - Page:0x3 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08001800 erased
EraseFlash - Page:0x4 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08002000 erased
EraseFlash - Page:0x5 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08002800 erased
EraseFlash - Page:0x6 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08003000 erased
EraseFlash - Page:0x7 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08003800 erased
EraseFlash - Page:0x8 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08004000 erased
EraseFlash - Page:0x9 Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08004800 erased
EraseFlash - Page:0xa Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08005000 erased
EraseFlash - Page:0xb Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08005800 erased
EraseFlash - Page:0xc Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08006000 erased
EraseFlash - Page:0xd Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08006800 erased
EraseFlash - Page:0xe Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08007000 erased
EraseFlash - Page:0xf Size:0x800 2021-07-20T12:14:31 INFO common.c: Flash page at addr: 0x08007800 erased
EraseFlash - Page:0x10 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08008000 erased
EraseFlash - Page:0x11 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08008800 erased
EraseFlash - Page:0x12 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08009000 erased
EraseFlash - Page:0x13 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08009800 erased
EraseFlash - Page:0x14 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800a000 erased
EraseFlash - Page:0x15 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800a800 erased
EraseFlash - Page:0x16 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800b000 erased
EraseFlash - Page:0x17 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800b800 erased
EraseFlash - Page:0x18 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800c000 erased
EraseFlash - Page:0x19 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800c800 erased
EraseFlash - Page:0x1a Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800d000 erased
EraseFlash - Page:0x1b Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800d800 erased
EraseFlash - Page:0x1c Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800e000 erased
EraseFlash - Page:0x1d Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800e800 erased
EraseFlash - Page:0x1e Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800f000 erased
EraseFlash - Page:0x1f Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0800f800 erased
EraseFlash - Page:0x20 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08010000 erased
EraseFlash - Page:0x21 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08010800 erased
EraseFlash - Page:0x22 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08011000 erased
EraseFlash - Page:0x23 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08011800 erased
EraseFlash - Page:0x24 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08012000 erased
EraseFlash - Page:0x25 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08012800 erased
EraseFlash - Page:0x26 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08013000 erased
EraseFlash - Page:0x27 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08013800 erased
EraseFlash - Page:0x28 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08014000 erased
EraseFlash - Page:0x29 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08014800 erased
EraseFlash - Page:0x2a Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08015000 erased
EraseFlash - Page:0x2b Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08015800 erased
EraseFlash - Page:0x2c Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08016000 erased
EraseFlash - Page:0x2d Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08016800 erased
EraseFlash - Page:0x2e Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08017000 erased
EraseFlash - Page:0x2f Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08017800 erased
EraseFlash - Page:0x30 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08018000 erased
EraseFlash - Page:0x31 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08018800 erased
EraseFlash - Page:0x32 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08019000 erased
EraseFlash - Page:0x33 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x08019800 erased
EraseFlash - Page:0x34 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0801a000 erased
EraseFlash - Page:0x35 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0801a800 erased
EraseFlash - Page:0x36 Size:0x800 2021-07-20T12:14:32 INFO common.c: Flash page at addr: 0x0801b000 erased
EraseFlash - Page:0x37 Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801b800 erased
EraseFlash - Page:0x38 Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801c000 erased
EraseFlash - Page:0x39 Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801c800 erased
EraseFlash - Page:0x3a Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801d000 erased
EraseFlash - Page:0x3b Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801d800 erased
EraseFlash - Page:0x3c Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801e000 erased
EraseFlash - Page:0x3d Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801e800 erased
EraseFlash - Page:0x3e Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801f000 erased
EraseFlash - Page:0x3f Size:0x800 2021-07-20T12:14:33 INFO common.c: Flash page at addr: 0x0801f800 erased
2021-07-20T12:14:33 INFO common.c: Finished erasing 64 pages of 2048 (0x800) bytes
2021-07-20T12:14:33 INFO common.c: Starting Flash write for F2/F4/F7/L4
2021-07-20T12:14:33 INFO flash_loader.c: Successfully loaded flash loader in sram
2021-07-20T12:14:33 INFO flash_loader.c: Clear DFSR
2021-07-20T12:14:35 INFO common.c: Starting verification of write complete
2021-07-20T12:14:37 INFO common.c: Flash written and verified! jolly good!

That was to be expected. Now let us try to flash the next 128 kB of flash:

lth@ncpws04:/tmp$ st-flash write random.bin 0x8020000
st-flash 1.7.0-dirty
2021-07-20T12:15:41 INFO common.c: L43x/L44x: 48 KiB SRAM, 128 KiB flash in at least 2 KiB pages.
Unknown memory region

That fails because the st-flash util check the data reported by the MCU. Fortunately, this can be overwritten by the --flash option:

lth@ncpws04:/tmp$ st-flash --flash=256k write random.bin 0x8020000         
st-flash 1.7.0-dirty
2021-07-20T12:16:55 INFO common.c: L43x/L44x: 48 KiB SRAM, 128 KiB flash in at least 2 KiB pages.
Forcing flash size: --flash=0x00040000
file random.bin md5 checksum: 9d3a763bd923a4c42ffe5fa434d6109, stlink checksum: 0x00ff70ec
2021-07-20T12:16:55 INFO common.c: Attempting to write 131072 (0x20000) bytes to stm32 address: 134348800 (0x8020000)
EraseFlash - Page:0x40 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08020000 erased
EraseFlash - Page:0x41 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08020800 erased
EraseFlash - Page:0x42 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08021000 erased
EraseFlash - Page:0x43 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08021800 erased
EraseFlash - Page:0x44 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08022000 erased
EraseFlash - Page:0x45 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08022800 erased
EraseFlash - Page:0x46 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08023000 erased
EraseFlash - Page:0x47 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08023800 erased
EraseFlash - Page:0x48 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08024000 erased
EraseFlash - Page:0x49 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08024800 erased
EraseFlash - Page:0x4a Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08025000 erased
EraseFlash - Page:0x4b Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08025800 erased
EraseFlash - Page:0x4c Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08026000 erased
EraseFlash - Page:0x4d Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08026800 erased
EraseFlash - Page:0x4e Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08027000 erased
EraseFlash - Page:0x4f Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08027800 erased
EraseFlash - Page:0x50 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08028000 erased
EraseFlash - Page:0x51 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08028800 erased
EraseFlash - Page:0x52 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08029000 erased
EraseFlash - Page:0x53 Size:0x800 2021-07-20T12:16:55 INFO common.c: Flash page at addr: 0x08029800 erased
EraseFlash - Page:0x54 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802a000 erased
EraseFlash - Page:0x55 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802a800 erased
EraseFlash - Page:0x56 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802b000 erased
EraseFlash - Page:0x57 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802b800 erased
EraseFlash - Page:0x58 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802c000 erased
EraseFlash - Page:0x59 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802c800 erased
EraseFlash - Page:0x5a Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802d000 erased
EraseFlash - Page:0x5b Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802d800 erased
EraseFlash - Page:0x5c Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802e000 erased
EraseFlash - Page:0x5d Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802e800 erased
EraseFlash - Page:0x5e Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802f000 erased
EraseFlash - Page:0x5f Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0802f800 erased
EraseFlash - Page:0x60 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08030000 erased
EraseFlash - Page:0x61 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08030800 erased
EraseFlash - Page:0x62 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08031000 erased
EraseFlash - Page:0x63 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08031800 erased
EraseFlash - Page:0x64 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08032000 erased
EraseFlash - Page:0x65 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08032800 erased
EraseFlash - Page:0x66 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08033000 erased
EraseFlash - Page:0x67 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08033800 erased
EraseFlash - Page:0x68 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08034000 erased
EraseFlash - Page:0x69 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08034800 erased
EraseFlash - Page:0x6a Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08035000 erased
EraseFlash - Page:0x6b Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08035800 erased
EraseFlash - Page:0x6c Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08036000 erased
EraseFlash - Page:0x6d Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08036800 erased
EraseFlash - Page:0x6e Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08037000 erased
EraseFlash - Page:0x6f Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08037800 erased
EraseFlash - Page:0x70 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08038000 erased
EraseFlash - Page:0x71 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08038800 erased
EraseFlash - Page:0x72 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08039000 erased
EraseFlash - Page:0x73 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x08039800 erased
EraseFlash - Page:0x74 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0803a000 erased
EraseFlash - Page:0x75 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0803a800 erased
EraseFlash - Page:0x76 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0803b000 erased
EraseFlash - Page:0x77 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0803b800 erased
EraseFlash - Page:0x78 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0803c000 erased
EraseFlash - Page:0x79 Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0803c800 erased
EraseFlash - Page:0x7a Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0803d000 erased
EraseFlash - Page:0x7b Size:0x800 2021-07-20T12:16:56 INFO common.c: Flash page at addr: 0x0803d800 erased
EraseFlash - Page:0x7c Size:0x800 2021-07-20T12:16:57 INFO common.c: Flash page at addr: 0x0803e000 erased
EraseFlash - Page:0x7d Size:0x800 2021-07-20T12:16:57 INFO common.c: Flash page at addr: 0x0803e800 erased
EraseFlash - Page:0x7e Size:0x800 2021-07-20T12:16:57 INFO common.c: Flash page at addr: 0x0803f000 erased
EraseFlash - Page:0x7f Size:0x800 2021-07-20T12:16:57 INFO common.c: Flash page at addr: 0x0803f800 erased
2021-07-20T12:16:57 INFO common.c: Finished erasing 64 pages of 2048 (0x800) bytes
2021-07-20T12:16:57 INFO common.c: Starting Flash write for F2/F4/F7/L4
2021-07-20T12:16:57 INFO flash_loader.c: Successfully loaded flash loader in sram
2021-07-20T12:16:57 INFO flash_loader.c: Clear DFSR
2021-07-20T12:16:57 INFO flash_loader.c: Clear CFSR
2021-07-20T12:16:59 INFO common.c: Starting verification of write complete
2021-07-20T12:17:01 INFO common.c: Flash written and verified! jolly good!

Lo and behold - it appeared to have worked. The st-flash utility actually read back the data and verify that it was written correctly.

Reading data from the MCU

Miscellaneous Links