Defining Const Variables for Fixed Address in PSoC 4 - KBA229222

Version 3

    Author: LinglingG_46         Version: **

     

    Translation - Japanese: PSoC 4 で定数を固定アドレスに配置する方法 - KBA229222 - Community Translated (JA)

    Question:
    How can I define const variables for the fixed address in PSoC® 4?

    Answer: 
    Const variables can be allocated for a fixed address in flash. To do this, you must modify the linker control file (linker script).

    You must calculate the application end address and select the address of the const var storage, so that the memory spaces of storage and application do not overlap.

    Follow these steps to update the linker control file for GCC and MDK compilers for PSoC 4 devices and define var:

     

     

    1. Open a project and build it. This is required to generate a linker script.

     

    2. Go to the linker script directory located at \<project_name>.cydsn\Generated_Source\PSoC<4, 5>\.

    For the GCC compiler, the linker control file name is cm0gcc.ld\cm0plusgcc.ld.

    For the MDK compiler, the linker control file name is Cm0RealView.scat / Cm0plusRealView.scat.

     

    3. Select the required linker script, copy it in the same directory, and rename the script. For example, rename cm0gcc.ld to custom_cm0gcc.ld (similarly rename Cm0RealView.scat to Custom_Cm0RealView.scat).

     

    4. Open the Build Settings dialog. From the left pane, expand the Linker node under the selected compiler. Select General. Then, click the ellipsis [] button corresponding to Custom Linker Script and select the appropriate file.

    For GCC, select the custom_cm0gcc.ld file.

    For MDK, change the file type to *.scat, and then select the Custom_Cm0RealView.scat file.

    5. Click OK.

     

    6. For the GCC compiler, open the custom linker script (custom_cmogcc.ld) and search for the following declaration:

     

    .cy_checksum_exclude : { KEEP(*(.cy_checksum_exclude)) } >rom

    a. Copy the following code and paste it right after the declaration:

    #define   MY_VAR_START_ADDRESS      < the absolute address in flash>

    .my_emulated_eeprom MY_VAR_START_ADDRESS :

    {

         KEEP(*(.my_var_fix_addr))

    } >rom

    b. Save the changes and close the file.

    For the MDK compiler, open the custom linker script (Custom_CmoRealView.scat) and search for the following declaration:

    APPLICATION APPL_START (CY_FLASH_SIZE - APPL_START)

    {

        ...

    }

     

    a. Copy the following code and paste it right after the declaration:

    #define   MY_VAR_START_ADDRESS      < the absolute address in flash>

      EM_EEPROM ( MY_VAR_START_ADDRESS )

      {

           . my_var_fix_addr+0

    {

                *(.my_var_fix_addr)

           }

      }

    b. Save the changes and close the file.

     

    7. Declare the const var in the newly created section. To do this, declare an array in flash. Here is an example of an array declaration:

    const uint8 Test[512] 

    CY_SECTION(".my_var_fix_addr") = {0xFFu,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF,0x55};

    https://www.cypress.com/documentation/application-notes/an89610-psoc-4-and-psoc-5lp-arm-cortex-code-optimization