IC:

RAM Layout Configuration Guide

Introduction

This chapter describes the default memory layout and provides guidance for customization.

RAM Memory Layout

Chipset integrates internal SRAM and expandable PSRAM with the following capacities:

  • Internal SRAM: 512KB

  • Expandable PSRAM: Available in various models with capacities including 0MB, 4MB, 8MB, and 16MB.

../../_images/ram_layout_dplus.svg

SRAM0 Layout (First 40KB)

The first 40KB of SRAM is reserved for storing ROM variables, BOOT code, and security processing functions, and this portion of memory is not accessible to users.

../../_images/sram0_layout_dplus.svg

Items

Start address

Size

Description

Mandatory

KM0_ROM_BSS_RAM

0x2000_0000

4KB

KM0 ROM BSS

KM0_MSP_RAM

0x2000_1000

4KB

KM0 Main Stack Pointer

KM0_STDLIB_HEAP_NS

0x2000_2000

4KB

KM0 ROM STDLIB heap

KM4_MSP_NS

0x2000_3000

4KB

KM4 non-secure Main Stack Pointer

KM4_ROM_BSS_COMMON

0x2000_4000

3.25KB

KM4 ROM secure and non-secure common BSS

KM0_BOOT_RAM

0x2000_4D00

64B

KM0 IMG2 entry

KM0_IPC_RAM

0x2000_4E00

512B

Exchange messages between cores

KM4_ROM_BSS_NS

0x2000_5000

4KB

KM4 ROM non-secure common BSS

KM4_STDLIB_HEAP_NS

0x2000_6000

4KB

KM4 ROM non-secure STDLIB heap

KM4_ROM_BSS_S

0x3000_7000

4KB

KM4 ROM secure-only BSS

KM0_RTOS_STATIC_0_NS

0x2000_8000

4KB

KM0 RTOS static pool position

KM4_MSP_S

0x3000_9000

4KB

KM4 secure Main Stack Pointer

RAM & PSRAM Hybrid Layout

RAM layout With PSRAM

../../_images/ram_layout_with_psram2_dplus.svg

RAM layout (with PSRAM)

Item

Start address

Size (KB)

Description

Mandatory

SRAM0

0x2000_0000

40

For ROM BSS, MSP, …

KM4 Bootloader

0x3000_A000

24

KM4 secure bootloader, including code and data

KM4 BD RAM

0x2001_0000

352

KM4 BDRAM data, BSS and heap

KM0 BD RAM

0x2004_0000

96

KM0 BDRAM data, BSS and heap

KM4 PSRAM

0x6000_0000

3220

KM4 PSRAM code, can be empty

KM0 PSRAM

0x6032_5000

876

KM0 PSRAM code, can be empty

KM4 HEAP EXT

0x6FFF_FFFF

0

If KM4 heap is not enough, it can be used to extend the heap size

x

KM0 HEAP EXT

0x6FFF_FFFF

0

If KM0 heap is not enough, it can be used to extend the heap size

x

Bootloader Size Configuration

Bootloader Size Adjustment

When enlarging KM4_BOOT_RAM_S, ensure modified size is 4KB-aligned (MPC protection works in 4KB units).

Steps to modify bootloader size:

  1. Configure CONFIG Link Option in menuconfig:

    • SRAM selection sets KM4_BOOTLOADER_RAM_S to 24KB

    • Flash selection sets KM4_BOOTLOADER_RAM_S to 4KB

    ../../_images/modify_bootloader_size_step1_dplus.png
  2. Modify linker script parameter (path: {SDK}\amebaxxx_gcc_project\amebaxxx_layout.ld):

    • Adjust KM4_IMG1_SIZE to change KM4_BOOTLOADER_RAM_S size

  3. Rebuild project to generate new bootloader

  4. If bootloader exceeds size limit:

    • Update end address in km4_boot_all.bin

    • Flash updated bootloader

    ../../_images/modify_bootloader_size_step4_dplus.png

Note

New bootloader version must be higher than current version for boot ROM loading

BD_RAM/BD_PSRAM Capacity Adjustment

BD_RAM Configuration

Steps to modify KM4 BD_RAM size:

  1. Adjust KM4_BD_RAM end address by modifying RAM_KM0_IMG2_SIZE in:

    {SDK}\amebadplus_gcc_project\amebaDplus_layout.ld

    ../../_images/modify_sd_ram_step1_dplus.png
  2. Rebuild and flash Bootloader with IMG2 OTA2 following APP OTA1 section

BD_PSRAM Configuration

To modify KM4 BD_PSRAM size:

  1. First configure IMG2 execution position in menuconfig (select any PSRAM-related option)

  2. Adjust KM4_BD_PSRAM end address by modifying PSRAM_KM4_IMG2_SIZE in:

    {SDK}\amebadplus_gcc_project\amebaDplus_layout.ld

    ../../_images/modify_sd_ram_step2_dplus.png

Heap Memory Configuration

System heap consists of multiple blocks initialized by os_heap_init() in component\os\freertos\freertos_heap5_config.c.

Initial PSRAM Heap Definition

  • PSRAM_HEAP1_START is invalid address

  • PSRAM_HEAP1_SIZE set to 0

Initial Heap Definition
KM4_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF  /* KM4 PSRAM Extended Heap */
KM0_PSRAM_HEAP_EXT (rwx) : ORIGIN = 0x6FFFFFFF, LENGTH = 0x6FFFFFFF - 0x6FFFFFFF  /* KM0 PSRAM Extended Heap */

KM4 Heap Extension

For insufficient KM4 heap:

  1. Define unused PSRAM regions in linker script amebaDplus_layout.ld:

    • Set valid Heap Start address

    • Configure Heap Size value

  2. Add heap blocks via system API:

    bool os_heap_add(u8 *start_addr, size_t heap_size);
    
  3. Rebuild and flash image to activate configuration

Note

Symbols defined in linker script (amebaDplus_layout.ld) must be declared in ameba_boot.h before usage

KM0 Heap Extension

For insufficient KM0 heap, modify KM0_PSRAM_HEAP_EXT parameter