download silent error

We’ve all had issues with downloading and have variously been advised to

use a different cable
switch USB ports
reboot you machine
check drivers
try different Arduino board if available

and so forth. I can go weeks with no trouble, then have days where everything seems very fussy. Of course something is at the bottom of it, but it is impractical to run every fault to ground when rebooting or simply trying again might work.

So my question that your own experiences might shed some light on:

If I download a program, and there are only indications of success, what is the probability that the downloaded code is not correct?

Not correct as in it does what I think it should, correct in the sense that the download was faithful, that the bits got to where they were meant to go, 1s and 0s.

I’ve always assumed there are mechanisms to detect failures, and I am not clever enough to invent a scenario where a program would whistle down jake and then make errors because some of the bits didn’t make it.

I old enough not to blame problems on such a download error idea, not the first (or second or third or …) place I would start looking if my program didn’t do what I thought it should be doing.

On the same hand, or is it indeed the other, I also am old enough to know that anything is possible. I’m 100 percent sure of nothing else. So it may well be that this error can/does/has happen[ed], to me, to you, I don’t know.

a7

If you check the box next to File > Preferences > Verify code after upload then the bits in the microcontroller's flash will be compared to the file on your computer that was uploaded. It makes the upload take a little longer, but probably worth it when you consider how much time you could waste on troubleshooting if the upload was corrupted.

Thank you.

Either I did that at some point, or it comes out of the box that way.

I would have guessed this was always done and not optional.

So now I guess my question should be expanded, viz:

If I download a program and it passes verification, what is the probability that the downloaded code is not correct?

I know it is closer to 0 than 1 and probably not 0.

It's really not where I am looking for a problem. Just curious, plus I have been trying to imagine ways in which it might yet go wrong, besides cosmic rays. More like some combinatoric thing where it would always do the same mistake silently.

a7

I have uploaded a lot of sketches to Arduinos. I have never encountered a case where the IDE reports the upload was successful, but the sketch was not actually uploaded perfectly. So, I am certain there is 0% chance of the IDE reporting success in upload but the resulting sketch on the Arduino being different from the sketch in the IDE. If there are problems with the program not doing what I think it should, it is 100% of the time a problem with the wiring of the project, the hardware used (transistors, resistors, capacitors, etc.), or the sketch is written improperly. I usually find the error and correct it, or get help here on the forum if I can't figure it out.

alto777:
or it comes out of the box that way.

Yes, it's the default setting.

I think the chance of getting a spurious verification pass is highly unlikely. First, you would need the upload to finish, but write bad data, and that is very rare. Then, you would need something to go wrong either with the reading of the corrupted flash memory or the reading of the file on your computer that just so happened to give a false match between the two.

I haven't ever had a verification failure under normal circumstances (I have when uploading with USBtinyISP to chips that it wasn't compatible with), but for years we have regularly gotten reports on this forum of people having uploads fail with "avrdude: verification error; content mismatch" errors, so it does happen. So I still think it's worth leaving the verification option turned on even though so far it's only been a waste of my time waiting slightly longer on each of the zillions of uploads I've done.

It seems a small price to pay, of course YMMV.

We can have high confidence with the verification it seems. As I sit here, I can think of a few ways the whole thing could still go wrong, none at all probable. Just possible.

Best: malice! I couldn't, but it seems like a piece of malware knowing what it was doing could really make mayhem with Arduino or other cross-loads!

a7