cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 and jump to function

Posted on May 16, 2018 at 12:15

Hi. Iì'm trying to implement the jump to function.

So my stm32 microcontroller has got 2 firmwares.

The first is located at address 0x08000000 and the second is located at address 0x08008800.

Using the st flash utility I have verified that the address 0x08000000 contains the first firmware and the address 0x08008800 contains the second firmware.

The jump to function is this

typedef void (*pFunction)(void);

void cmd_Jump_To_Application(uint32_t start_Address) {

    __disable_irq();

    uint32_t addressToJump = *(__IO uint32_t*) (start_Address + 4);

    pFunction Jump_To_Application = (pFunction) addressToJump;

    __set_MSP(*(__IO uint32_t*) start_Address);

    Jump_To_Application();

}

cmd_Jump_To_Application(0x08008800);

but the second firmware never run.

That it is wrong?
6 REPLIES 6
Posted on May 16, 2018 at 13:13

Try stepping with a debugger to better understand what is happening across the transition.

Linker must define correct base of each image.

Vector Table address (FLASH_OFFSET) must be set correctly. Usually in system_stm32fxxx.c SystemInit()

Equivalent to SCB->VTOR = 0x08008800

If you disable interrupts expect to have to enable them again on the other side.

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 23, 2018 at 17:06

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6uf&d=%2Fa%2F0X0000000bxt%2F8Bf5BfB9ofBk_5BUopQgiyoY98X63DNe3X20KX9nM4E&asPdf=false
Posted on May 23, 2018 at 18:14

>>Many thanks for your reply but I dont find nothing related to SCB->VTOR

This would be because the Cortex-M0 device you're using doesn't have that register, instead you must copy the vectors into RAM and map that into the zero address space.

It wasn't sufficiently clear from your initial post exactly what part you were using.

You might want to review the IAP (In Application Programming) examples for the F0 family to get some insight into how this is achieved.

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 23, 2018 at 18:24

Ok. Now I'm trying with a Nucleo L4R5ZI demo board.

This demo board accepts the line of code

SCB->VTOR = APP_ADDRESS;

so I have stored my slave firmware at 0x08010000

To call the firmware this is my function

void JumpToApplication(uint32_t APP_ADDRESS) {

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

    typedef void (*pFunction)(void);

    pFunction Jump = (pFunction)JumpAddress;

    HAL_RCC_DeInit();

    HAL_DeInit();

    NVIC->ICER[ 0 ] = 0xFFFFFFFF ;

    NVIC->ICER[ 1 ] = 0xFFFFFFFF ;

    NVIC->ICER[ 2 ] = 0xFFFFFFFF ;

    NVIC->ICER[ 3 ] = 0xFFFFFFFF ;

    NVIC->ICER[ 4 ] = 0xFFFFFFFF ;

    NVIC->ICER[ 5 ] = 0xFFFFFFFF ;

    NVIC->ICER[ 6 ] = 0xFFFFFFFF ;

    NVIC->ICER[ 7 ] = 0xFFFFFFFF ;

    SysTick->CTRL = 0;

    SysTick->LOAD = 0;

    SysTick->VAL  = 0;

    SCB->VTOR = APP_ADDRESS;

    __set_MSP(*(__IO uint32_t*)APP_ADDRESS);

    Jump();

}

and my main

JumpToApplication(0x08010000);

but does not work

Posted on May 23, 2018 at 18:49

Then you're going to need to dig out your debugger and use it to narrow down the 'does not work' into some more specific mode of failure.

Step through the transition and follow the rabbit into the code on the other side. Does that look to be the startup.s from your app? How far does it get?

Is there any code in your app that sets SCB->VTOR to something else? grep for 'FLASH_BASE' or 'VTOR'

Have a Hard Fault handler that does something more useful than while(1) and see if it ends up back there either on the loader or app side of the fence.

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 23, 2018 at 21:33

Finally I have understood how to do. It is easy.

The bootloader have to contains a function like this:

void JumpToApplication(uint32_t APP_ADDRESS) {

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

    typedef void (*pFunction)(void);

    pFunction Jump = (pFunction)JumpAddress;

    __set_MSP(*(__IO uint32_t*)APP_ADDRESS);

    Jump();

}

Called where you want in this way:

JumpToApplication(0x08004000);

Where 0x08004000 is the location where I have decided to store my application firmware.

But it is necessary to do something in the application firmware too.

I'm trying with a STM32L4R5ZIT microcontroller and in the system_stm32l4xx.c file I have edited a define:

&sharpdefine VECT_TAB_OFFSET  0x4000

and in the STM32L4R5ZITx_FLASH.ld I have edited

from

FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 2048K

to

FLASH (rx)      : ORIGIN = 0x8004000, LENGTH = 2048K

Trying with another microcontroller, STM32F091RCTx I haven't got the defin

VECT_TAB_OFFSET

so I don't know how to do.