This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using #pragma RETAIN to store interrupt vector in RAM on boot up?



I would like to know just exactly what #pragma RETAIN is doing because this line isn't making sense to me and the documentation by TI is quite vague.  

Basically, I have a custom mini-bootloader that will boot into a main application. The miniboot will be running the standard interrupt vector in flash while the main app will be using interrupt vector in RAM.  

When the miniboot jumps to the main app address, the first thing the app will do is create a constant structure with it's starting address at the interrupt vector address (in SRAM).  I noticed that if I were to use: #pragma RETAIN(ram_int_vect), everything works beautifully and my TI-TXT output has the ISR addresses written in 0x3800 area.  Ram_int_vect is an instance of a structure of ISR pointers and is defined as a constant before main (which you can call global).

Now if the #pragma RETAIN(ram_int_vect) is omitted, the TI-TXT file no longer shows the ISR addresses at 0x3800 memory area, and my program behaves real funky due to the ISR addresses getting over-written.

So my question is, does the program really depend on having the addresses in the TI-TXT file?  If the pragma retain was used, but I did not download any binary information from the 0x3800 area (only the 0x8000 flash program area), then would the main application behave correctly?  

Second, is it true that if the #pragma retain is not used, then the linker/compiler is optimizing the code and removing this from the binary because it believes it is not in use?  Is that why i'm seeing problems when I omit this line?

Thanks

  • >Second, is it true that if the #pragma retain is not used, then the linker/compiler is optimizing the code and removing this from the binary because it believes it is not in use?  Is that why i'm seeing problems when I omit this line?

    Exactly.

    The RETAIN pragma can be applied to a code or data symbol. It causes a .retain directive to be generated into the section that contains the definition of the symbol. The .retain directive indicates to the linker that the section is ineligible for removal during conditional linking. Therefore, regardless whether or not the section is referenced by another section in the application that is being compiled and linked, it will be included in the output file result of the link.

**Attention** This is a public forum