Skip to content

Commit

Permalink
Merge branch 'support_psram_noinit_segment_on_s3_v5.1' into 'release/…
Browse files Browse the repository at this point in the history
…v5.1'

feat(psram): add psram noinit  segment support on s2/s3/p4/c5 and bss segment on c5 (v5.1)

See merge request espressif/esp-idf!33258
  • Loading branch information
suda-morris committed Sep 5, 2024
2 parents d80d9a4 + bec23c9 commit cc56879
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 25 deletions.
1 change: 1 addition & 0 deletions components/esp_common/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
components/esp_common/test_apps/esp_common:
disable:
- if: CONFIG_NAME == "psram" and SOC_SPIRAM_SUPPORTED != 1
- if: CONFIG_NAME == "psram_noinit" and SOC_SPIRAM_SUPPORTED != 1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
idf_component_register(SRCS "test_app_main.c" "test_attr.c"
INCLUDE_DIRS "."
PRIV_REQUIRES unity esp_psram
PRIV_REQUIRES unity esp_mm esp_psram
WHOLE_ARCHIVE)
16 changes: 15 additions & 1 deletion components/esp_common/test_apps/esp_common/main/test_attr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -10,10 +10,17 @@
#include "esp_log.h"
#include "soc/soc.h"
#include "esp_system.h"
#include "hal/cache_ll.h"
#include "hal/cache_hal.h"
#include "esp_cache.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp_private/esp_psram_extram.h"
#endif

#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))

static const char *TAG = "attr_test";

extern int _rtc_noinit_start;
extern int _rtc_noinit_end;
extern int _rtc_data_start;
Expand Down Expand Up @@ -45,6 +52,7 @@ static EXT_RAM_NOINIT_ATTR uint32_t s_noinit_ext;

static bool data_in_segment(void *ptr, int *seg_start, int *seg_end)
{
ESP_LOGV(TAG, "ptr:%p seg_start:%p seg_end:%p", ptr, seg_start, seg_end);
return ((intptr_t)ptr < (intptr_t)seg_end) && \
((intptr_t)ptr >= (intptr_t)seg_start);
}
Expand Down Expand Up @@ -95,7 +103,13 @@ static void write_spiram_and_reset(void)
}
printf("Flushing cache\n");
// Flush the cache out to SPIRAM before resetting.
#if CONFIG_IDF_TARGET_ESP32
esp_psram_extram_writeback_cache();
#else
size_t psram_alignment = cache_hal_get_cache_line_size(CACHE_TYPE_DATA);
uint32_t ext_noinit_size = sizeof(s_noinit_buffer);
TEST_ESP_OK(esp_cache_msync(&s_noinit_buffer, ALIGN_UP(ext_noinit_size, psram_alignment), 0));
#endif

printf("Restarting\n");
// Reset to test that noinit memory is left intact.
Expand Down
12 changes: 8 additions & 4 deletions components/esp_common/test_apps/esp_common/pytest_esp_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
from typing import Any

import pytest
from pytest_embedded import Dut
Expand All @@ -20,6 +21,8 @@ def test_esp_common(dut: Dut) -> None:

# psram noinit attr tests with psram enabled
@pytest.mark.esp32
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
@pytest.mark.parametrize(
'config',
Expand All @@ -34,17 +37,18 @@ def test_esp_attr_psram_noinit(dut: Dut) -> None:

# psram noinit memory tests with psram enabled
@pytest.mark.esp32
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
@pytest.mark.supported_targets
@pytest.mark.parametrize(
'config',
[
'psram_noinit'
],
indirect=True,
)
def run_multiple_stages(dut: Dut, test_case_num: int, stages: int) -> None:
dut.run_all_single_board_cases()
def test_esp_attr_psram_noinit_multiple_stages(case_tester: Any) -> None:
case_tester.run_all_multi_stage_cases()


# psram attr tests with psram enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# For EXT_RAM_NOINIT_ATTR

CONFIG_IDF_TARGET="esp32"
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
CONFIG_IDF_TARGET="esp32s2"
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_RODATA=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
CONFIG_IDF_TARGET="esp32s3"
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_RODATA=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
2 changes: 1 addition & 1 deletion components/esp_psram/Kconfig.spiram.common
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ config SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
config SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY
bool "Allow .noinit segment placed in external memory"
default n
depends on SPIRAM && IDF_TARGET_ESP32
depends on SPIRAM
help
If enabled, noinit variables can be placed in PSRAM using EXT_RAM_NOINIT_ATTR.

Expand Down
3 changes: 1 addition & 2 deletions components/esp_system/ld/esp32s2/memory.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ _data_seg_org = ORIGIN(rtc_data_seg);

/* The lines below define location alias for .rtc.data section based on Kconfig option.
When the option is not defined then use slow memory segment
else the data will be placed in fast memory segment
TODO: check whether the rtc_data_location is correct for esp32s2 - IDF-761 */
else the data will be placed in fast memory segment */
#ifndef CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM
REGION_ALIAS("rtc_data_location", rtc_slow_seg );
#else
Expand Down
16 changes: 15 additions & 1 deletion components/esp_system/ld/esp32s2/sections.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ SECTIONS
_noinit_end = ABSOLUTE(.);
} > dram0_0_seg

