diff --git a/components/newlib/Kconfig b/components/newlib/Kconfig index 221ef36a94..9cbfd8ec4b 100644 --- a/components/newlib/Kconfig +++ b/components/newlib/Kconfig @@ -11,6 +11,10 @@ menu "LibC" depends on !IDF_TOOLCHAIN_CLANG && IDF_EXPERIMENTAL_FEATURES endchoice + config LIBC_MISC_IN_IRAM + bool "Place misc libc functions (abort/assert/stdatomics) in IRAM" if SPI_FLASH_AUTO_SUSPEND + default y + config LIBC_LOCKS_PLACE_IN_IRAM bool "Place lock API in IRAM" default y diff --git a/components/newlib/src/newlib.lf b/components/newlib/src/newlib.lf index 1e2782ac7d..7ca47a0b9b 100644 --- a/components/newlib/src/newlib.lf +++ b/components/newlib/src/newlib.lf @@ -1,10 +1,11 @@ [mapping:newlib] archive: libnewlib.a entries: - if HEAP_PLACE_FUNCTION_INTO_FLASH = n: - heap (noflash) - abort (noflash) - assert (noflash) - stdatomic (noflash) + if LIBC_MISC_IN_IRAM = y: + if HEAP_PLACE_FUNCTION_INTO_FLASH = n: + heap (noflash) + abort (noflash) + assert (noflash) + stdatomic (noflash) if STDATOMIC_S32C1I_SPIRAM_WORKAROUND = y: stdatomic_s32c1i (noflash) diff --git a/tools/test_apps/configs/sdkconfig.flash_auto_suspend_iram_reduction b/tools/test_apps/configs/sdkconfig.flash_auto_suspend_iram_reduction new file mode 100644 index 0000000000..756b665313 --- /dev/null +++ b/tools/test_apps/configs/sdkconfig.flash_auto_suspend_iram_reduction @@ -0,0 +1,15 @@ +# Options that will enable common IRAM usage reduction option. These options should be safe to use with most setups +CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y +CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y +CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH=y +CONFIG_LIBC_LOCKS_PLACE_IN_IRAM=n +CONFIG_HAL_ASSERTION_SILENT=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y + +# Options that will enable IRAM reduction option that are not necessarily safe for all use-cases +CONFIG_RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH=y + +# Options that will enable IRAM reduction option that are only usable together with flash auto-suspend +CONFIG_SPI_FLASH_AUTO_SUSPEND=y +CONFIG_LIBC_MISC_IN_IRAM=n diff --git a/tools/test_apps/system/.build-test-rules.yml b/tools/test_apps/system/.build-test-rules.yml index ea44516f09..a897171aa6 100644 --- a/tools/test_apps/system/.build-test-rules.yml +++ b/tools/test_apps/system/.build-test-rules.yml @@ -30,6 +30,15 @@ tools/test_apps/system/eh_frame: tools/test_apps/system/esp_intr_dump: +tools/test_apps/system/flash_auto_suspend_iram_reduction: + disable: + - if: IDF_TARGET == "esp32" or IDF_TARGET == "esp32s2 + reason: Targets do not support auto-suspend + disable_test: + - if: IDF_TARGET != "esp32c3" + temporary: true + reason: lack of runners + tools/test_apps/system/g0_components: enable: - if: INCLUDE_DEFAULT == 1 or IDF_TARGET in ["esp32c5", "esp32c61", "esp32h21", "esp32h4"] # preview targets diff --git a/tools/test_apps/system/flash_auto_suspend_iram_reduction/CMakeLists.txt b/tools/test_apps/system/flash_auto_suspend_iram_reduction/CMakeLists.txt new file mode 100644 index 0000000000..352f87dbb8 --- /dev/null +++ b/tools/test_apps/system/flash_auto_suspend_iram_reduction/CMakeLists.txt @@ -0,0 +1,9 @@ +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +list(PREPEND SDKCONFIG_DEFAULTS "$ENV{IDF_PATH}/tools/test_apps/configs/sdkconfig.flash_auto_suspend_iram_reduction") + +project(flash_auto_suspend_iram_reduction) diff --git a/tools/test_apps/system/flash_auto_suspend_iram_reduction/README.md b/tools/test_apps/system/flash_auto_suspend_iram_reduction/README.md new file mode 100644 index 0000000000..ffceaeb158 --- /dev/null +++ b/tools/test_apps/system/flash_auto_suspend_iram_reduction/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-P4 | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | diff --git a/tools/test_apps/system/flash_auto_suspend_iram_reduction/main/CMakeLists.txt b/tools/test_apps/system/flash_auto_suspend_iram_reduction/main/CMakeLists.txt new file mode 100644 index 0000000000..b028b00e6f --- /dev/null +++ b/tools/test_apps/system/flash_auto_suspend_iram_reduction/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "flash_auto_suspend_iram_reduction.c" + INCLUDE_DIRS ".") diff --git a/tools/test_apps/system/flash_auto_suspend_iram_reduction/main/flash_auto_suspend_iram_reduction.c b/tools/test_apps/system/flash_auto_suspend_iram_reduction/main/flash_auto_suspend_iram_reduction.c new file mode 100644 index 0000000000..49cdea3292 --- /dev/null +++ b/tools/test_apps/system/flash_auto_suspend_iram_reduction/main/flash_auto_suspend_iram_reduction.c @@ -0,0 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include + +void app_main(void) +{ + printf("Hello World!\n"); +} diff --git a/tools/test_apps/system/flash_auto_suspend_iram_reduction/pytest_flash_auto_suspend_iram_reduction.py b/tools/test_apps/system/flash_auto_suspend_iram_reduction/pytest_flash_auto_suspend_iram_reduction.py new file mode 100644 index 0000000000..232591f1cf --- /dev/null +++ b/tools/test_apps/system/flash_auto_suspend_iram_reduction/pytest_flash_auto_suspend_iram_reduction.py @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import pytest +from pytest_embedded import Dut +from pytest_embedded_idf.utils import idf_parametrize + + +@pytest.mark.flash_suspend +@idf_parametrize('config', ['defaults'], indirect=['config']) +@idf_parametrize('target', ['esp32c3'], indirect=['target']) +def test_flash_auto_suspend_minimize_iram_usage(dut: Dut) -> None: + dut.expect_exact('Hello World!', timeout=30) diff --git a/tools/test_apps/system/flash_auto_suspend_iram_reduction/sdkconfig.ci.defaults b/tools/test_apps/system/flash_auto_suspend_iram_reduction/sdkconfig.ci.defaults new file mode 100644 index 0000000000..90dbad8c42 --- /dev/null +++ b/tools/test_apps/system/flash_auto_suspend_iram_reduction/sdkconfig.ci.defaults @@ -0,0 +1,2 @@ +# Now the runners are massively using xmc-c chips, to be removed when xmc-d goes massive production. +CONFIG_SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND=y