tags:

views:

769

answers:

3

Hey!

I would like to have two applications in my STM32 flash, one is basically a boot and the other the 'main' application. I have figured out how to load each of them into different areas of flash, and after taking a memory dump everything looks like it is in the right place.

So when I do a reset it loads the boot, all the boot does at the moment is jump to the application. Debugging the boot, this all appears to work correctly. However the problems arrives after i've made the jump to the application, it just executes one instruction (assembly) and then jumps back to the boot. It should stay in the application indefinitely.

My question is then, where should I 'jump' to in the app?

It seems that there are a few potential spots, such as the interrupt vectors, the reset handler, the main function of the app. Actually I've tried all of those with no success.

Hopefully that makes sense, i'll update the question if not.

thanks for your help! Richard

Updates:

  • I had a play around in the debugger and manually changed the program counter to the main of the application, and well that worked a charm, so it makes me think there is something wrong with my jump, why doesn't the program counter keep going after the jump?
  • Actually it seems to be the PSR, the 'T' gets reset on the jump, if I set that again after the jump it continues on with the app as I desire
  • Ok found a solution, seems that you need to have the PC LSB set to 1 when you do a branch or it falls into the 'ARM' mode (32 bit instruction instead of 16 bit instructions like in the 'thumb' mode. Quite an obscure little problem, thanks for letting me share it with you!
+2  A: 

Make sure you jump to an address where the LSB is 1. See this site for an explanation: http://www.embedded.com/columns/beginerscorner/15200241?_requestid=162471

Richard
A: 

Richard,

I was trying to do the same thing you succeeded at, but was having problems. I was using the IAR IDE and updated the *.icf file (in the "proj" directory) to put my application at 0x08002000 and loaded a separate project at 0x08000000 that just does a jump to the address at the reset vector at 0x08002004. The boot code started up and does seem to jump to the application start, but the application failed sometime during the IAR initialization, ending up at an ILLEGAL INSTRUCTION trap.

After single-stepping through the application code, I found that I forgot to set the interrupt vector base address to that of the application's. It was still pointing to 0x08000000 and thus the code went insane. Adding a call to set the vector address before enabling any interrupts solved my problem and is required if you wish to have an application shifted in flash.

Ira.

A: 

Hi Richard,

You might want to search for the IAP (In-application programmer) it allows you to bootload code from the RS232 psort on the stm32. I started using and since it provides the source code, it is very simple to modify it for your purposes. basically after a reset you can code the IAP to bootload either from say address 0x08002000 or address 0x08003000. then all you have to do is set a flag in your application code then say restart and the new application will then run I hope this helps.

jramirez