This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to jump to Application 2 from Application 1

Hello ervery one,

I am doing development on NRF52840. I have a problem as follows looking forward to your guidance.

I need to jump to Application 2 (address: 0x32000) from Application 1 (address: 0x26000). I did not use Bootloader / DFU because it found it quite confusing and did not suit my problem.
I expect when the boot device will run into Application 1 and then jump to Application 2.
Looking forward to your help, thank you!

Parents
  • Fist things first: App2 must be linked to address 0x32000 - check the linker settings / linker script.

    Secondly use the folowing function to set the vector table base in softdevice:

    sd_softdevice_vector_table_base_set(0x32000);

    Third: Load the SP and PC from the fist two words at 0x32000 - this starts the actual execution. May need some inline assembly in order to work across all compiler optimization settings.

  • Hi Turbo, Tks you for your support.

    1, I use KeilC, I don't know if my settings are correct! (This is Application 2, Image bellow) 

    2, Call funtion sd_softdevice_vector_table_base_set(0x32000) in application 1? Right

    3, This is my code for jump to application 2:

    Tks you so much!

    void jump_to_application(void)
    {
    	uartSendDBG((uint8_t *)"Function jump bl\r\n", strlen("Function jump bl\r\n"));
    	void (*fn_jump_app)(void);
    	uint32_t msp_value = *(volatile uint32_t *)FLASH_ADDRESS_APPLICATION_PRIMARY;
    	__set_MSP(msp_value);
    	uint32_t resetHandler = *(volatile uint32_t *)(FLASH_ADDRESS_APPLICATION_PRIMARY+4U);
    	fn_jump_app = (void *)resetHandler;
    	fn_jump_app();
    	uartSendDBG((uint8_t *)"Done\r\n", strlen("Done\r\n"));
    }

  • Trying to jump to another application in plain C is asking for trouble, but it might work if the compiler optimized the code properly.

    I recommend checking the disassembly of jump_to_application() in a debugger.

    The problem is that local variables on the stack are no longer accessible once the new MSP value is set.

    Edit: The "Done" debug message should be changed to "Failed", since this code cannot be reached.

  • Log "Done" not reached on the terminal, the device is hang when I call fn_jump_app()   or  sd_softdevice_vector_table_base_set(0x32000).

Reply Children
Related