AnsweredAssumed Answered

Running code from fixed address in flash

Question asked by stevedecoen on Dec 17, 2015
Latest reply on Dec 23, 2015 by stevedecoen

Hi

 

I want to run a function (hw_InitLL()) that resides in Program Code from Bootloader .

 

What i did to accomplish this

 

in linker files of both program and bootloader :

m_hw_InitLL (RX) : ORIGIN = 0x000020C0, LENGTH = 0x00000200

SECTIONS

/* The HwInit code goes first into INTERNAL_FLASH */

  .hw_InitLL :

  {

*(.hw_InitLL)

  } > m_hw_InitLL

 

in Program code :

void hw_InitLL(void) __attribute__((section(".hw_InitLL")));

 

void hw_InitLL(void)

{

  // do some hw initialisation

  // in this example i return without any other code

}

 

if i check the linker output after building both projects, i see function InitLL at address 0x20C0 which i wanted.

 

When i run hw_InitLL(); in program code, then it executes fine as expected. U can see assembly and memory content in this prtscr

hw_init_from prog code.PNG

 

in BL code :

 

When i run ((void (*) (void)) 0x000020C0) (); , then it jumps to addess 0x20C0 as expected. i can see the memory content is the same, but there are other assembly instructions in disassembly window (see prtscr). When i step further i run into a hardware fault

hw_init_from BL code.PNG

 

 

I did use a HardwareFault component in processor expert. This gives me stacked_lr : 5159 -> "Unable to retrieve disassembly data from backend".

 

My Question

 

Why do i see the same memory content but is codewarrior not able to show these as assembly instructions?

Why do i run into a hardwarefault?

 

Is there any way to execute that piece of code from 2 different places?

 

I will tell u why this is so important .. I want to use my BL in different hardware. When for example i use hardware with different ports assigned to different functions , like controlling a motor, i dont want the ports in an unitialized stated during the time needed to update the firmware.

So what i do is this -> Program code gets instruction to update firmware -> write an update flag in Eflash -> reset -> BL starts and run hw_InitLL() (must run from program code) -> BL erase flash and update with new program

 

I appreciate anyone's help very much.

 

Thank u

Steve

Outcomes