cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 code relocation

marknorman9
Associate II
Posted on March 31, 2009 at 13:54

STM32 code relocation

15 REPLIES 15
marknorman9
Associate II
Posted on May 17, 2011 at 13:07

I'm designing a application downloader that can be run from the main application. The mechanism I want to employ would be to load a replacement application into a secondary ''bank'' of flash and then do a soft reboot into that region without having to copy it into the normal running location. Does this chip have a mechanism that would allow me to do this, I'm assuming that the Interupt vector table would have to move also. Also would the compiler produce relocatable code using relative instead of fixed location jumps?

trevor1
Associate II
Posted on May 17, 2011 at 13:07

Hi Mark,

I'm not aware you can produce relocatable code using relative instead of fixed location jumps. Even if you could it might have a big impact on performance

The way I do this is to store the new app external (serial Flash or SD card etc) and once I have it stored and validated I reset where my bootloader loads it into the application area nd runs it.

You could take the same approach but store your new app in an area of internal flash and then get your bootloader to detect it and copy it into the application area before jumping to it. This way the app you are going to run always lives at the same address.

Trevor

marknorman9
Associate II
Posted on May 17, 2011 at 13:07

Hi Trevor

Unfortunately I only have the flash area to play with, I can, given enough space, use three images in the flash, and move them around allowing the state changes I need. But I'm trying to avoid this for reasons of room and speed. Thanks for your advice.

Mark

trevor1
Associate II
Posted on May 17, 2011 at 13:07

Mark,

There is no extra space requirement or external memory requirement. With both methods you can have two apps stored at one time. You have an app and you store a new app above it and once you know you have it all correct you reset and let your bootloader copy the new app over the old one. The bootloader then ''marks'' the new app as deleted (by just zeroing one byte or something). See below

I agree there is some extra time spent copying the new app over the old one but would be quite quick.

------------

| bootloader |

|------------|

| |

| app |

| |

|------------|

| |

| new app |

| |

------------

marknorman9
Associate II
Posted on May 17, 2011 at 13:07

Trevor

I have a similar thread running on the Keil forum and have been told I can do this, if I inform the compiler to produce position-independent code and I map the interrupt vectors into RAM. Them I can just jump to the relocated code and it should work. Do you think this is posible?

Mark

trevor1
Associate II
Posted on May 17, 2011 at 13:07

Hi Mark,

I can't say either way as I've never tried this. If someone on the other forum thinks it is possible then I have no reason not to believe this.

If you try please let us know how you get on.

Regards

Trevor

marknorman9
Associate II
Posted on May 17, 2011 at 13:07

I will, but first I need to understand how the interupt vectors work and where they are normally located, what is the best reference document for this?

marknorman9
Associate II
Posted on May 17, 2011 at 13:07

Trevor or anyone who knows

I have found a reference to ''NVIC vector table offset register'' will this do what I think it will do, i.e will it move the position of the vector table, giving me the ability to do what I need. I am still having problems finding any documentation on how this NVIC stuff works.

Mark

trevor1
Associate II
Posted on May 17, 2011 at 13:07

I've never tried this so I don't know, sorry.