2008-08-21 08:12 AM
jumping from bootloader to application
2011-05-17 03:24 AM
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(); }2011-05-17 03:24 AM
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 :p2011-05-17 03:24 AM
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();2011-05-17 03:24 AM
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 ?2011-05-17 03:24 AM
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.2011-05-17 03:24 AM
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 ]