AnsweredAssumed Answered

Reset vector vs Entry point

Question asked by Marshall Schiring on Mar 18, 2014

Hello all -

 

I have a project for a QE128 and had a question.

 

Background:

I am performing an automatic code update on my device that is running C code. After writing all the FLASH the MCU performs an illegal opcode reset. In the PRM for the project the reset vector is defined to go to main(). main() initializes the stack pointer (SP), runs a few commands, and then calls _Startup(). Startup() remains unchanged except that instead of calling main it now jumps to user defined MAIN_RunNormal() where normal execution continues.

 

In my memory map I noticed a line:

Entry point: 0x3134 (_Startup)

 

Changing the location of _Startup on a code upgrade would cause the upgrade to fail. This makes this section of code very sensitive. I was changing a function above _Startup, which pushed it lower in memory, and getting code upgrade failures. If I removed as much code as I added to another function above _Startup so that it was at the same place in memory the update would succeed.

 

I found this kind of confusing because I figured the entry point would be the same as the reset vector, or main for my project, not _Startup. After digging through the Build Tools Utilities Manual I found that the command INIT main might be required in my PRM file. It claims this is optional except in assembly projects.

 

So I try putting INIT main in my PRM and notice that my Entry point now points to main and not _Startup. Again I tried the code upgrade, but again it failed - I am not surprised because the entry point between the two version was different. I made a change so both versions of code used INIT main as the entry point and the upgrade worked fine! I then further tested an upgrade where both versions used INIT main, but the second version bumped main (the entry point) down in memory like the failure case above. This update also worked fine. It appears to me that it is critical to have your reset vector identical to your entry point.

 

Question:

So I guess my overall question is what is the difference between these two mechanisms? When is the reset vector being used and when is the entry point being used? I'm curious if the illegal opcode functions differently from a POR? Is there ever a scenario where you would want the reset vector to be different from the entry point?

 

Thanks for your time!

Outcomes