0

I'm using the STM32L496 and have a bootloader at 0x08000000 of flash. After that, I have two partitions for applications, one at 0x08040000 which is the main application, and one at 0x080C0000 for a "golden image" that the bootloader can use if the main application is corrupted (the idea being the main app can be re-programmed with IAP). I've been able to modify the linker and scb->vtor setting so it will build the application to boot from either partition (golden image when main app is blank).

My question is, is there a way to do this without changing the linker and vector offset manually? Let's say I have a new build that is the new "golden image", I'd like to be able to build that so I can program it to each partition.

2
  • This has definitely been asked before but I can't find it. The short answer is basically no, you can't make a statically linked application that can be loaded to different addresses, and using dynamic linking in a microcontroller application is very unusual, which makes it very difficult. It is also very inefficient when running. Commented Oct 11, 2022 at 19:52
  • Seems like the best option is to use the IDE with multiple build options that use different linker files: essentially a "Release" build and "Golden Image" build that use different linkers. The vector can be adjusted with software. Commented Oct 11, 2022 at 20:32

1 Answer 1

0

I think what you mean is Position Independant Code. It's possible to generate PIC code with ARM cortex GCC though I never did it myself.

It is pretty complicated: see here for example.

However as others wrote already, I don't really see the benefit to do that especially on a small STM32L4 MCU. It is inefficient and complex (so error prone).

Moreover the STM32L4 provide a functionality to do (more or less) what you need: there are two flash banks and you can swap them. It means the HW changes the aliased adress of bank2: you can link your software always to the same adress 0x0800 0000 but load it either in bank 1 or in bank 2. It is meant to ease software update.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, absolutely answers my question. I did figure out an interesting alternate path: not adjusting the application via linker or vector, but instead using a partition of flash as storage for the "golden image", and I can just copy that to the main application partition, rather than jump to the part of flash where the golden image resides.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.