Modifying the Default Memory Map in FX3, CX3, FX3S, SD3, FX2G2, and SD2 - KBA229114

Version 2

    Author: KandlaguntaR_36           Version: **

     

    Question: How can I modify the linker script file in FX3, CX3, FX3S, SD3, FX2G2, and SD2?

    Answer: Cypress FX3 family chips are available in two SRAM sizes: 256 KB and 512 KB. Each SRAM size chip has its own memory mapping, provided through the linker script files (.ld files). In addition to the linker script files, every project must have the cyfxtx.c file in the project directory. The cyfxtx.c file provides application-specific exception handlers and memory allocation routines. The linker script file is used at the linker stage in the Eclipse integrated development environment (IDE) to build the Executable and Linkable Format (.elf) file. The macros defined in cyfxtx.c are used at runtime to allocate driver heap and DMA buffer memory areas.

    Sometimes, memory mapping provided in the default linker script file (.ld file) and the cyfxtx.c file might conflict with your requirements. For example, you might require a code area size of 212 KB, but the default code size is set to 180 KB in linker script file. This knowledge base article (KBA) addresses such issues, and provides steps to modify the linker script file and the cyfxtx.c file for the 512 KB SRAM chip. You can also refer to this KBA for modifying the 256 KB SRAM chip.

     

    Default Linker Script File

    The default linker script file (fx3.ld) for 512 KB SRAM chip is available in the FX3 SDK at the default path: C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\fw_build\fx3_fw.

    The linker script file allocates memory for the Instruction Tightly-Coupled Memory (ITCM) section and SYSTEM Memory and Data Memory.

    The ITCM is a 16-KB dedicated space for holding exception vectors and interrupt service routine (ISR) code. While it is possible to read and write to the ITCM memory region from the Arm® CPU, it is not possible to use this memory region as a target for DMA transfers. Note that the ITCM is not a part of 512 KB SRAM memory space.

    The SYSTEM Memory space is used to store the application code and is also called as Code area.

    The Data Memory space is used to store the initialized data and BSS data (uninitialized global data).

    Default Memory Map of 512 KB SRAM

    Table 1 lists the default application memory map of 512 KB FX3 family chip. Note that the address of 512 KB SRAM starts at 0x40000000 and ends at 0x4007FFFF. 

    Table 1. Default Memory Map of 512 KB FX3 Family Chip

     

    Base Address

    Size (KB)

    Descriptor Area

    0x40000000

    12

    Code Area

    0x40003000

    180

    Data Area

    0x40030000

    32

    Driver Area

    0x40038000

    32

    Buffer Area

    0x40040000

    224

    Second Stage Boot Area

    0x40078000

    32

    Note: The second stage boot area is optional (only required if the application makes use of a persistent in-memory boot-loader). If this boot area is not being used, the 32 KB reserved for this segment can be merged with the buffer area by changing CY_U3P_SYS_MEM_TOP to 0x40080000 in cyfxtx.c.

    The above memory mapping is documented in the cyfxtx.c file of every FX3 family example project.

    Modifying the Linker Script File and cyfxtx.c File

    Assume that a user application has the following requirements:

    • Code size of 212 KB
    • Maintain DMA buffer space of 224 KB

    To increase the code size by 32 KB while maintaining the DMA Buffer Size at 224 KB, you must deallocate the second stage bootloader area.

    To adjust the memory space as per your requirements, modify the default memory mapping in the linker script file and MACROS defined in the cyfxtx.c file.

    Follow these steps to modify the linker script file:

    1. Change the LENGTH of SYS_MEM space to 0x35000 (equivalent to 212 KB)

     

    SYS_MEM : ORIGIN = 0x40003000    LENGTH = 0x35000

    2. Adjust the ORIGIN of DATA space to 0x40038000 (that is, 0x40003000 + 0x35000)

     

    DATA   : ORIGIN = 0x40038000    LENGTH = 0x8000

     

    After modifying the linker script file, modify the MACROS in the cyfxtx.c file:

     

    1. Change the Heap base to 0x40040000

     

    #define CY_U3P_MEM_HEAP_BASE         (0x40040000)

     

    2. Change the SYS_MEM_TOP to 0x40080000

     

    #define CY_U3P_SYS_MEM_TOP           (0x40080000)

     

    Note that the last 32 KB of RAM is reserved for second-stage boot operation. The SYS_MEM_TOP value is changed to 0x40080000 since the second stage boot area is not required in the application.

     

    Table 2 compares the default memory map with the modified memory map.

     

    Table 2. Comparison between Default and Modified Memory Maps

     

    Default Memory Map

    Modified Memory Map

    Base Address

    Size (KB)

    Base Address

    Size (KB)

    Descriptor Area

    0x40000000

    12

    0x40000000

    12

    Code Area

    0x40003000

    180

    0x40003000

    212

    Data Area

    0x40030000

    32

    0x40038000

    32

    Driver Area

    0x40038000

    32

    0x40040000

    32

    Buffer Area

    0x40040000

    224

    0x40048000

    224

    Second Stage Boot Area

    0x40078000

    32

    0x40080000

    0

     

    The modified linker script file and the cyfxtx.c file are attached with this KBA for reference.