Bootloader jump to main app

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

ngoncalves
Posts: 9
Joined: Tue Apr 03, 2012 3:34 pm

Bootloader jump to main app

Mon Apr 09, 2012 3:45 pm

Hi,

I am trying to jump from my bootloader to the start of the main app. I modified the linker scripts so that the bootloader is between 0x00400000 (the start of the flash in the Atmel SAM3S4C) and 0x00400FFF . The main app starts at 0x00401000.

The code which I am using is this (in IAR for ARM, v6.3):

Code: Select all

   #define FIRMWARE_START_ADDRESS (0x00401000)
   #define FIRMWARE_RESET_ADDRESS (FIRMWARE_START_ADDRESS  + 4)

   void (*runFirmware)(void) = NULL ; 

  __set_MSP(*(int *)FIRMWARE_START_ADDRESS) ; 
  
  // offset the start of the vector table (first 6 bits must be zero)
  // The register containing the offset, from 0x00000000, is at 0xE000ED08
  *(int *)0xE000ED08 = FIRMWARE_START_ADDRESS ;
     
  // jump to the start of the firmware, casting the address as function pointer
  // to the start of the firmware
  runFirmware = (void(*)(void))(FIRMWARE_RESET_ADDRESS) ;
  
  runFirmware() ; 
I am almost sure the code is correct, but for some reason it ends up triggering a hard fault exception.

Can it be a problem with the addresses ? Using the debugger, I noticed that the reset handler (in the vector table) is at 0x0040AD3D, but the startup function in fact is at 0x0040AD3C (one byte before).

I also tried making the jump to the main() of my application (I found the start address in the linker map file) and it worked. But then it should also work for the function in the reset table, no ?

Any suggestions to what I am doing wrong ?

Nelson Gon\c calves
ngoncalves
Posts: 9
Joined: Tue Apr 03, 2012 3:34 pm

Re: Bootloader jump to main app

Mon Apr 09, 2012 4:07 pm

Found the problem.

This

Code: Select all

runFirmware = (void(*)(void))(FIRMWARE_RESET_ADDRESS) ;
is wrong. I am jumping to the position of the reset handler in the vector table, instead of the address to which it is pointing.

This is correct

Code: Select all

runFirmware = (void(*)(void))(*(int *)FIRMWARE_RESET_ADDRESS) ;
What a noob mistake !

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 4 guests