cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to understand the logic in Bootloader to test if user code is present at application address

ramya
Associate
Posted on February 24, 2016 at 09:17

In the examples provided for STM32(STM32L476G_EVAL), there is a logic written to test whether user code is present in the application address before jumping.

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

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

    {

      /* Jump to user application */

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

      JumpToApplication = (pFunction) JumpAddress;

      /* Initialize user application's Stack Pointer */

      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

      JumpToApplication();

    }

I am unable to understand why 0x2FFE0000 is used to AND with the value of the APPLICATION_ADDRESS. Can someone help me with this?

#lmgtfy #stm32 #stm32 #bootloader #bootloader #!stm32
5 REPLIES 5
Radosław
Senior
Posted on February 24, 2016 at 10:02

Check if MSP (stack pointer) of aplication is in range of SRAM.

ramya
Associate
Posted on February 24, 2016 at 13:04

Yes, the MSP is within the range of RAM. There is no problem in jumping to my application code. The application runs fine after the jump.

What I am unclear is why 0x2FFE0000 is used to AND with the value of APPLICATION_ADDRESS.

Posted on February 24, 2016 at 13:31

It is not testing the address, it is testing what is AT the address, which should be an initial stack pointer, that needs to be in RAM.

I've gone over this several times in the last few weeks

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/CSTACK%20issue%20with%20IAP&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=38]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FCSTACK%20issue%20with%20IAP&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=38

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
skupp
Associate II

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

   {

     /* Jump to user application */

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

     JumpToApplication = (pFunction) JumpAddress;

     /* Initialize user application's Stack Pointer */

     __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

     JumpToApplication();

   }

Can any one please explain the logic of the code and how to check whether MSP(stack pointer) is in the range of SRAM. Also Please explain why APPLICATION_ADDRESS is added with 4.

Perhaps review some basic documentation on the Cortex-Mx​ cores to understand the concept and form the vector table takes.

The RAM test checks to see a value in range of 0x20000000..0x2001FFFF, this may not be adequate depending on specific part in question.​

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