2019-01-26 07:09 AM
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.
2019-01-26 07:21 AM
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.
2019-01-26 08:04 AM
I understand how it work in theory and I made test code with copied one function from mcu flash to ram but i don'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.
2019-01-26 08:47 AM
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.
2019-01-26 09:05 AM
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....
2019-01-26 09:38 AM
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.
2019-01-26 01:31 PM
https://community.st.com/s/question/0D50X00009Xki6WSAR/bootloader-and-jumping-to-flash-location
2019-01-28 06:26 AM
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
.....
2019-01-28 06:46 AM
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.
2019-01-28 06:49 AM
uint32_t pc = *(__IO uint32_t*) &func[1]; // The Initial PC in a Vector Table