Memory

This chapter primarily introduces the memory system of the RTL8752H.

Memory Map

The memory system of the RTL8752H is designed based on the memory mapping architecture of the Arm Cortex-M0+ and primarily consists of ROM, RAM, Cache, Flash, and eFuse. Its design involves mapping the ARM address map to the memory regions defined by Realtek, as illustrated in Memory Mapping of RTL8752H.

../../../_images/Memory_Mapping.png

Memory Mapping of RTL8752H

The distribution of Realtek defined regions is shown in Memory Regions Defined by Realtek.

Memory Regions Defined by Realtek

Region

Address Space

Size

ROM

[0x00000000, 0x00057FFF]

352 KB

Data RAM

[0x00200000, 0x00219FFF]

104 KB

Cache

[0x0021A000, 0x0021BFFF]

8 KB

Buffer RAM

[0x00280000, 0x00283FFF]

16 KB

SPIC Flash (Cacheable)

[0x00800000, 0x017FFFFF]

Maximum mapping space is 16 MB.

SPIC Flash (Non-Cacheable)

[0x01800000, 0x027FFFFF]

Maximum mapping space is 16 MB.

eFuse

/

1 KB

Note

  • The RTL8752H’s Cache has dedicated RAM, and this RAM can also be configured for use as general-purpose RAM. For a detailed introduction, please refer to Cache.

  • The size of the Flash is determined by the part number of SoC used in practice.

ROM

The ROM address space of the RTL8752H is [0x00000000, 0x00057FFF], with a total size of 352KB.

The ROM is embedded with programs such as the Bootloader, BT Controller, Flash Driver, and Power Manager. Some of these modules (such as the Flash Driver) are exported to developers in the form of header files and ROM symbols. Using the interfaces in the ROM can reduce the code size of applications.

RAM

The RAM of RTL8752H is divided into two parts:

RTL8752H RAM

Region

Address Space

Size

Usage

Data RAM

[0x00200000, 0x00219FFF]

104KB

Used for storing data, executing code, and heap allocation.

Buffer RAM

[0x00280000, 0x00283FFF]

16KB

Primarily used for heap allocation, and the Realtek Bluetooth protocol stack uses this heap block by default.

Data RAM

The Data RAM of the RTL8752H is by default divided into 6 regions, distributed as follows:

../../../_images/DATA_RAM_LAYOUT.png

Data RAM Layout

Each region has a specific purpose:

Data RAM Usage

Region

Usage

Is Size Adjustable?

ROM Data

Stores global variables and static variables in ROM code.

No

Main Stack

Used for the startup process and interrupt service routines.

No

Patch RAM

Global variables and static variables for storing Patch code, as well as code executed in RAM.

No

BT Host RAM

Stores global variables and static variables of the BT Host code, as well as code executed in RAM.

Yes

APP RAM

Stores global variables and static variables of the APP, as well as code executed in RAM.

Yes

Data RAM Heap

Used for dynamically allocating memory for ROM code, Patch code, and APP code.

Yes

Three resizable RAM regions can be customized in size through the macros UPPERSTACK_GLOBAL_SIZE and APP_GLOBAL_SIZE in the mem_config.h file under the project directory.

Note

The macro UPPERSTACK_GLOBAL_SIZE must be set according to the version of the BT Host Image, so please pay attention to the BT Host version and release notes.

Buffer RAM

The address space of Buffer RAM is [0x00280000, 0x00283FFF], with a total size of 16KB, and its layout is as follows:

../../../_images/BUFFER_RAM_LAYOUT.png

Buffer RAM layout

Each region has a specific purpose:

Buffer RAM Usage

Region

Usage

Is Size Variable

ROM Data

Stores global variables and static variables from ROM code.

No

Buffer RAM Heap

Used for dynamic memory allocation for ROM code, Patch code, and APP code (Realtek Bluetooth protocol stack uses this heap by default).

No

Cache

The cache size of the RTL8752H is 8KB, corresponding to the address space [0x0021A000, 0x0021BFFF]. The cache, in conjunction with the SPI Flash Controller (SPIC), can accelerate the read and write access speeds of the Flash.

The cache of RTL8752H can be configured as Shared Cache RAM for storing data and executing code. Users can control the size of cache configured as RAM through the macro SHARE_CACHE_RAM_SIZE in the mem_config.h file under the project directory.

Configuration Methods for Share Cache RAM

Macro SHARE_CACHE_RAM_SIZE

Cache Size

Data RAM Size

Applicable Scenarios

0

8 KB

0 KB

Running a large amount of Flash code.

4

4 KB

4 KB

Run some Flash code, with requirements for the efficiency of Flash code execution.

8

0 KB

8 KB

Basically no need to run Flash code, or no efficiency requirements for running Flash code.

Note

The macro SHARE_CACHE_RAM_SIZE is set to 0 by default in SDK projects.

Heap Management

As introduced above, the RTL8752H is configured by default with two Heap areas (Data RAM Heap and Buffer RAM Heap) for developers to dynamically allocate memory.

The inc/os/os_mem.h provides the APIs for Heap Management:

APIs for Heap Management

API

Description

os_mem_alloc

Allocate memory.

os_mem_zalloc

Allocate memory and initialize it to 0.

os_mem_aligned_alloc

Allocate memory and align it according to the specified method.

os_mem_free()

Release the allocated memory.

os_mem_aligned_free()

Release memory allocated with specified alignment.

os_mem_peek()

Count the unused size of the specified RAM type Heap.

When calling APIs related to allocating, there will be different strategies based on the input parameter ram_type:

  • When ram_type is RAM_TYPE_DATA_ON, memory is allocated from the Data RAM Heap. If the Data RAM Heap is insufficient, it will automatically allocate from the Buffer RAM Heap.

  • When ram_type is RAM_TYPE_BUFFER_ON, memory is allocated from the Buffer RAM Heap. If the Buffer RAM Heap is insufficient, an out-of-space error will be reported.

RAM Usage of the Application

The RAM usage of the application primarily includes two parts:

  • The usage of static RAM after compilation

  • The usage of dynamically allocated memory from the Heap

This section will introduce the statistical methods, and the RAM usage in Bluetooth applications.

Static RAM Usage Statistics Method

After the APP is compiled, the usage of static RAM can be obtained by querying the MAP file generated during compilation.

The size of static RAM on Data RAM can be obtained by searching the RAM_DATA_ON keyword in the MAP file. Data RAM (Static) Usage Statistics is a screenshot of the RAM_DATA_ON area in the MAP file compiled by Keil, where you can see the execution region start address, load region start address, and actual used size of the RAM_DATA_ON area.

../../../_images/APP_DATA_RAM_USAGE.png

Data RAM (Static) Usage Statistics

If the APP is configured with Share Cache RAM, the size of static RAM on Share Cache RAM can be obtained by retrieving the CACHE_DATA_ON keyword in the MAP file. Share Cache RAM Usage Statistics is a screenshot of the MAP file compiled by Keil, where you can see the execution region start address, load region start address, and actual used size of the CACHE_DATA_ON area.

../../../_images/SHARE_CACHE_RAM_USAGE.png

Share Cache RAM Usage Statistics

Heap Usage Statistics Method

By calling os_mem_peek(), you can obtain the allocatable size of the specified RAM type Heap.

RAM Usage Statistics

For a Bluetooth application, the Realtek platform and Bluetooth protocol stack code will occupy a portion of the RAM resources during runtime. Therefore, this section will count the amount of RAM used by Realtek in the Bluetooth application and calculate the actual available RAM size left for APP developers.

According to the default Bluetooth settings in MP Tool under Config Set -‣ Stack:

  • LE Master Link Num: 2

  • LE Slave Link Num: 2

  • Support LE AE ADV: Enable

  • PSD Enable: Enable

The statistical results of RAM usage are as follows:

RAM Usage Statistics of Bluetooth Applications (Default Settings)

Region

Total Size

Usage by Realtek

RAM Size Available for APP

Data RAM Heap + APP RAM

68 KB

28 KB

40 KB

Buffer RAM Heap

14.5 KB

13 KB

1.5 KB

Note

  • Usage by Realtek mainly accounts for the Heap usage in Bluetooth applications, excluding static RAM usage.

  • The above statistics allocate 2KB by default to BT Host RAM, making the total size of Data RAM Heap + APP RAM 68KB.

  • Patch updates may cause changes in Realtek usage, so the available RAM size for the APP should be based on the actual situation.

RAM Usage Optimization

If you want to further increase the amount of RAM available for the app, the following two methods can be considered.

Method 1: Change Bluetooth Settings

By modifying Bluetooth settings in the MP Tool under the Config Set -‣ Stack interface, such as the number of Bluetooth links, AE and PSD functions, etc., the purpose of increasing the RAM available for the app can be achieved.

../../../_images/MPTool_Stack_Config_Setting.png

Modify Bluetooth settings through MP Tool

If the default Bluetooth settings are changed as follows:

  • LE Master Link Num: 2->0

  • LE Slave Link Num: 2->0

  • Support LE AE ADV: Enable->Disable

  • PSD Enable: Enable->Disable

The RAM usage statistics will be changed to:

RAM Usage Statistics of Bluetooth Applications (After Changing Bluetooth Settings)

Region

Total Size

Usage by Realtek

RAM Size Available for APP

Data RAM Heap + APP RAM

68 KB

22 KB

46 KB

Buffer RAM Heap

14.5 KB

10.7 KB

3.8 KB

Method 2: Turn Off the LOG System

By unchecking the LOG Config option in the Config Set -‣ Log interface of MP Tool, an additional 1.5KB of RAM can be freed for APP use.

Flash

See Flash.

eFuse

  • eFuse is a one-time programmable memory used to store important and fixed information, such as UUIDs, keys, and other information that will only be configured once.

  • Each bit in eFuse can only be changed from 1 to 0 and cannot be changed from 0 to 1, so extreme caution must be exercised when updating eFuse.

  • 2.5V (±10%) power supply must be applied when programming eFuse.

  • Realtek provides MP Tool to update eFuse.