Running code from fixed address in flash

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Running code from fixed address in flash

Jump to solution
1,303 Views
stevedecoen
Contributor II

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

117190_117190.PNGhw_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

117191_117191.PNGhw_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

Labels (1)
0 Kudos
Reply
1 Solution
1,142 Views
stevedecoen
Contributor II

Hi Alice,

No need to post parts of the code . I found the solution,

i just need to call the function with an uneven address, so 0x020C1 instead of 0x020C0

Googling, I found:

The mechanism for switching makes use of the fact that all instructions must be (at least) halfword-aligned, which means that bit[0] of the branch target address is redundant. Therefore this bit can be re-used to indicate the target instruction set at that address. Bit[0] cleared to 0 means ARM and bit[0] set to 1 means Thumb.

Thank you for the help !

Steve

View solution in original post

0 Kudos
Reply
4 Replies
1,143 Views
stevedecoen
Contributor II

Hi Alice,

No need to post parts of the code . I found the solution,

i just need to call the function with an uneven address, so 0x020C1 instead of 0x020C0

Googling, I found:

The mechanism for switching makes use of the fact that all instructions must be (at least) halfword-aligned, which means that bit[0] of the branch target address is redundant. Therefore this bit can be re-used to indicate the target instruction set at that address. Bit[0] cleared to 0 means ARM and bit[0] set to 1 means Thumb.

Thank you for the help !

Steve

0 Kudos
Reply
1,142 Views
stevedecoen
Contributor II

Hello Alice,

Thank u for the response .

To answer your questions.

Are sure you have flash the function correctly -> both programs are flashed in different FLASH area's , when i debug bootloader code i make sure i don't wipe  Program code. i'm sure the hw_InitLL() instructions are still in flash when i call them. Thats what u see in the examples at address 0x20C0.
I also tried to run the code without debugger as this is maybe just a debugger issue, but then it also dont work .

U are right that the debugger says No source available, thats what i try to figure out why this is. I just want to execute "RAW "assembly instructions from flash address 0x020C0 and jump back in bootloader code . But the moment i the code at 0x20C0 starts to execute, it seems to generate an exception error.

hw_InitLL() resides only in Program Code. I compile BL code and Program code separate.

And what's different between the two test above you said. -> one test is in Program Code that shows the moment i jump into hw_InitLL() , the other test is in BL code where i jump to the address where hw_InitLL() code is located .


Thank u :smileyhappy:

0 Kudos
Reply
1,142 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello steve,

Through the "Actions" button you can attach fiels :

pastedImage_0.png

Also i will say hello to you email .

BR

Alice

0 Kudos
Reply
1,142 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Steve,

"reset -> BL starts and run hw_InitLL() (must run from program code) -> BL erase flash and update with new program"

In Bl, how do you jump to “hw_InitLL()”,and are sure you have flash the function correctly ,?  for i see it show :

pastedImage_0.png

And what's different between the two test above you said.

I see you use the chip of KE02, could you please show some code or project , i will be

facility to debug then find .

BR

Alice

0 Kudos
Reply