Bad controller?

Got into a strange problem with a Mega2560.

It run one sketch (avrdude: 16696 bytes of flash verified).

I then made a new sketch based on the first one but with a few changes (avrdude: 17324 bytes of flash verified).
Now the controller run until in the middle of the setup() function and the restart. Just before it restart part of a Serial.println(F("Some test")); is printed and with some special characters behind (od in linux say octal values 342 270 256).

I thought it could be a bug in the function being called from the setup(), so I added a few more Serial.println(...) in the code and uploaded it (avrdude: 17454 bytes of flash verified). Now the controller won't start at all. Nothing happens.

My first though is that the flash memory is bad, but the verification process that avrdude is doing - isn't that done to verify that the content of the flash memory is correct?

Back out the changes, one by one.

I'm sorry but I do not want to be rude. But you did not answer my question, which was:

the verification process that avrdude is doing - isn't that done to verify that the content of the flash memory is correct?

No, verification is to show that the code on the device is the same as the code uploaded, not that the code is correct.

Compilation completion shows that the code is syntactically correct, not that the code will do what is expected.

OP is talking about the verify in avenue if I'm not mistaken.

So the upload succeeded and the code crashes. That indicates a problem with your code.

TheMemberFormerlyKnownAsAWOL:
No, verification is to show that the code on the device is the same as the code uploaded, not that the code is correct.

Compilation completion shows that the code is syntactically correct, not that the code will do what is expected.

Thanks. In other words: IF the flash memory is bad, avrdude will tell me.

sterretje:
OP is talking about the verify in avenue if I'm not mistaken.

So the upload succeeded and the code crashes. That indicates a problem with your code.

Yes, it was a problem with my code. Funny that adding a few Serial.println(F("some text")) cause the controller to hang.

How does the compiler arrange different part of the code in the application flash section?
I assume the code start from address 0000 to address xxxx and constants (like "some text") after xxxx?

It's not the rearranging of flash, it's the rearranging of variables in RAM. And e.g. writing outside the boundaries of an array while in a function might overwrite the return address resulting in a return in another location in your code.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.