2017-06-23 03:04 PM
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!
Solved! Go to Solution.
2018-05-10 05:13 AM
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.
2018-05-10 06:27 AM
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
2018-05-10 04:25 PM
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 ENDPThis 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.
2018-05-10 04:49 PM
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
2018-05-10 08:17 PM
Hello Gordon, I will try it many thanks
2018-05-10 08:18 PM
Thank you very much Clive.