4

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.

VC.One
  • 14,790
  • 4
  • 25
  • 57
Capn Jack
  • 1,201
  • 11
  • 28
  • @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 though – Capn Jack Aug 06 '19 at 22:43
  • 3
    This may be a better question for https://electronics.stackexchange.com/ – drescherjm Aug 06 '19 at 22:44
  • It's definitely in between the two. I'll post there if I can't get anything here in a day! – Capn Jack Aug 06 '19 at 22:45
  • BTW, I **highly** recommend removing the C++ and C tags because your question has nothing to do with those languages. – Thomas Matthews Aug 07 '19 at 00:16
  • @ThomasMatthews removed, probably going to have to post this in electronics SE now that there'll be no traffic here lol – Capn Jack Aug 07 '19 at 00:18
  • Flash used for program memory is of a kind that is as physically compact as possible. I'm by no means an expert of how memories are designed in hardware, but there's some electrical reason why larger erase sectors allows better physical density. Traditional EEPROM with very small erase sectors is the best for things like storing run-time data, bootloaders etc, but it takes more space. Therefore MCU manufacturers move away from that, even if it makes it a pain to use flash for storing data. With 16kb erase size you'll essentially need to save 16kb to RAM while erasing - very slow. – Lundin Aug 07 '19 at 06:46

2 Answers2

3

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.

  • Your answers does a good job of pointing out _why_ smaller sectors are important on devices with little ROM. But it doesn't mention why larger devices still have small sectors at the beginning. Because the STM32F410C8 is in the same F4 family, is there some type of sector layout structure that all the children in this family must adhere to? I don't yet see why what you're saying about the STM32F410C8 chip is relevant – Capn Jack Aug 07 '19 at 01:40
  • 2
    "Is there some type of sector layout structure that all the children inthe family must adhere to?" The table in your question **is** that structure -- the smaller devices just leave off sectors from the end. The whole point of a device family is to minimize differences between devices in it -- changing flash layout in some devices would amount to splitting the family. –  Aug 07 '19 at 02:01
  • "The whole point of a device family is to minimize differences between devices in it -- changing flash layout in some devices would amount to splitting the family" this was missing for me. I get it now thanks. I feel this is the actual answer, and my observation is just a nice convenient perk. – Capn Jack Aug 07 '19 at 04:31
2

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).

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154