cancel
Showing results for 
Search instead for 
Did you mean: 

jumping from bootloader to application

smart
Associate II
Posted on August 21, 2008 at 17:12

jumping from bootloader to application

6 REPLIES 6
smart
Associate II
Posted on May 17, 2011 at 12:24

I have two questions regarding source code of AN 2557 (IAP using USART). I hope somebody can help me

1] In the source code file main.c what is the idea behind to check the

Flash if it is already programmed.How do we know that this value will always be 0x20000000 for any software? Is this related with compiler?

2] When I do debugging I can see that the function pointer points to 0x08002121 Why? it should point to 0x08000004 (Application address + 4) .

Looks like first compiler gets the value from address 0x08000004

and jumps to the that value not the application address(0x8002000)

what's the idea to read the value from address (Application address + 4) and execute the code from that location.

Can anybody provide me some more information with these two questions? Code is given below from AN2557

Thanks

typedef void (*pFunction)(void);

#define ApplicationAddress 0x8002000

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

if (((*(vu32*)ApplicationAddress) & 0x2FFF0000 ) == 0x20000000)

{

/* Jump to user application */

JumpAddress = *(vu32*) (ApplicationAddress + 4);

Jump_To_Application = (pFunction) JumpAddress;

/* Initialize user application's Stack Pointer */

__MSR_MSP(*(vu32*) ApplicationAddress);

Jump_To_Application();

}

16-32micros
Associate III
Posted on May 17, 2011 at 12:24

Hi smart.avr 🙂

Your nickname is cute and seems you are an Atmel AVR fan ! Welcome in our STM32 group 🙂 , To go back to your questions :

Quote:

1] In the source code file main.c what is the idea behind to check the Flash if it is already programmed.How do we know that this value will always be 0x20000000 for any software? Is this related with compiler?

The idea here is just an tutorial example to check if this new vector table base offset,which contains the Stack Pointer, is really a valid address in the phyiscal RAM or not ? this is not a compiler dependant and all toolchain linkers should have the vector table at the first address of the final application Address ''#define ApplicationAddress 0x8002000 ''

However, the main purpose is to check the IAP program has downloaded a valid image or the flash content is not corrupted by some UART transmission or power failure etc.. and this avoids jumping to a wrong program that may execute a wrong sequence that will harm your hardware etc.. In the field to most used method is to use a CRC software to check the consistency of your flash image before jumping to final code.

Quote:

2] When I do debugging I can see that the function pointer points to 0x08002121 Why? it should point to 0x08000004 (Application address + 4) .

Looks like first compiler gets the value from address 0x08000004

and jumps to the that value not the application address(0x8002000)

what's the idea to read the value from address (Application address + 4) and execute the code from that location.

(Application address + 4) Contains the reset Handler of your final application and is an obsolute address so with debugger the PC ( program counter) will point you to the obsolute address that is contained

at (Application address + 4) and in your case it is 0x08002121.

For more details on Vector table and cortex-M3 boot mode you can have a look on ARM - Cortex-M3 Technical Reference Manual. Hope thsi helps you.

Regards,

STOne-32 :p

smart
Associate II
Posted on May 17, 2011 at 12:24

Thanks for your reply.

Based on your explanation we jump to reset vetcor placed at Application address + 4 that makes complete sense.

Can you please tell me how we can jump to an absoulte address in main application in STM32 and we have the statup code reset vector and INVEC table only in Bootloader project not in main application project.

In AN2557 source code I can see two IAR embedded project ST32F10X_IAP.ewp and SysTick.ewp

I can see both project setting are setup so that code execution starts from default __program_start using IAR compiler.

Both projects have the startup code ,reset vector and INTVEC table at different memory locations.

For our application we want to put the startup code,reset vector and INTVECTab only in Bootloader project not in main application project.

In that case how we can use this code, I also tried some other absolute jump code I always get the hard fault exception. can you please help me. if I am not clear I will send you more detail info with example.

/* Jump to user application */

JumpAddress = *(vu32*) (ApplicationAddress + 4);

Jump_To_Application = (pFunction) JumpAddress;

/* Initialize user application's Stack Pointer */

__MSR_MSP(*(vu32*) ApplicationAddress);

Jump_To_Application();

st3
Associate II
Posted on May 17, 2011 at 12:24

Quote:

The idea here is just an tutorial example to check if this new vector table base offset, which contains the Stack Pointer, is really a valid address in the phyiscal RAM or not ?

In other words, it's checking that the address falls within the range 0x20000000 to 0x2000FFFF ?

This makes sense with the check shown in the original post:

Code:

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

if( ( (*(vu32*)ApplicationAddress) & 0x2FFF0000 ) == 0x20000000 )

{

/* Jump to user application */

But, in the latest download of the App Note code, it has chabged to:

Code:

if( ( (*(vu32*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000 )

Why has the mask changed to 0x2FFE0000 ?

tibo
Associate II
Posted on May 17, 2011 at 12:24

in high density devices the max. ram address is 0x2000FFFF

(64 KB) and the initial stack pointer can point to

0x20010000. If you make a test on a stackpointer the

test value 0x2FFE0000 is correct.

st3
Associate II
Posted on May 17, 2011 at 12:24

Quote:

max. ram address is 0x2000FFFF (64 KB) and the initial stack pointer can point to 0x20010000.

Thanks - that makes sense! :D

So, as a refinement, one could adjust this to match the actual RAM available on the particular device in use...

[ This message was edited by: st7 on 21-08-2008 20:45 ]