/* external memory bss, from any global variable with EXT_RAM_BSS_ATTR attribute*/
/* External Memory BSS. (Variables with EXT_RAM_BSS_ATTR attribute). */
.ext_ram.bss (NOLOAD) :
{
_ext_ram_bss_start = ABSOLUTE(.);
Expand All @@ -258,6 +258,20 @@ SECTIONS
_ext_ram_bss_end = ABSOLUTE(.);
} > extern_ram_seg

/**
* This section holds data that won't be initialised when startup.
* This section locates in External RAM region.
*/
.ext_ram_noinit (NOLOAD) :
{
_ext_ram_noinit_start = ABSOLUTE(.);

*(.ext_ram_noinit*)

. = ALIGN(4);
_ext_ram_noinit_end = ABSOLUTE(.);
} > extern_ram_seg

/* Shared RAM */
.dram0.bss (NOLOAD) :
{
Expand Down
14 changes: 14 additions & 0 deletions components/esp_system/ld/esp32s3/sections.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ SECTIONS
_ext_ram_bss_end = ABSOLUTE(.);
} > extern_ram_seg

/**
* This section holds data that won't be initialised when startup.
* This section locates in External RAM region.
*/
.ext_ram_noinit (NOLOAD) :
{
_ext_ram_noinit_start = ABSOLUTE(.);

*(.ext_ram_noinit*)

. = ALIGN(4);
_ext_ram_noinit_end = ABSOLUTE(.);
} > extern_ram_seg

/* Marks the end of IRAM code segment */
.iram0.text_end (NOLOAD) :
{
Expand Down
12 changes: 5 additions & 7 deletions docs/en/api-guides/external-ram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ This option reduces the internal static memory used by the BSS segment.

Remaining external RAM can also be added to the capability heap allocator using the method shown above.

.. only:: esp32

.. _external_ram_config_noinit:
.. _external_ram_config_noinit:

Allow .noinit Segment to Be Placed in External Memory
--------------------------------------------------------------
Allow .noinit Segment to Be Placed in External Memory
--------------------------------------------------------------

Enable this option by checking :ref:`CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY`. If enabled, a region of the address space provided in external RAM will be used to store non-initialized data. The values placed in this segment will not be initialized or modified even during startup or restart.
Enable this option by checking :ref:`CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY`. If enabled, the region of the data virtual address space where the PSRAM is mapped to will be used to store non-initialized data. The values placed in this segment will not be initialized or modified even during startup or restart.

By applying the macro ``EXT_RAM_NOINIT_ATTR``, data could be moved from the internal NOINIT segment to external RAM. Remaining external RAM can still be added to the capability heap allocator using the method shown above, :ref:`external_ram_config_capability_allocator`.
By applying the macro ``EXT_RAM_NOINIT_ATTR``, data could be moved from the internal NOINIT segment to external RAM. Remaining external RAM can still be added to the capability heap allocator using the method shown above, :ref:`external_ram_config_capability_allocator`.

.. only:: SOC_SPIRAM_XIP_SUPPORTED

Expand Down
12 changes: 5 additions & 7 deletions docs/zh_CN/api-guides/external-ram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,14 @@ ESP-IDF 启动过程中,片外 RAM 被映射到以 {IDF_TARGET_PSRAM_ADDR_STAR

剩余的片外 RAM 也可以通过上述方法添加到堆分配器中。

.. only:: esp32

.. _external_ram_config_noinit:
.. _external_ram_config_noinit:

允许 .noinit 段放入片外存储器
-------------------------------------
允许 .noinit 段放入片外存储器
-------------------------------------

通过勾选 :ref:`CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY` 启用该选项。启用该选项后,外部 RAM 中提供的地址空间区域将用于存储未初始化的数据。即使在启动或重新启动期间,放置在该段中的值也不会被初始化或修改。
通过勾选 :ref:`CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY` 启用该选项。启用该选项后,PSRAM 被映射到的数据虚拟地址空间将用于存储未初始化的数据。即使在启动或重新启动期间,放置在该段中的值也不会被初始化或修改。

通过应用 ``EXT_RAM_NOINIT_ATTR`` 宏,可以将数据从内部 NOINIT 段移到片外 RAM。剩余的片外 RAM 也可以通过上述方法添加到堆分配器中,具体请参考 :ref:`external_ram_config_capability_allocator`。
通过应用 ``EXT_RAM_NOINIT_ATTR`` 宏,可以将数据从内部 NOINIT 段移到片外 RAM。剩余的片外 RAM 也可以通过上述方法添加到堆分配器中,具体请参考 :ref:`external_ram_config_capability_allocator`。

.. only:: SOC_SPIRAM_XIP_SUPPORTED

Expand Down

0 comments on commit cc56879

Please sign in to comment.