2014-04-03 08:49 AM
Hello,
I'm trying to create a bootloader into the component STM32f106RDT with 384KO of Flash. I have mapped the memory like this: 0x08000000 - 0x0802DFFF for main software (first binary) 0x0802F000 - 0x08030FFF reserved 0x08031000 - 0x0805FFFF for the temp binary (second binary) My function of bootloader() to jump at selected main address is in flash. When I debug with keil the pc is in the file startup_stm32f10x_hd.s, then i want to go into my function bootloader so IMPORT the function like this : ; Reset handler Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main IMPORT SystemInit IMPORT FLASH_Bootloader /*my add*/ LDR R0, =SystemInit BLX R0 LDR R0, =FLASH_Bootloader /*my add*/ BLX R0 /*my add*/ ;LDR R0, =__main ;BX R0 ENDP The problem is that i want to jump on one of the two binary file. How do i get the flash address of the main() function? If i jump on 0x08000000+4 the beginning of the first binary mapping it does nothing. Somebody have an idea to select one of my 2 apps and run it? Thank you. #stm32 #bootloader2014-04-04 04:36 AM
Look, you're not trying to jump to 0x08000004 but the content pointed TOO by it, indirectly.
You also don't want to be jumping to the main() function because it would ignore all the C runtime startup code which copies your statics, and clears your initial variables. Observe the ODD address of the code that is supposed to get jumped too.2014-04-04 04:45 AM
My next function is going in hardfault handler, why?
Poor cut-n-paste job? Tried stepping through it with a debugger?void FLASH_Bootloader(void)
{
JumpAddress = *( (uint32_t *)0x08000004); // Load the ACTUAL content for initial PC
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) 0x08000000);
Jump_To_Application();
}
2014-04-04 06:28 AM
Thank you for replying and the screenshot,
this function is now working, but i'm reseting in loop. And when i'm pointing to the second binary at 0x8031000, with the same software than binary1 I have the same address pointing to 0x80000145 and So it point to the same point at first binary.2014-04-04 06:37 AM
Hi
''And when i'm pointing to the second binary at 0x8031000, with the same software than binary1 I have the same address pointing to 0x80000145'' The second version of the application need to be located differently.2014-04-04 06:49 AM
I agree,
how can I get the address of the function currently used? void FLASH_Bootloader(uint32_t* register_args) { pFunction Jump_To_Application; __IO uint32_t JumpAddress; uint32_t* CurrentStack; uint32_t BinToGo=2; CurrentStack=&FLASH_Bootloader(uint32_t*); /*not working, i'm trying to get the flash address of the current function*/ if(((uint32_t)CurrentStack>=(uint32_t)0x31000) && BinToGo==1)/*change to Binary1*/ { JumpAddress = *(__IO uint32_t*) (ADDRESS_BIN1+4); /*offset tab vector*/ Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) ADDRESS_BIN1); Jump_To_Application(); } else if(((uint32_t)CurrentStack<(uint32_t)0x2F000) && BinToGo==2)/*change to Binary2*/ { JumpAddress = *(((__IO uint32_t*)(ADDRESS_BIN2+4))+0x31000); /*offset of main function*/ Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(ADDRESS_BIN2); Jump_To_Application(); } else { /*don't change binary file*/ } }2014-04-04 06:58 AM
Hi
How does the bootloader decide which binary to use?2014-04-04 07:05 AM
When you don't change the binary, you continu to the __main.
The ''BinToGo'' will be dynamical, reading from an emulated EEPROM in the Flash. Like a flag to select with binary file to boot on. ; Reset handler Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main IMPORT SystemInit IMPORT FLASH_Bootloader /*my add*/ LDR R0, =SystemInit BLX R0 LDR R0, =FLASH_Bootloader /*my add*/ BLX R0 /*my add*/ LDR R0, =__main /*continue if no binary change*/ BX R0 ENDP2014-04-04 07:14 AM
You have to build two different binaries, as the Vector Table contains fixed/absolute addresses. To do this in Keil you have to modify the IROM(1) range in the Target dialog pane.
For examples to Boot Loader + App, review the IAP USART example code, and search also the forum where I covered this all before.2014-04-04 07:14 AM
Hi
I am confused about the current problem. Can you say again what the current problem is please?2014-04-07 12:25 AM
I think Clive1 you are right, may be I have to change the mapping in the scatter file to make my new binary. My problem Sung is that I have the two same binary file in two different part of flash, I can boot on these two binary BUT the address of the first pointing function is fixed, so my main() address will be always the same, pointing to the main of the first binary. I was meaning that there was an offset made but it don't look like so.
But with this method I need always to know where the new binary will be flashed, and this is a problem for me, because it should be random in function of my cards.