Skip to main content
jogerh
Associate III
May 9, 2017
Question

BOOTLOADER- How to jump....

  • May 9, 2017
  • 5 replies
  • 1962 views
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
    This topic has been closed for replies.

    5 replies

    jogerh
    jogerhAuthor
    Associate III
    May 9, 2017
    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.

    jogerh
    jogerhAuthor
    Associate III
    May 9, 2017
    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,

    Gabor Szeman
    Associate
    May 10, 2017
    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
    jogerhAuthor
    Associate III
    May 13, 2017
    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