[SOLVED] [ASK] jumps to a specific address in STM32 Cortex-M3

Status
Not open for further replies.

Ahmad Edi Saputra

Junior Member level 2
Joined
Apr 2, 2015
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
209
[ASK] jump to specific address in STM32 Cortex-M3

Hi

i am currently using stm32f103C8, i want to build a custom bootloader in address 0x8000000 and my application will placed in 0x8008000.
in cortex M4 (stm32f407vgtx) i manage to jump to address 0x8008000 with these code

Code:
if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000){
      JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
      Jump_To_Application();
}

but these code seem doesn't work in cortex M3, i tried a few modification. like bellow, it doesn't work either. i am sure my application already in place. i check address 0x8008000 during debug, my binary app was already there, and yes i compile it with address 0x8008000

Code:
//JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
//Jump_To_Application = (pFunction) JumpAddress;
stackAddress = *(__IO uint32_t*) APPLICATION_ADDRESS;
SCB->VTOR = APPLICATION_ADDRESS;
__set_MSP(stackAddress);
//Jump_To_Application();
NVIC_SystemReset();

Best Regards
Edi
 

Re: [ASK] jump to specific address in STM32 Cortex-M3

Code:
typedef void (*pFunction)(void);
pFunction Jump_To_Application;
uint32_t JumpAddress;

..........YOUR CODE.............

  NVIC_SetVectorTable(NVIC_VectTab_FLASH, MAIN_FLASH_OFFSET);
	__disable_irq();
  JumpAddress = *(__IO uint32_t*) (MAIN_FLASH_OFFSET + 4);
  Jump_To_Application = (pFunction) JumpAddress;
  __set_MSP(*(__IO uint32_t*) MAIN_FLASH_OFFSET);
  Jump_To_Application();
 

Re: [ASK] jump to specific address in STM32 Cortex-M3

Thanks for your answer


i've tried, but it jump to the next instruction. here is what i meant

Code:
if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000){
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, APPLICATION_ADDRESS);
	__disable_irq();
	JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
	Jump_To_Application = (pFunction) JumpAddress;
	__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
	Jump_To_Application();
}
//next instruction

and if i do without calling Jump_To_Application() my bootloader back to main again after all statement in if block is executed. i have no idea why. what do you think?
 

Re: [ASK] jump to specific address in STM32 Cortex-M3

Code:
*(__IO uint32_t*)APPLICATION_ADDRESS)
is a the value in pointer address, not value of pointer itself. Just your misunderstanding I suppose.
 

Re: [ASK] jump to specific address in STM32 Cortex-M3

i tried to dig deeper, i break down the different hex from STM32f103 and STMF407, bellow is the hex i break down base on intel hex format. i found very interesting fact, that changes of ROM address in keil make no effect for stm32f103 (generated hex is exactly the same), but it has effect on stm32f407. i assume that start address in stm32f407's hex change (0000 and 8000) and i think jump command has also pointed to different location (9D01 and 9D81. i have not found a way to change ROM for stm32f1 yet, any idea?




- - - Updated - - -

Code:
*(__IO uint32_t*)APPLICATION_ADDRESS)
is a the value in pointer address, not value of pointer itself. Just your misunderstanding I suppose.

yah, it is the value from memory address (APPLICATION_ADDRESS or MAIN_FLASH_OFFSET). when i debug, it already has the correct value, if not, it would not be executed at the first time, i mean there is an if to make sure stack pointer has correct offset from 0x20000000

Code:
if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000){
//something here
}
 

Re: [ASK] jump to specific address in STM32 Cortex-M3

i think i just figured that out. its definitely linker problem, i change rom base address in the linker option. thanks, i'll mark as resolved
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…