Keil Logo

ARMCC: LOCATE CONSTANTS TO FIXED LOCATIONS


Information in this article applies to:

  • RealView C Compiler Version 3

QUESTION

I am using a Philips LPC2000 device. To read protect the chip, I want to locate a constant at a fixed memory location (0x1FC) in the Flash ROM.

What is the best way to do this?

ANSWER

To locate a constant at a fixed address you must create a small module that contains the constant, and modify the scatter file to reference that module. Here are the steps:

  1. Write the following C module called ABS_ADDRESS.C to define the constant:

    #pragma push
    #pragma Ono_remove_unused_constdata
    unsigned int const Security_Value = 0x87654321;
    #pragma pop
    

    Make sure that you reduce optimization with:

    #pragma Ono_remove_unused_constdata
    

    Without this directive, the linker could remove the constant from the final object.

  2. Locate the project's scatter file. µVision creates a scatter file (with the extension *.SCT) when the Use Memory Layout from Target Dialog option (Project — Options for Target — Linker) is checked. The scatter file looks like this:

    LR_IROM1 0x00000000 0x00080000  {  ; load region
      ER_IROM1 0x00000000  {       ; load address = execution address
       *.o (RESET, +First)
       * (+RO)
      }
      RW_IRAM1 0x40000000 0x00008000  {  ; RW data
       * (+RW +ZI)
      }
    }
    
  3. Disable the Use Memory Layout from Target Dialog option, then specify the scatter file under Project — Options — Linker — Scatter File and change the content of this file to:

    LR_IROM1 0x00000000 0x00080000 { ; load region
      ER_IROM1 0x00000000 { ; load address = execution address
        *.o (RESET, +First)
        .ANY (*)
      }
    
      ABS_ADDRESS 0x1FC FIXED 4 {
        abs_address.o (*)
      }
    
      ER_IROM2 +0 0x80000 {
        * (+RO)
        .ANY(*)
      }
    
      RW_IRAM1 0x40000000 0x00008000 { ; RW data
        * (+RW +ZI)
      }
    }
    

This will locate the constant in the file ABS_ADDRESS.C to memory location 0x1FC.

The linker will still remove unused sections. To avoid that you need to enter the directive --keep abs_address.o(.constdata) under Project — Options — Linker — Misc controls.

MORE INFORMATION

  • RealView Linker and Utilities User's Guide

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Wednesday, November 15, 2006


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.