4
votes

Recently been working a lot with flash ROM, and I've found consistently within both within the internal flash of a chip and even with external SPI flash devices, that sectors are usually sized in a pattern like so:

flash layout of an STM32F405/415

I'm curious as to why the starting address space has smaller sectors than the later addresses. My suspicion is that it's more convenient when using something like a bootloader. Since bootloaders are often less than 128k, this would allow the bootloader to be written to maybe the first 2 or 3 sectors. This enables the main space application to have more room to expand into since to program it, we need to start at the beginning of a new sector. If we had only 128k sized sectors, then we'd essentially be wasting 128k - bootloader_size in space.

Is my suspicion correct? Or is there another reason this is done? Really curious to know what the design decision is here.

2
@drescherjm Just figured those devs have had a good chance of coming across this as well. I'll remove the tags if you reckon it's inappropriate thoughCapn Jack
This may be a better question for electronics.stackexchange.comdrescherjm
It's definitely in between the two. I'll post there if I can't get anything here in a day!Capn Jack
BTW, I highly recommend removing the C++ and C tags because your question has nothing to do with those languages.Thomas Matthews
@ThomasMatthews removed, probably going to have to post this in electronics SE now that there'll be no traffic here lolCapn Jack

2 Answers

3
votes

Because not all STM32F40x/41x devices have the full 1 MB of flash memory described in this table. Some, like the STM32F410C8, have as little as 64 KB -- that is, just the first four 16 KB sectors. Reducing the sector size at the start of memory allows these devices to still have multiple sectors available to work with, without leading to an excessive number of sectors on larger devices. It also makes some small sectors available on all devices for applications like EEPROM emulation, which requires two distinct flash sectors to be allocated for its exclusive use.

2
votes

Typically, bootloader code performs:
1. Processor initialization.
2. Jumps to the application code.

Bootloader code is generally a lot smaller than the application code. The small segments allow for faster programming of the Flash, since many Flash have a minimum sector size that can be erased and programmed. The smaller the segment size, the faster it can be erased and reprogrammed.

Some Flash manufacturers place Bootloader segments either at the lower end or the upper end (or allow you to set it as you please).