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.

Code protection (FMPPE=1 FMPRE=0) and compiler limitation

Dear,

We want to copy-protect our code and it is done by setting FMPPE=1 FMPRE=0 for the corresponding registers where the .text segment is allocated. Unfortunately this causes a "fault interrupt" when the code is executing. I have read https://e2e.ti.com/support/microcontrollers/stellaris_arm/f/471/p/302797/1056967#1056967, and here it is stated that most compilers will place data sections inline with the code, which is not convenient when the flash is read protected. Is it possible to avoid this limitation, we are using CCS 5.04

Best regards,
Jesper

  • Hello Jesper,

    As Bobby did mention, the only method is to write the specific code in assembly.

    Regards
    Amit
  • jbu said:
    Is it possible to avoid this limitation, we are using CCS 5.04

    If you are using the TI ARM compiler the --embedded_constants option may help.

    From the description of the optino in the ARM Optimizing C/C++ Compiler v5.2 User's Guide SPNU151J:

    --embedded_constants={on|off}

    By default the compiler embeds constants in functions. These constants can include literals, addresses, strings, etc. This is a problem if you wants to prevent reads from a memory region that contains only executable code. To enable the generation of "execute only code", the compiler provides the --embedded_constants=[on|off] option. If the option is not specified, it is assumed to be on. The option is available on the following devices: Cortex-A8, Cortex-M3, Cortex-M4, and Cortex-R4.


    [I haven't tried this option together with code protection]

  • Hi Chester,

    Thank you for the answer!

    I did try the --embedded_constants option without any luck before I posted the question. But after receiving your answer I gave it at retry, and found that I missed the option in one of the libraries I am using - after fixing that, and rebuilding everything it seems to work, the code is actually running with read protection (FMPPE=1 FMPRE=0) :-)
    I will do some additional testing to verify the impact on performance, and publish the results later on.

    Thanks again :-)

    Regards,
    Jesper
  • Hello Jesper,

    I have some follow up that I had marked on this post.

    1. Were you protecting Sector-0 or some other sector of the device?

    Regards,
    Amit