Skip to main content
Santhosh KM
Associate II
September 7, 2017
Question

Bootloader + Two applications

  • September 7, 2017
  • 7 replies
  • 3117 views
Posted on September 07, 2017 at 08:19

Hi, 

I have to download second application and enter second application from the first application.

Bootloader to First application jump is happening and working fine.

I have problem to jump to second application from the first application ( downloaded second application from the bootloader same as first application) using the same approach as jump is made from bootloader to first application.

Bootloader -> jump to first application -> Jump to Second application.  I am getting this error

The stack pointer for stack 'CSTACK' (currently 0xF000FB64) is outside the stack range (0x2000DFC0 to 0x2000FFC0) and followed by first application restarts and enters booloader

I have this changes in the linker file ( .icf file)

Bootloader:

define symbol __ICFEDIT_intvec_start__ = 0x08000000;   f

define symbol __ICFEDIT_size_cstack__ = 0x4000;

define symbol __ICFEDIT_size_heap__ = 0x200;

First application:

define symbol __ICFEDIT_intvec_start__ = 0x08010000;   for first application

define symbol __ICFEDIT_size_cstack__ = 0x4000;

define symbol __ICFEDIT_size_heap__ = 0x200;

Second application: 

define symbol __ICFEDIT_intvec_start__ = 0x08020000;   for second application 

define symbol __ICFEDIT_size_cstack__ = 0x6000;

define symbol __ICFEDIT_size_heap__ = 0x200;

Using this code to jump to second application, used same from bootloader to first application:

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

SCB->VTOR = ApplicationAddress;

Jump_To_Application = (pFunction) JumpAddress;

__set_MSP(*(__IO uint32_t*) ApplicationAddress);

Jump_To_Application();

Any help is welcome, I think I have problem with the linker settings 

Thanks

Santosh

#cstack-error-while-jumping-to-application
    This topic has been closed for replies.

    7 replies

    Nesrine M_O
    Associate
    September 11, 2017
    Posted on September 11, 2017 at 15:39

    Hi

    kmtaranath

    ,

    Please refer to the

    http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-expansion-software/x-cube-extboot.html

    application note and the associated software it may help you.

    -Nesrine-

    Tesla DeLorean
    Guru
    September 11, 2017
    Posted on September 11, 2017 at 15:56

    Look at the .MAP file and the .BIN or .HEX an see what the Linker actually built and where it placed things.

    The .ICF should describe different ROM/FLASH regions which clearly define the constraints of those specific regions.

    ie

    0x08020000..0x0802FFFF

    Read/review the documentation for your chosen tools.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Santhosh KM
    Associate II
    September 12, 2017
    Posted on September 12, 2017 at 10:42

    All these files linker addressed matching as per .ICF file.

    Tesla DeLorean
    Guru
    September 12, 2017
    Posted on September 12, 2017 at 11:08

    Step the code, and transition, at a disassembly level,and understand where the SP gets loaded with a bogus value. When you understand where it comes from you'll be in a better place to fix it.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Gregory Holcomb
    Associate II
    September 11, 2017
    Posted on September 11, 2017 at 16:44

    Also look to see at run time that your telling the processor where the interrupt vector table is.  In my Keil solution with your program location of 0x8020000, I think you'd need NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x20000);

    Tesla DeLorean
    Guru
    September 11, 2017
    Posted on September 11, 2017 at 16:54

    In many CMSIS implementations they use SCB->VTOR = 0x08020000; or an equivalent in SystemInit(). I pull in the __Vectors symbol which save the necessity of changing/tracking this in multiple places.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Santhosh KM
    Associate II
    September 12, 2017
    Posted on September 12, 2017 at 12:00

    __vector_table is pointing to 

    __ICFEDIT_intvec_start__     in each build .. Bootloader, application1 and application2

    Santhosh KM
    Associate II
    September 12, 2017
    Posted on September 12, 2017 at 12:01

    I can see PC and SCB_VTOR is changing before trying to jump from one application to other, I expect same behaviour from application1 -> application2. Becuase its working from bootloader -> appliction1

    Tesla DeLorean
    Guru
    September 12, 2017
    Posted on September 12, 2017 at 16:46

    We get out the debugger, and we step the code, we follow it through until it gets to main(), or it veers off the tracks..

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

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Santhosh KM
    Associate II
    September 13, 2017
    Posted on September 13, 2017 at 10:42

    Single step is not possible to debug, it will not show anything after few steps to see how it enters main().  I can see VTOR is changing and reset is happening after jump to second application

    Tesla DeLorean
    Guru
    September 13, 2017
    Posted on September 13, 2017 at 13:00

    Ok, and your supervisor is satisfied with that answer? 

    With the data you're seeing why would it reset? Do you have a watchdog timer? Does the code look like the Reset Handler for App2? 

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Francois Baratin
    Associate
    September 14, 2017
    Posted on September 14, 2017 at 10:15

    Hello,

    I was also unable to jump to an application, I fixed it by disabling everything before doing the jump, like this:

    void fn_jump_to_application(void)

    {

    SCB_DisableICache();

    SCB_DisableDCache();

    HAL_MspDeInit();

    HAL_DeInit();

    HAL_RCC_DeInit();

    __HAL_RCC_PWR_CLK_DISABLE();

    __HAL_RCC_GPIOE_CLK_DISABLE();

    __HAL_RCC_GPIOB_CLK_DISABLE();

    __HAL_RCC_GPIOG_CLK_DISABLE();

    __HAL_RCC_GPIOD_CLK_DISABLE();

    __HAL_RCC_GPIOA_CLK_DISABLE();

    __HAL_RCC_GPIOC_CLK_DISABLE();

    __HAL_RCC_GPIOI_CLK_DISABLE();

    __HAL_RCC_GPIOH_CLK_DISABLE();

    __HAL_RCC_GPIOF_CLK_DISABLE();

    /* Jump to user application */

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

    Jump_To_Application = (pFunction) JumpAddress;

    /* Initialize user application's Stack Pointer */

    __set_MSP(*(__IO uint32_t*) FLASH_APPLICATION_START_ADDRESS);

    Jump_To_Application();

    }

    + don't forget to update the VECT_TAB_OFFSET, like this:

    #ifdef BOOTLOADER_MODE

    #define VECT_TAB_OFFSET 0x00000000       //start address = 0x08000000

    #elif APPLICATION_MODE

    #define VECT_TAB_OFFSET 0x00080000       //start address = 0x08080000

    #endif

    ...

    SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */)

    Francois

    Santhosh KM
    Associate II
    September 18, 2017
    Posted on September 18, 2017 at 05:13

    Turvey.Clive.002

    Yes I was having watch dog timer it jumps to application ( disabled watchdog for time being) now. Thanks