cancel
Showing results for 
Search instead for 
Did you mean: 

How do execute a program from a location other than the beginning of flash memory?

Gordon Madden
Associate III
Posted on June 24, 2017 at 00:04

Using STM32F417, programs uploaded to internal flash start executing at address 0x0800_0000.

I want to start the program at 0x0800_0010 instead. The reason for the extra bytes at the beginning of flash is to save status bytes that indicate the state of the startup or bootloader in case of a failure during firmware updates.

By going into flash options in KEIL uVison, I can change the ROM settings to program to flash starting at that address.

If I then go to the LINK Utility, I can see that the program does indeed start at the new address, but it will not execute.

The program is still probably still starting at the beginning of flash.

Searching through the files in the project, I find various #defines that may or may not affect where the program starts running. I have stepped through the startup sequence and did not see anything with that address that could be changed.

I tried changing the base address for the Ram fro 0x0800_0000 to the new address, thusly:

#define RamAddress        (IO_BASE+0x08000010)

How do I get the program to start executing at 0x0800_0010 instead of 0x0800_0000?

Thank you for your help!

15 REPLIES 15
henry.dick
Senior II
Posted on May 10, 2018 at 14:13

Many ways of doing it, like jumping to that address....

The easiest in C would be to declare a function pointer, point it to that address, and execute that function pointer.

From the cpus perspective it doesnt matter where the code is or if it is valid. It simply fetches and executes.

Posted on May 10, 2018 at 13:27

Hello Gordon & Clive, I have almost the same problem and appreciate if Clive explains a bit more in detail. from what Clive mentioned, I learned that my bootloader will sit on the beginning starting from 

0x08000000 to 0x08003FFF and the application codes from 

0x08008000 to 0x080FFFFF. Thank you. I have already programmed my bootloader via uart1 at the right location and my application codes using my bootloader via USB-COM also at specified location starting from 0x08008000 . I ensure that both locations are safely written. will you please teach me how to enforce the MCU to start from the application code at  0x08008000 after reset? this is where I am lost actually. please consider explaining to a kid with little knowledge. Thanks in advance  

Posted on May 10, 2018 at 23:25

I have two Keil projects, one runs at 0x800_0000 and the main code at 0x800_8000.

All the first one does is jump to the second.

In main:

int main(void) 

{

    JumpApp();

}

Remember to declare JumpApp somewhere.

JumpApp() is an assembly function in startup_stm32f417xx.s. Here is the definition:

JumpApp            PROC

                EXPORT  JumpApp

                LDR     R0, =0x08008000 ; APP BASE, FLASH sector 2

                LDR     SP,[R0, &sharp0]     ; SP @ +0

                LDR     R0,[R0, &sharp4]     ; PC @ +4

                BX      R0

                ENDP

This sets the address to run from, stack pointer (SP), and programme counter (PC).

It then jumps to the programme counter address (SP plus 4)

As long as your code is in the right place, it should begin running.

Posted on May 10, 2018 at 23:49

Using assembler is somewhat less of a circus, and less confusing about addresses in arrays and function pointers.

In systems where the loader brings up a lot of interrupts or an RTOS it is sometimes preferable to do a quick sanity check of the app image and jump to it from the Reset_Handler. Also using RAM variables to allow the app to nuke itself and drop into the loader, or system loader.

Going to cross-link into the other thread here

https://community.st.com/0D50X00009XkWSTSA3

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 11, 2018 at 03:17

Hello Gordon, I will try it many thanks  

Posted on May 11, 2018 at 03:18

Thank you very much Clive.