Author Topic: Filling flash with 0xFF  (Read 848 times)

0 Members and 1 Guest are viewing this topic.

Offline sanka1pTopic starter

  • Contributor
  • Posts: 26
  • Country: us
Filling flash with 0xFF
« on: June 13, 2024, 04:57:20 pm »
Hi Everyone,

I have a question, what is the use or advantage of option "Fill un-used flash with 0xFF"? In my case I am using IAR IDE and ATMEGA1608. I can see it being used to make checksum but what if my flash is not filled with 0xFF, checksum should still be there!


Thank you.
Using Analog in a Digital world.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11726
  • Country: us
    • Personal site
Re: Filling flash with 0xFF
« Reply #1 on: June 13, 2024, 05:36:20 pm »
This option fills gaps between sections with a known value. 0xFF is selected because it minimizes the flash wear. If your program has multiple sections with gaps between them, then programmers are free to leave the old data when programming that image. If you then calculate CRC as one big chunk, you will include that random data into CRC calculation, making it incorrect.
Alex
 
The following users thanked this post: sanka1p

Offline jzx

  • Regular Contributor
  • *
  • Posts: 84
  • Country: es
Re: Filling flash with 0xFF
« Reply #2 on: June 13, 2024, 05:52:39 pm »
Sometimes it is also to speed the burning. If after erasing all the bytes are FF, the programmer can skip these positions because burning a position is slow.
For one flash this time is not important, but for a factory making many it is.
 
The following users thanked this post: sanka1p

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 854
Re: Filling flash with 0xFF
« Reply #3 on: June 13, 2024, 11:06:22 pm »
Quote
This option fills gaps between sections with a known value. 0xFF is selected because it minimizes the flash wear.
Even though they would have to pick a value to use, and an erased value is a logical choice, I'm not sure flash wear would really enter the picture. The flash that gets erased/written every time at the very least would be the vector table, and it would not be a big win to have preserved some other flash locations while the vector table starts to fail. I would think it would be better to have every flash byte 'exercised' equally so they start to fail at the same time frame, giving you the max sample size of bytes as failure detectors. Probably makes little difference in most cases as one never approaches the flash writing limits by normal programming. If flash is used for runtime storage, then its on the app code to sort this out.

It seems to me this option would simply be for ranges of unused flash in pages otherwise left untouched by the programming process. In other words, if a flash page has code in it, it will be erased and any unused flash in that page will already be 0xFF.

For this avr, there is a choice the programming software can make- either program by pages or do a chip erase first then program the flash. It could simply be the ide has an option to do a chip erase disguised as 'fill unused flash with 0xFF', as a chip erase would be the easy way to do this.

One reason one may want to do this- you simply do not want remnants of previous code remaining in the mcu. If your currently loaded (flawed) code happens to get past the end of your app code for some reason, you end up in harmless instructions and will be able to detect the wrap-around (end up back at reset vector, startup code checks for any reset flag, if no flag you have a problem and are going to want to do a software reset). Also having a 'clean' mcu will mean anytime in the future you need/want to read the flash to see whats inside, you will not have to decipher pieces of code that are no longer part of the current app.

A reason to 'not' do a chip erase (fill with 0xFF), for this avr, would be if you have the avr setup to use the Application Data section. If you want to preserve that data between programming, you cannot do a chio erase as it would also erase that data. The programming software then most likely would do page programming, and the Application Data section would be untouched as its location will not have any code to program.

So, for this avr, I would do a chio erase (fill with 0xFF) unless I was making use of an Application Data section and I wanted that data preserved between programming. There could be other possible scenarios, but you will know when you are there.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11726
  • Country: us
    • Personal site
Re: Filling flash with 0xFF
« Reply #4 on: June 13, 2024, 11:22:19 pm »
Even though they would have to pick a value to use, and an erased value is a logical choice, I'm not sure flash wear would really enter the picture.
It depends on the size of those gaps. Generally erase block is bigger than the program block and some blocks may not need to be programmed at all. Although it obviously does not matter in real life.

it would be better to have every flash byte 'exercised' equally so they start to fail at the same time frame
Flash performance varies from block to block way more than any damage you can do by differential programming.

It just had to be some value, and 0xff is a natural choice.

It could simply be the ide has an option to do a chip erase disguised as 'fill unused flash with 0xFF'
The option is for the binary file output. It will either output a HEX file with multiple sections, or a single section file with gaps filled. And for raw binary files, the gaps would be filled anyway.

My personal preference is to always fill and pad the file size to the erase block size. This way you get consistent behavior across all programmers. It may not matter in absolute majority of the cases, but it eliminates a few cases where it matters.
Alex
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 854
Re: Filling flash with 0xFF
« Reply #5 on: June 14, 2024, 01:11:58 am »
Quote
Generally erase block is bigger than the program block
Though we are talking about a specific mcu here- the mega1608, which is erased either in page sizes or via a chip erase. Flash writing in this mcu is then done via a page buffer (from a single byte up to a page).

I don't use IAR, but it looks like they have this option in the Checksum section, with the option to set the fill byte to the value of your choice (so is not really 'fill unused flash with 0xFF', its just that 0xFF is already filled in as the default value), along with the option to enable checksum (can do either, both, or neither).

Basically, it makes no difference what you do up until you want to use the checksum, or have some specific reason to fill unused flash. If you leave it unchecked, you can also do a chip erase (most likely an option in whatever software does the programming) and will get unused flash in its erased state.
 

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 4111
  • Country: gb
  • Doing electronics since the 1960s...
Re: Filling flash with 0xFF
« Reply #6 on: June 15, 2024, 06:37:55 am »
FWIW, the 32F4 can do circular buffers using DMA.

And IME the biggest speedup for FLASH programming is to do a pre-read and program only if different. Often the speedup is dramatic e.g. 100x.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf