Memory

This document describes memory system of RTL87x2G and introduces how to use them. RTL87x2G memory consists of ROM, RAM, Flash and eFuse, as is shown in Memory Layout. This flexible memory configuration mechanism allows RTL87x2G to support a wide range of application programs.

Memory Layout

Memory Type

Region

Start Addr

End Addr

Size(bytes)

ROM

0x00000000

0x0007FFFF

512K

RAM

ITCM1

0x00100000

0x0012FFFF

192K

DTCM0

0x00130000

0x0013FFFF

64K

DTCM1

0x00140000

0x0014FFFF

64K

Data SRAM

0x00200000

0x00203FFF

16K

Buffer SRAM

0x00280000

0x0028BFFF

48K

Cache

I-Cache

--

--

32K

D-Cache

--

--

16K

Flash

SPI Flash

0x04000000

0x07FFFFFF

64M*

eFuse

eFuse

--

--

1K

备注

* means the maximum mapping space is 64 MB, but the actual size depends on the used Flash memory size.

ROM

The ROM code is located at [0x0, 0x7FFFF), with a total size of 512KB, in which Bootloader, RTOS, BT Stack, Flash Driver and other platform modules are built in. RTL87x2G ROM opens some modules such as RTOS, BT Stack for application to use. RTL87x2G SDK contains the header files of these ROM modules which enables users to access built in ROM functions. This reduces the application code size and RAM size.

RAM

Memory Space Layout

The RAM Space of RTL87x2G is divided into 5 parts. Five parts of RAM space can be used to store data and execute code.

RAM Space

Region

Starting Address

Address Range

Total Size

ITCM1

0x00100000

0x00100000~0x0012FFFF

192KB

DTCM0

0x00130000

0x00130000~0x0013FFFF

64KB

DTCM1

0x00140000

0x00140000~0x0014FFFF

64KB

Data SRAM

0x00200000

0x00200000~0x00203FFF

16KB

Buffer SRAM

0x00280000

0x00280000~0x0028BFFF

48KB

RAM is divided into three blocks, namely TCM, Data RAM and Buffer RAM. Namely TCM with an address space of 0x00100000 ~ 0x0012FFFF with a total size of 192KB, DTCM0 with an address space of 0x00130000 ~ 0x0013FFFF with a total size of 64KB, and DTCM1 with an address space of 0x00140000 ~ 0x0014FFFF with a total size of 64KB. The three space addresses are consecutive. The memory space layout will be different for TrustZone enable and TrustZone disable, as follows.

  • TCM: A specially designed type of memory that focuses on providing low latency, high bandwidth, and deterministic access characteristics.

  • ITCM: A type of TCM specifically used for storing program instructions, allowing the CPU to quickly access and execute the code.

  • DTCM: A type of TCM specifically designed for storing data, enhancing the access speed to this data.

TrustZone Disable Memory Space Layout

../../../../_images/TrustZone_disable_RAM_layout.png

TrustZone disable RAM Layout

备注

When TrustZone is disabled, there is no distinction between secure and non-secure.

Each part has a fixed arrangement sequence and a specific purpose, as shown in TrustZone disable RAM Usage.

TrustZone disable RAM Usage

Memory Type

Memory Usage

Memory Variable

S ROM data

Store global variables and static variables in Secure ROM Code

No

Main Stack

Used in startup and interrupt service routines

No

Boot Patch RAM

Store Boot Patch global variables and static variables and code executed on RAM

No

System Patch RAM

Store System Patch global variables and static variables and code executed on RAM

No

Stack Patch RAM

Store Stack Patch global variables and static variables and code executed on RAM

No

NS ROM data

Store global variables and static variables in Non-Secure ROM Code

No

DTCM + ITCM Heap

For the dynamic application space of Non-Secure ROM code, Non-Secure Patch code, Non-Secure Upperstack code and APP code

Yes

APP RAM

Store global variables and static variables in APP and code executed on RAM

Yes

BT Host stack RAM

Store global variables and static variables in BT Host stack and code executed on RAM

Yes

TrustZone Enable Memory Space Layout

../../../../_images/TrustZone_enable_RAM_layout.png

TrustZone enable RAM Layout

TrustZone enable RAM Usage

Memory Type

Memory Usage

Memory Variable

S ROM data

Store global variables and static variables in Secure ROM Code

No

Secure Main Stack

The stack is used in secure startup and interrupt service routines

No

Boot Patch RAM

Store Boot Patch global variables and static variables and code executed on RAM

No

System Patch RAM

Store System Patch global variables and static variables and code executed on RAM

No

Stack Patch RAM

Store Stack Patch global variables and static variables and code executed on RAM

No

NS ROM data

Store global variables and static variables in Non-Secure ROM Code

No

NS Main Stack

The stack is used in non-secure startup and interrupt service routines

No

Secure Heap

For the dynamic application space of Secure ROM code and SecureAPP code

Yes

Secure APP RAM

Store Secure APP global variables and static variables and code executed on RAM

Yes

NS DTCM + ITCM Heap

For the dynamic application space of Non-Secure ROM code, Non-Secure Patch code, Non-Secure BT Host stack code and APP code

Yes

NS APP RAM

Store global variables and static variables in NS APP and code executed on RAM

Yes

BT Host stack RAM

Store global variables and static variables in BT Host stack and code executed on RAM

Yes

The Adjust RAM are uniformly modified through different macro definitions in mem_config.h. NS_RAM_UPPERSTACK_SIZE must be set accordingly according to the version of the BT Host image used. Different BT Host images occupy different sizes of DTCM. Please pay attention to the BT Host release document and its description. Adjust the size of NS_RAM_UPPERSTACK_SIZE according to application needs.

Adjust RAM

Memory Type

Macro

Upperstack RAM

NS_RAM_UPPERSTACK_SIZE

APP RAM

NS_RAM_APP_SIZE

DTCM + ITCM Heap

NS_RAM_APP_RESERVED_SIZE - NS_RAM_APP_SIZE - NS_RAM_UPPERSTACK_SIZE

APIs

By calling the API: os_mem_alloc, you can dynamically apply for memory from DTCM Heap or Buffer SRAM Heap. The type of application is specified by the parameter ram_type, which corresponds to RAM_TYPE_DATA_ ON and RAM_TYPE_BUFFER_ON. The specific codes are as follows.

typedef enum
{
    RAM_TYPE_DATA_ON,        //DTCM Heap
    RAM_TYPE_DATA_OFF = RAM_TYPE_DATA_ON,
    RAM_TYPE_BUFFER_ON,
    RAM_TYPE_BUFFER_OFF = RAM_TYPE_BUFFER_ON,
    RAM_TYPE_EXT_DATA_SRAM,  //Ext DATA SRAM heap
    RAM_TYPE_NUM
} RAM_TYPE;

/**
* @brief  Allocate memory dynamically from Data RAM Heap or Buffer RAM heap
* @param  ram_type : specify which heap to allocate memory from
* @param  size: memory size in bytes to be allocated
* @retval pointer to the allocated memory
*/
#define os_mem_alloc(ram_type, size)
        os_mem_alloc_intern(ram_type, size, __func__, __LINE__)

Other APIs for dynamically applying for memory are as follows: (For details, refer to os_mem.h)

os_mem_zalloc:

allocated memory will be initialized to 0.

os_mem_aligned_alloc:

allocated memory will be aligned to the specified alignment.

os_mem_free:

free a memory block that had been allocated from data ram heap or buffer ram heap.

os_mem_aligned_free:

free an aligned memory block that had been allocated.

s_mem_peek:

get the unused memory size of the specified RAM type.

Access Efficiency

Subsequent version updates.

Memory Usage Calculation

According to the way the app uses ram, it is divided into static area and dynamic area.

Statistics of Static Zone Size on Data RAM

Find the app.map file generated by Build to find the first address allocated in Data RAM, the end address and the used size. By searching the map of the loading area ER_IRAM_NS Map, you can determine the static usage of APP DTCM.

../../../../_images/ER_IRAM_NS_Map.png

ER_IRAM_NS Map

Statistics of Remaining Heap Size

The remaining heap size of the specified RAM type can be obtained through the os_mem_peek function.

Adjust the total size of RAM that the APP can use

Subsequent version updates.

Cache

RTL87x2G supports 32KB I-Cache and 16KB D-Cache.

Cache default policy:

  • Flash are Cacheable by default.

  • Data ram and Buffer ram are Non-Cacheable by default.

Flash

Refer to Flash.

PSRAM

Refer to PSRAM.

eFuse

eFuse is a block of one-time programming memory which is used to store the important and fixed information, such as UUID, security key and other one-time programming configuration. The single bit of eFuse cannot be changed from 0 to 1, and there is no erase operation to eFuse, so be careful to update eFuse. Realtek offers MPTool to update certain eFuse sections.