cancel
Showing results for 
Search instead for 
Did you mean: 

Position-Independent Code for STM32L4 relocatable application

helmi haddad
Associate II

how i can configure my project to make a relocatable application , i use the IAR workbench.

  1. i activated the --ROPI option in IAR Options
  2. i modified the .s file as follow :
MODULE  ?cstartup
 
        ;; Forward declaration of sections.
        SECTION CSTACK:DATA:NOROOT(3)
 
        SECTION .intvec:CODE:NOROOT(2)
 
        EXTERN  PI_Reset_Handler
        PUBLIC  __vector_table
.
.
.
        PUBWEAK Reset_Handler
        SECTION .text:CODE:NOROOT:REORDER(2)
Reset_Handler
        LDR     R0, =PI_Reset_Handler
        BX      R0
.
.
.
  1. i modified in main.c
...
/* Private functions ---------------------------------------------------------*/
 
extern void __iar_data_init3(void);
 
extern void __iar_program_start(void);
 
void PI_Reset_Handler(void)
{
    SystemInit();
    __iar_data_init3();
    __iar_program_start();
}
 
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{ ....

But when i put the binary file of app in flash at address (0x8010000) , my boot when jump to app , the app can't run . i remarked that the NVIC must be relocated . but the problem when i relocated the NVIC ( add an offset x10000) , i see the same problem .

So how i can configure my app to be relocatable please ?

5 REPLIES 5

Will still have to deal with the fact the vector table has absolute addresses.

In IAR I'd expect a check box item for compiler/linker to generate position independent code. Check the documentation and support materials, surely covered.

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

where i can found the documentation please ?

David SIORPAES
ST Employee

Options / C/C++ Compiler / Code / Position-independence

0690X00000898rNQAQ.png

I already activated this option , i still have the problem how the IVECT table be relocatable ?

Alex R
Senior

Check the system_stm32l4xx.c and system_stm32l4xx.h files for the SystemInit() function.

At the end of it, you'll find the instructions to relocate the Vector Table.

In particular, you nee to write the SCB->VTOR register to set the address location (SRAM or FLASH) and the offset within that location.