cancel
Showing results for 
Search instead for 
Did you mean: 

BOOTLOADER- How to jump....

jogerh
Associate II
Posted on May 09, 2017 at 09:12

Dear Community,

I want to implement a boot loader routine located in the first flash sector (0x8000000) of a stm32F407 device. After power up the bootloader decides whether the program pointer can jump to the main app located @ 0x8004000 or stay within the boot loader routine.

I managed so far to upload a bootloader interface and an app to the desired memory locations. Then I was copy and pasting the following code from

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

:

&sharpdefine APPLICATION_ADDRESS   (uint32_t)0x08040000

typedef void (*pFunction)(void);

pFunction Jump_To_Application;

uint32_t JumpAddress;

//…

case StartUP:   

                               // Jump to user application

                               JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);

                               Jump_To_Application = (pFunction) JumpAddress;

                               // Initialize user application's Stack Pointer

                               __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

                               Jump_To_Application();

break;

Inside the system_stm32f4xx.c of the Testapp located @ 0x08040000 I modified the line:

&sharpdefine VECT_TAB_OFFSET 0x40000

Since the post in mentioned forum (see above) mentioned this script has to work I would be very happy if someone could comment on this (unfortunately in my case it does not work).

null
5 REPLIES 5
jogerh
Associate II
Posted on May 09, 2017 at 09:51

EDIT:  #define APPLICATION_ADDRESS   (uint32_t)0x08004000

            #define VECT_TAB_OFFSET 0x4

000

But still the same result: It does not work.

Posted on May 09, 2017 at 12:01

 ,

 ,

I think the routine for relocating the vector table from the link mentioned above is wrong since the following script does also not work (I would expect a reset- like behaviour since the bootloader starts from 0x08000000):

 ,

♯ define APPLICATION_ADDRESS , , (uint32_t)0x08000000

typedef void (*pFunction)(void),

pFunction Jump_To_Application,

uint32_t JumpAddress,

 ,

 ,

case StartUP:

JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4),

Jump_To_Application = (pFunction) JumpAddress,

__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS),

Jump_To_Application(),

break,

Posted on May 09, 2017 at 15:17

Use the debugger and come up with a more specific reason it 'doesn't work', step into the code

0x08040000 or 0x08004000, not being entirely consistent. Processors want consistency, and the linker needs to build the image for the correct address. Inspect the image and vector table, make sure the addresses point to the routines correctly.

The SCB->VTOR is a very uncomplicated register, you set the base of the aligned vector table.

More probable you've got other interrupts and clocks set up. Consider NVIC_SystemReset() to get back into the Boot Loader.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Gabor Szeman
Associate II
Posted on May 10, 2017 at 10:23

Hi,

I recently created a working solution for a same problem. My code to launch begins at 0x0800C000. In the comment I write some explanation for you.

__asm('ldr r0, =0x0800C000'); //the SP value can be found under this address.

//the C syntax for this would be: uint32_t * r0 = (uint32_t *)0x0800C000;

__asm('ldr r1,[r0]'); //read pointed value into r1. This will be the SP! C syntax: uint32_t r1 = *r0;

__asm('ldr r0, =0x0800C004'); // C syntax: r0 = (uint32_t *)0x0800C004;

__asm('ldr r2,[r0]'); // C syntax: uint32_t r2 = *r0;

__asm('mov SP, r1'); //initialize stack pointer. You must do this before 'goto'

__asm('blx r2'); //move to r2. We don't use function calls, because that would modify the SP.
jogerh
Associate II
Posted on May 13, 2017 at 21:38

Dear Community

thank you very much for replying.  The point was that the given JUMP- Code (see my first post) is actually working. However I used an USART interface to reply whether the JUMP into the application does succeed or not and since I didn’t got any response I concluded it is not working. However using the KEIL – Debugmode initialized for the application I was able to see that the JUMP is working after executing the JUMP function. The important point was that the application I was jumping into was not able to reinitialize the USART correctly.

Thank you very much for your support