5
\$\begingroup\$

I am writing data to the internal flash of a STM32F746 and I'm wondering what the difference between pages and sectors is? And what is the purpose of using sectors instead ? Notice that I'm very new and the reason to why I'm asking is because I have previously written to flash knowing the page size and amount of pages. But now I have 8 sectors instead.

Unless I have missed it somewhere I can't find any reference to pages or page size in any any document to the STM32F746

\$\endgroup\$

1 Answer 1

7
\$\begingroup\$

The concept is the same, between page and sectors. STM32F7 documentation uses the sector term because they are much bigger than the typical pages in external flash memory. But it doesn't matter.

So, you can't find reference to pages because what you called pages are here called sectors.

The constraint is: when you want to erase, you have to erase the whole sector. As you have seen, on STM32F7, there are 8 sectors, with different sizes (4 sectors of 32 Kbytes, 1 sector of 128 Kbytes, and 3 sectors of 256 Kbytes). The fact they have different sizes allow you to have more flexibility in the way you organize your flash. For example, you could have a sector reserved for configuration data. This way, when you want to reprogram this part, you don't have to erase the whole firmware code. But you still have to erase the whole configuration sector, even if you need to change just a single byte of it. And it is true these sectors are huge, so you can't use this flash as easily as typical external serial flashes on which you could organize things in a more flexible way (or even use a filesystem). But this is not the purpose of these embedded flash memories.

If you need a more flexible way to store persistent data that can change over time, use an external flash, or external EEPROM, depending on you constraints. There is, however, a trick you could use on the main MCU flash: the erase is required only when you switch bits from 0 to 1. To switch bits from 1 to 0, you just need to program the flash bytes (see the note in chapter 3.3.7 in the ref manual). Programming the flash bytes can be made as many times as you want on the sector, and can be made on individual bytes. So you could take advantage of this by dividing the huge "configuration" sector in small chunks that you program individually, when your data changes. Then, you need an index in which you "fuse" the bits from 1 to 0 to know in which chunk the latest data can be found. Finally, when all the chunks have been used, you erase the whole sector and start over. This wastes a lot of space, but may give you the flexibility you need without compromising too much on flash endurance.

\$\endgroup\$
6
  • \$\begingroup\$ What is the minimum number of physical sectors that you can run on? STM32F7 can also use a 23 sector arrangement. So is 4 enough? SPIFFS documentation talks about using a 2MB flash with 6kb sector size. \$\endgroup\$
    – tothphu
    Commented Apr 16, 2018 at 2:26
  • \$\begingroup\$ @tothphu The minimum number of sectors your system can run on? It's certainly 1, provided your system is simple enough. I'm not sure I understand the question. Anyway, this is another question and should be asked separately. Be sure to explain clearly what you want to achieve. \$\endgroup\$
    – dim
    Commented Apr 16, 2018 at 5:11
  • \$\begingroup\$ well yes, if you can hold the entire sector size in memory than 1 sector is enough. However, I think you can still use a filesystem on it, given you can have a few physical blocks. \$\endgroup\$
    – tothphu
    Commented Apr 17, 2018 at 21:28
  • \$\begingroup\$ @tothphu having a filesystem on an internal MCU flash seems very inadequate. Theoretically, you can, but given the organization with huge sectors and the endurance typically much lower than an external flash chip, I don't think you'll achieve what you expect. Just use an external flash. Internal flash is for code which almost never change, and eventually a bit of configuration data that change from time to time. Not for using it like a hard drive. \$\endgroup\$
    – dim
    Commented Apr 17, 2018 at 21:34
  • \$\begingroup\$ AFAIK STM32F7 has a 100k endurance on the flash (2MiB total). Also the erase block size is 128KiB (with the right configuration, and from ~256KiB upwards), while it can be 8 byte written (as opposed to ~256 bytes on external flash). Saving settings or alike can save you from extra hardware components. Also sometimes this is an afterthought, when HW modifications are undesirable. \$\endgroup\$
    – tothphu
    Commented Apr 24, 2018 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.