Is the whole program uploaded even if only one byte changed?

Hello :slight_smile:

I'm not sure where to post this question...

I am wondering if when I upload a program in which I did only small changes compared to the previous version of that program (changing for example byte a = 2 to byte a = 3), will the whole program be uploaded or just the changes?

My real question is, will uploading a program "damage" every memory cells it uses, even if only one memory cell was required to be changed? Considering "memory supports at least 10,000 writes or upload cycles"... I'm already at 2000+ uploads I think, and I haven't even done 10% of the code for my project, just testing things...

The whole program is uploaded every time. The flash has 10x the wear endurance of the EEPROM that you quoted, so it is not a practical problem.

Not to worry.

-br

billroy:
The whole program is uploaded every time. The flash has 10x the wear endurance of the EEPROM that you quoted, so it is not a practical problem.

Actually the other way 'round. Still seems like a lot though. From the ATmegaXX8 datasheet:

Features
โ€ข High Performance, Low Power AtmelยฎAVRยฎ 8-Bit Microcontroller Family
โ€ข Advanced RISC Architecture
โ€“ 131 Powerful Instructions โ€“ Most Single Clock Cycle Execution
โ€“ 32 x 8 General Purpose Working Registers
โ€“ Fully Static Operation
โ€“ Up to 20 MIPS Throughput at 20MHz
โ€“ On-chip 2-cycle Multiplier
โ€ข High Endurance Non-volatile Memory Segments
โ€“ 4/8/16/32KBytes of In-System Self-Programmable Flash program memory
โ€“ 256/512/512/1KBytes EEPROM
โ€“ 512/1K/1K/2KBytes Internal SRAM
โ€“ Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
โ€“ Data retention: 20 years at 85?C/100 years at 25?C(1)
โ€“ Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
โ€“ Programming Lock for Software Security

Oops - sorry, you're right. My mistake.

Still never been a practical problem here and I have a very old '328.

-br

billroy:
Still never been a practical problem here and I have a very old '328.

Agree. If and when it does wear out, it's only a few dollars investment.

Well you are right, I use a Mega 2560 so can't replace chip (at least not easily) but (sainsmart's) Mega 2560 is like 15$ these days. But still, isn't it possible for the "uploader" (avrdude?) to "download" the current program that is on the chip, compare with the to-be-uploaded and if only few bytes changed only upload those bytes? Is it theorically possible and if yes, why it hasn't been made? It would greatly increase the lifetime of that flash memory right?

  1. Small changes in the source code cause bigger changes in the executable. Think about it: if you insert an instruction without changing anything else, everything after it is moved later in memory.

  2. The flash memory is organized into pages anyway (see table 27-11 on page 299 of the '328 data sheet) which means you're writing large sectors for a 1-byte change.

  3. To solve what real-world problem?

-br

guix:
I'm already at 2000+ uploads I think, and I haven't even done 10% of the code for my project, just testing things...

Is this an exaggeration? I can't imagine how a project small enough to fit on an Arduino could require 2000 attempts to get 10% of it working. Are you uploading the code when you meant to just verify it, or something? You'd have to be uploading every five minutes for weeks on end to reach that sort of number of uploads.

Well, I have an Arduino since approx 7 months, uploading on average 10 times a day... (that's how it works when you want to explorate and learn) so that's how I calculated those 2000+. Maybe you don't realize, but it goes quick.

Divide the cost of a new Arduino by the number of hours you will have been programming before it wears out. If you do about 15 minutes of programming for every upload that works out at 2,500 hours before you use up the 10,000 uploads. ยฃ25 / 2,500 = 1p per hour. Not very expensive compared with your time.

...R

Is it theorically possible

yes

and if yes, why it hasn't been made?

because it is not a problem and it would take so much memory space in the boot loader that it would restrict the maximum program size.
But suppose you added one byte at the start of the memory then everything else gets shuffled down making all the code needing moving. So just changing one line in C might result in one more or less actual machine code instructions and that would shuffle everything.

It would greatly increase the lifetime of that flash memory right?

Yes, but to what end? Practically it is not a problem.

guix:
Well, I have an Arduino since approx 7 months, uploading on average 10 times a day... (that's how it works when you want to explorate and learn) so that's how I calculated those 2000+. Maybe you don't realize, but it goes quick.

Bearing in mind that when the flash life runs out the failure symptoms are that the memory becomes 'leaky' and will eventually encounter bit errors if you leave it for long enough, if you keep using your arduino rather than leaving it for months and years without being reprogrammed, it is likely you will be able to massively exceed the specified life without encountering any errors. And, if it does encounter any errors you can resolve them by reloading your sketch. And if you get fed up with that it's only a couple of bucks to replace the chip, although I suppose by the time you reach that point these chips will be obsolete and will have been replaced by something with the same form factor but a million times more powerful.

OK, I will stop worrying about memory lifetime then :slight_smile: