Why can I read and write flash memory beyond 0x0810 0000 in an STM32F427VG chip with only 1MB of flash?
Hi all,
I have a project running on an STM32F427VI that makes some specific use of the dual-bank flash, both for storing certain configuration parameters and for a custom bootloader.
It's great, but I don't get anywhere near using the full 2MB of flash memory, so given difficulties in finding chips I'd like to be able to use the STM32F427VG chip, with 1MB of flash, instead.
I see that if the DB1M option bit is set, I can use the flash of the 1MB chip in dual-bank mode with a layout similar to the 2MB chip, which is perfect.
So I got a 1MB chip and soldered it to the board. For fun, I programmed it with my existing bootloader and application and ... it worked?
This is surprising, because the bootloader process uses flash that is beyond the 0x0810 0000 (1MB) boundary. If I connect to the chip using ST-LINK, it correctly shows the 1MB flash size, and if I go to "Erase Sectors ..." it correctly shows the 1MB single-bank flash layout. But in my code, at various times I erase flash sectors > 11 (which don't exist given that the DB1M option is in its default state of not being set) and even FLASH_SECTOR_23 (which doesn't exist in any documented configuration of this chip). Even more surprising, using ST-LINK I can read and write to flash addresses beyond the 0x0810 0000 boundary.
My existing code assumes the memory layout is as shown in Table 6 of RM0090, with 24 total sectors in two banks (0x0800 0000 - 0x080F FFFF, and 0x0810 0000 - 0x81F FFFF). For erasing flash, I use the FLASH_SECTOR_* macros in HAL, and hardcoded addresses. So if I look at Table 9 of the same document, my hardcoded addresses should be all wrong, and at least some of my flash sectors shouldn't exist. First I thought that the HAL code was doing some translation magic, but I don't see it anywhere, and ST-LINK also happily shows me the contents of flash address ranges that shouldn't exist. I also note that address 0x1FFF 7A22 of the VG chip correctly shows 0x0400 for the flash size.
I am assuming that either a) I am going insane, b) I am mistaken somehow, or c) I have won the ST lottery and received a bonus extra 1MB of flash in my 1MB chip, but I am hoping that the answer is (b) and someone here can point out where I am wrong.
Thanks!