Skip to main content
u23
Associate III
June 23, 2014
Question

STM32F105 problem jumping to application

  • June 23, 2014
  • 14 replies
  • 2211 views
Posted on June 23, 2014 at 15:35

I have problem with jump to application by bootloader.

The device used is the STM32F105R8.

The bootloader does not jump in the application,it crashes in the function ''Jump_To_Application()''.

The code of the bootloader making the jump is:

#define APPLICATIONADDRESS    (uint32_t)0x08008000

/* Test if user code is programmed starting from address ''ApplicationAddress'' */

if (((*(__IO uint32_t*)APPLICATIONADDRESS) & 0x2FFE0000 ) == 0x20000000)

    {                    

        /* Jump to user application */

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

        Jump_To_Application = (pFunction) JumpAddress;

        /* Initialize user application's Stack Pointer */

        __set_MSP(*(__IO uint32_t*) APPLICATIONADDRESS);

        Jump_To_Application();

    }

In the application i have relocate the vector table:

int main(void)

{

    //    __disable_irq();  

    

      /* Set the Vector Table base location at 0x8000 */

      NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);

    //    __enable_irq();  

    /***************** Add your application code here   ***************************/

    ........

}

I attached the image (bootloader + application) downloaded  from flash.
    This topic has been closed for replies.

    14 replies

    Tesla DeLorean
    Guru
    June 23, 2014
    Posted on June 23, 2014 at 16:36

    Wouldn't the code typically in SystemInit() relocate the Vector table?

    Your application does not appear to be linked at 0x08008000, the ResetHandler vector points to 0x08007165 which is all 0xFF's

    a) You could print out values for the SP/PC before you jump

    b) You should be able to step through the transfer code and into the application, do it in the disassembly view, and pay attention to the register contents, and where it jumps too.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    u23
    u23Author
    Associate III
    June 24, 2014
    Posted on June 24, 2014 at 12:35

    I am attaching

    the

    screen shoot

    ,

    you

    look at

    the values

    ​​of ST

    / LR

    before the jump.

    The

    reallocation

    of the vector table

    takes place

    in the application

    , I can not

    see

    the values ​​that

    assumes

    ST /

    LR

    in the application

    .

    Why the ResetHandler vector points to 0x08007165?

    Thanks

    ________________

    Attachments :

    SP_LR_Value.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0pM&d=%2Fa%2F0X0000000bej%2FBTil3SqiG4Z3snRRB8FUsqSistDtorqTzmxM4BR1m48&asPdf=false
    Tesla DeLorean
    Guru
    June 24, 2014
    Posted on June 24, 2014 at 15:41

    Probably because you haven't set up the target memory parameters correctly, or the linker script / scatter file.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    u23
    u23Author
    Associate III
    June 24, 2014
    Posted on June 24, 2014 at 17:04

    I attached the source code.

    Can you controller the target memory parameters?

    Thanks

    ________________

    Attachments :

    Bootloader.rar : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0du&d=%2Fa%2F0X0000000bei%2FlF9Sfv_k9.Pg7Don3jMcjpIi3UBIqNSJLg6MjTBSga0&asPdf=false
    Tesla DeLorean
    Guru
    June 24, 2014
    Posted on June 24, 2014 at 17:46

    You have to separate the Boot Loader and the Application. The Application needs to be compiled for the higher address (0x08008000 ?)

    0690X00000602rlQAA.jpg
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    u23
    u23Author
    Associate III
    June 25, 2014
    Posted on June 25, 2014 at 08:37

    The Application and Bootloader is separated.

    The option target for Application in attached.

    Y

    ou can give

    me

    some suggestions?

    Thanks

    ________________

    Attachments :

    Option_Application.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0fx&d=%2Fa%2F0X0000000beh%2F79pSp4wlNuLzYAqyevmpTo2AVFX.w1Shamk85PVWisE&asPdf=false
    u23
    u23Author
    Associate III
    June 25, 2014
    Posted on June 25, 2014 at 11:46

    I solved!

    The solution consist in settings the parameters in application code:

    1) In SystemInit function the ''VECT_TAB_OFFSET'' must be equal as 0x7000 (application address - 0x1000);

    2) The Application needs to be compiled for the higher address (0x08008000) with size equal 0x9000 (flash size - VECT_TAB_OFFSET);

    3) The first istruction in the main must be  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000).

    Tesla DeLorean
    Guru
    June 25, 2014
    Posted on June 25, 2014 at 12:22

    Sounds like you're modifying code that's already been adapted, the SCB->VTOR needs to end up pointing to 0x08008000, where FLASH_BASE = 0x08000000, VECT_TAB_OFFSET = 0x8000, or FLASH_BASE = 0x08008000, VECT_TAB_OFFSET = 0

    system_stm32f1xx.c

    ...
    /*!< 
    Uncomment
    the following line if you need to relocate your vector Table in
    Internal SRAM. */
    /* #define VECT_TAB_SRAM */
    #define VECT_TAB_OFFSET 0x8000 /*!< Vector Table base offset field.
    This value must be a multiple of 0x */
    ...
    void SystemInit (void)
    {
    /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
    /* Set HSION bit */
    RCC->CR |= (uint32_t)0x00000001;
    ...
    /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
    /* Configure the Flash Latency cycles and enable prefetch buffer */
    SetSysClock();
    #ifdef VECT_TAB_SRAM
    SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
    #else
    SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
    #endif
    }

    Personally I prefer letting the linker do it by using SCB->VTOR = __Vectors;
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    u23
    u23Author
    Associate III
    June 25, 2014
    Posted on June 25, 2014 at 14:19

    The VECT_TAB_OFFSET must be equal 0x7000 ( 0x8000 - offset) else not function! This for application.

    You need configure the option device:

    0690X00000602vDQAQ.jpg

    ________________

    Attachments :

    OptionTarget.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0od&d=%2Fa%2F0X0000000beg%2FkL8FbDF3Dx0X5io6..3K2Z76U7RY3YIiRb6p3ECY2V8&asPdf=false
    Tesla DeLorean
    Guru
    June 25, 2014
    Posted on June 25, 2014 at 15:07

    Awesome, I hope this all works out for you, but the presented facts appear internally inconsistent.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..