Hello all,
to reflash my MSP430F5308, I want to move the actual copying routine (do_reprogram()) to RAM and run it from there. Noting unusual so far. I am using CCS5.4.
I have tried two approaches:
- Selecting an arbitrary RAM address, copying the code from flash there and then branching to the beginning of the code in RAM. No references to functions in flash are used.
This will overwrite the existing RAM, but the reflashing routine terminates with a reset anyway, so this would not be a problem. Advantage: the function which is rarely called does not occupy any RAM. - As in the appnote: modify the linker command file. What I put there is:
.flashcode : load = FLASH, run > RAM
and in the C file:
#pragma CODE_SECTION(do_reprogram,".flashcode")
In both cases, the function code is copied to the correct location in RAM. The copy looks fine as far as I can tell (copied using memcpy()).
While the code runs fine when executed from flash, it gives me resets when executed from RAM. What makes thins worse: if I run the code with "Resume" in the debugger, the reset comes before even reaching the function in RAM (a breakpoint placed at the beginning of the function is never reached). In single step mode, everything looks fine.
Reset causes (as defined by SYSRSTIV) are either PMM access violations (which is plain nonsense since I do not use the PMM functionality) or flash password violations (which makes a little more sense, but as stated before, the function which does the flash access is not even reached).
Before I go into details and start posting tons of code: is there any caveat to be considered when running code from RAM? I am starting to get pretty frustrated.
Max