cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411 Memory

CEagl.1
Associate II

Hi,

I have a few questions about how the STM32 works.

I would like to be able to jump from my main program to a secondary program (bootloader) That will carry out a firmware update if one is available.

My plan here is to have my main application running from 0x08000000 so it should boot and run without any issues. I have my application already running like this. This application will download a firmware and store it in an external memory for later.

At a set time the main application will jump into a second application. This application will be responsible for writing the firmware from the external memory to the internal memory from 0x08000000. Once complete the secondary application will issue a reset command and the device will boot back into the main application.

I am trying to find out the answer to the following questions,

If i just jump to another location in the memory i.e the second application, will the code at that location simply execute?

If not what will i need to do to make it execute?

Thanks

5 REPLIES 5
TDK
Guru

> If i just jump to another location in the memory i.e the second application, will the code at that location simply execute?

If you do it right, yes.

Most applications store the bootloader at 0x08000000 and the main program somewhere else. But doing the reverse is also fine.

Here is one of many many hits on how to jump to the bootloader on the STM32F4. You'd use the same code except use the main program address instead of the bootloader address.

https://community.st.com/s/question/0D50X00009XkeeW/stm32l476rg-jump-to-bootloader-from-software

If you feel a post has answered your question, please click "Accept as Solution".

A manual on the Cortex-M4 might be something to look over to understand the mechanics of control transfer.

Generally you want the update/loader app as the primary code at 0x08000000, it can check and handover control to an application deeper into the flash memory. This provides for a means of recovery if the update process goes sideways.

To run images at different location you should use standard firmware for with a vector table in front, use the initial SP/PC to enter into it, and relocate the vector table via the SCB->VTOR. Transfer should be done under stable conditions, and without interrupt firing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
CEagl.1
Associate II
#define ApplicationAddress 0x08008000
typedef void (*pFunction)(void);
 
uint32_t JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
 
pFunction Jump_To_Boot = (pFunction) JumpAddress;
 
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
 
Jump_To_Boot();

I think then that this will suit my needs??? I shall try this out this evening.

Curious as to why jump to application is 0x08008000 + 4. Why jump past those 4 bits?

It is a Vector Table, not executable code, you've got a pair of 32-bit addresses for the initial SP and PC (Stack Pointer / Program Counter).

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
CEagl.1
Associate II

Thanks Clive, I was thinking it may be something like that but didnt know for certain.

The code that i have above from someone elses project does not include SCB->VTOR as you previously mentioned.

Is it required in the above??