cancel
Showing results for 
Search instead for 
Did you mean: 

Confusion in understating the FLASH STRUCTURE OF M4

skuma.8
Associate III

Hii there

I am using STM32F410RB (M4). it has a flash of 128 KB divided into following 4  sectors

skuma8_0-1701225308073.png

My query is that I want to store and retain some non-volatile data in the flash. We can use the last few pages of the flash for this purpose. I have come across a few examples, and they achieve this by either erasing a page or a sector. While working with other microcontrollers, their flash architectures are described in a page format, with page sizes of 1 KB, 2 KB, or so on.

Now, the actual issue is writing something into the flash. The smallest section we can erase is either a page or a sector. Erasing the last sector in this microcontroller would result in using 64 KB, half the size of my actual flash, and I don't want that. I only need a space of 2 KB, which is more than enough for me.

Question 1: In this flash memory architecture, are the sectors also subdivided into pages? If yes, how can I get the details of the size and address of pages?

Question 2: If it is not subdivided into pages, is there any better way to not waste half of our flash and use only a few kilobytes from the last section of our flash?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

1) No, the F4 just has huge flash sectors, as shown. On the F4, a flash sector and a flash page are effectively the same. You can't erase less than an entire sector.

2) You can journal your settings so that you write them, say, 2kB at a time and only erase the page once it's full. When reading, you have to make sure you use the latest settings, so have a flag that makes them obsolete, or something else to tell which is the latest. This cuts down on flash erasing a lot.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

1) No, the F4 just has huge flash sectors, as shown. On the F4, a flash sector and a flash page are effectively the same. You can't erase less than an entire sector.

2) You can journal your settings so that you write them, say, 2kB at a time and only erase the page once it's full. When reading, you have to make sure you use the latest settings, so have a flag that makes them obsolete, or something else to tell which is the latest. This cuts down on flash erasing a lot.

If you feel a post has answered your question, please click "Accept as Solution".
skuma.8
Associate III

Thanks for the reply TDK

I have few more queries regarding the same, as per your statement mentioned above "a flash sector and a flash page are effectively the same. You can't erase less than an entire sector" we can't erase less than a sector or a page. 

Let's consider one another STM microcontrollers whose flash are organized in page format like below.

skuma8_0-1701231603042.png

Q1. here, we are getting multiple pages of size 2kb each, so technically if we will erase a single page here then we will be only erasing a single page of size 2kb, isn't it a better than erasing a sector of M4 architecture of size 64 kb. 

or do we need to erase the entire bank before re writing in this flash architecture? 

Q2. And in my actual configuration where i have flash architecture like below

skuma8_1-1701231947662.png

Suppose my program requires a flash size of 80 KB. After uploading it, my first three sectors will be fully occupied with the program, and 16 KB of sector 4 will also be used. Can I write and save my data from the 17th byte of sector 4 without erasing it, considering the flash is erased when we upload the program for the first time

Q3 Is it true that i can continue writing into the next address, but lets say an address X is already written and  if i want to write it again then can i overwrite the same address without erasing or will i have to erase the whole 4 sector? which will result in erasing actual program also?

TDK
Guru

> here, we are getting multiple pages of size 2kb each, so technically if we will erase a single page here then we will be only erasing a single page of size 2kb, isn't it a better than erasing a sector of M4 architecture of size 64 kb. or do we need to erase the entire bank before re writing in this flash architecture?

Correct. On the microcontroller you showed, you can erase a single 2 kB page. Not sure how to quality it as better or worse than erasing a 64 kB sector. It's just different. Regardless, the option to erase only 2 kB doesn't exist on the STMF4 series.

> Can I write and save my data from the 17th byte of sector 4 without erasing it, considering the flash is erased when we upload the program for the first time

(Guessing you meant 17th kB) Yes, you can write to that memory once and it will work. (Technically, you can write as many times as you want but you can only flip bits from 1 -> 0, not the other way around.)

> Is it true that i can continue writing into the next address, but lets say an address X is already written and  if i want to write it again then can i overwrite the same address without erasing or will i have to erase the whole 4 sector? which will result in erasing actual program also?

You can only flip bits from 1 -> 0, which means you can only effectively write once. Again, yes, you have to erase the entire sector and since that includes some of the program, that part of the program will be erased.

 

There is no way of getting around fundamental FLASH hardware limitations:

  • Memory can only be written once after being erased.
  • You cannot erase less than an entire page (or "sector" on the STM32F4).
If you feel a post has answered your question, please click "Accept as Solution".