I'm going to write 2 revisions of the same program to flash and make a bootloader which will start one of them, depending on some criterias.
Hi Krzysztof Sawicki,
You can do this by creating new sections in Flah using scatter (Linker) file . See example shown in this thread.
Not sure right now, but ST link should be able to load code into any location of memory? However it is much more convenient to have one file, or you can use the gnu tools to append one code at the end of other or so to create one binary out of it (objcopy???). I think it's the same process as loading a bootloader and an app into the MCU.
Have a nice day,
It is not a problem for me to load the code at any position, but the problem is: how to get the machine code which will run at any position (this means no absolute adresses, jumps etc.).
The feature you look for is called 'PIC' (Position Independent Code); At gcc -fpic option would generate PIC code.
If can refer directly to the gcc Code Generation Options ( https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options ) and ARM machine dependent options ( https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html#ARM-Options ) for details.
ARM Cortex-M should support -fpic since there are ARM specific options around PIC such as
Some things work (GPIO based) and some not.
HAL_Delay() with the use of Systick will never return.
Using a Timer for HAL_Delay(), the application is not even executed.
I'm still looking for the right recipe.
The vector table contains absolute addresses, you'd want to fixup/rebase that into RAM
Thank you so much!
Can you please share your solution? I am having some sanity issues with relocating executable code into RAM.
In my case:
/* USER CODE BEGIN 1 */
SCB->VTOR=0x080C0000; // my app is located at this address in Flash
Doesn't seem like that would address absolute addresses when the image was loaded at an arbitrary address.
Hi Joerg Wagner ,
request you please share the solution with details of require compiler - linker settings required.
Do you understand the concept of the vector table used in the Cortex-Mx parts? You'll need to exclude a sector of RAM (512 byte aligned) into which you will need to create a new vector table, you'll go through the vectors adjusting the addresses to reflect the address you've chosen to place the executable code. After that you'll need to point SCB->VTOR at this new table. If you link the image with a ZERO based address you can add the new offset to each vector.
Work product might not be sharable, especially if you work in a competitive company. Apply your knowledge/appreciation of compilers, linkers and loaders when it comes to creating relocatable objects with the tools you have chosen.
Linux style code which can be ram loaded anywhere in the memory space is to be in demand in embedded bare metal or rtos space. It basically forbid to use the satically defined heap space by the linker. In 1990's HW access was done through what became the bios, through so called SWI #nn to make code more relocatable. If the code only use stack, then something might be ironed out. Indirect addressing in accessing data or function by pointers may cost cycles and acceleration bumps. These are performance or energy penalties when developping deep embedded apps on battery budget.
Retrieving data ...