Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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

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();

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?

stm32f103 address 0x8000000
:02 0000 04 0800 F2
:10 0000 00 C8060020 A901 0008 AD01 0008 AF01 0008 E2
:10 0010 00 B101 0008 B301 0008 B501 0008 0000 0000 AC

stm32f103 address 0x8008000
:02 0000 04 0800 F2
:10 0000 00 C8060020 A901 0008 AD01 0008 AF01 0008 E2
:10 0010 00 B101 0008 B301 0008 B501 0008 0000 0000 AC


stm32f407 address 0x8000000
:02 0000 04 0800 F2
:10 0000 00 28990020 9D01 0008 5D09 0008 5909 0008 91
:10 0010 00 5B09 0008 9902 0008 C739 0008 0000 0000 C9

stm32f407 address 0x8008000
:02 0000 04 0800 F2
:10 8000 00 28990020 9D81 0008 5D89 0008 5989 0008 91
:10 8010 00 5B89 0008 9982 0008 C7B9 0008 0000 0000 C9

- - - 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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top