cancel
Showing results for 
Search instead for 
Did you mean: 

How is make run program from ram

MMykh
Associate II

Hi ​every body.

I need to make change some external program.

In external spi flash ​i want write meny programs, and one selected program must copy to ram in fixed start address for call from main program like shift program.

10 REPLIES 10

Build the many programs, as you would with an overlay, so they run at a specific address in RAM. Copy the executable code into RAM. Transfer control via a function pointer. Consider having a table of entry points at the front of the image.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MMykh
Associate II

I understand how it work in theory and I made test code with copied one function from mcu flash to ram but i do​n't understand why it not work. When i use function pointer to function in internal flash all work fine my function has address 0x080048c8, i call function from 0x080048c9 and it work, but when i copied function from 0x080048c8 to ram 0x20001000

After ​copied i try call function throght pointer on 0x20001001 address bun mcu anly skip this call and work next step... and i don't understand what i do wrong.

Yes, sounds good.

You should disassemble the instructions at 0x20001000, and step into the.

Try something simple like setting a register and then a BX LR

Watch for calling other functions, the calls are relative and might be out of scope if the code is moved.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

QSPI flash with XIP (execute in place) is an alternative option.

Data cache, when available, makes performance pretty good.

Otherwise consider what would happen if you shift the location of the content of a function.

Compilers usually use absolute address in assembly op-codes for jumps, switch/case, etc...

It's not as easy as in an MPU/CPU with linux type relocatable code.

Depending on the toolchain, maybe compile with the final image?

Check the IDE manuals on how to generate RAM code or relocatable code.

It's a bit like how to relocate the interrupt vector table from Flash to RAM....

MMykh
Associate II

Thaks for reply. Now i understand is not easy. ​

QSPI flash don't want use because device must cost much money. Fast performances to ​access spi flash programs don't need,

From spi must loading only one function at fixed address.​

https://community.st.com/s/question/0D50X00009Xki6WSAR/bootloader-and-jumping-to-flash-location

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MMykh
Associate II

I try to use exemple IAP but perhaps I did some thing wrong....

If can you help me, what I did uncorrect...

I try:

1)

uint8_t func[0x2dc]; // massive fo data from function

main

   SCB->VTOR = ( uint32_t )&func ;// registred vector

  __set_MSP(*(__IO uint32_t*) &func[0]); //registred pointer

//then call function by

( ( void ( * )( void ) )(&func[1]) )();

but in this code give me error defaul_hendler

.....

Would suggest that you have some interrupt(s) enabled that you aren't handling.

You're not trying to call the address of the vector, but the content of the vector.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

uint32_t pc = *(__IO uint32_t*) &func[1]; // The Initial PC in a Vector Table

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..