: "Illegal opcode happens the most often not due to selferased bits of flash, but due to uninitialized pointers, due to stack overflow etc."
: uninitialized pointers==> How ?Kindly can you explain this.I've heard this uninitialized pointers leads to crash.But never knew how?
If you try to access a part of the memory map where nothing resides, you will get an illegal opcode interrupt. If your pointers aren't initialized, they are pointing at a random location.
: due to stack overflow ==>Yes, If the program code resides in RAM (relocatable code-Flash routines) and gets overwritten then there is a case of illegal opcode issue.Is there any point which i missed to see?
When the stack overflows, you could get the same error as for unitialized pointers. The SP could then point at a non-valid memory location. Ie it has nothing to do with where the code resides, though code in RAM can cause further issues like the ones yoy mentioned.
If you are smart when you design your memory map, you put the stack on top of the RAM and make sure that the address above RAM isn't valid. If your program gets a stack overflow, you will then get the opcode interrupt + reset instead of the program starting to behave randomly. It will also be much easier to find stack error bugs using this method.
: @Lundin: "Another reason could be a corrupt binary file downloaded into the MCU from a PC, or that the download itself faced EMI. Hopefully, both binary files and download tools use checksums to check the data" .
S19 has checksum field as you said.Doesn't it protect from corrupt hex codes (in s19) being flashed into the MCU, even in case of EMI environment. No corrupt code enters from s19 point of view enters MCU;This is my understanding,Please correct me if I am wrong.
Then I will correct you
S19 is just an ASCII file which is the Motorola/Freescale standard way of storing programs on your PC. The BDM pod will read this file but translate it to raw binary data, which is then sent to the MCU.
First of all, the checksum in s-records is laughable. It just sums everything, there is a huge chance that such a checksum algorithm fails to detect file corruptions. The serious approach would have been to use CRC-8 or better. But no matter how good the checksum is, no checksum is 100% fail proof.
Second, what happens between the PC and the MCU is all in the hands of your BDM pod manufacturer. Hopefully they are using checksums/read-back, I have no idea.