Merge branch 'feature/newlib_in_flash' into 'master'

feat(newlib): added option for placing functions in flash if flash-auto-suspend

Closes IDF-11958

See merge request espressif/esp-idf!37767
This commit is contained in:
Marius Vikhammer
2025-03-18 14:55:14 +08:00
10 changed files with 72 additions and 5 deletions

View File

@@ -11,6 +11,10 @@ menu "LibC"
depends on !IDF_TOOLCHAIN_CLANG && IDF_EXPERIMENTAL_FEATURES depends on !IDF_TOOLCHAIN_CLANG && IDF_EXPERIMENTAL_FEATURES
endchoice 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 config LIBC_LOCKS_PLACE_IN_IRAM
bool "Place lock API in IRAM" bool "Place lock API in IRAM"
default y default y

View File

@@ -1,10 +1,11 @@
[mapping:newlib] [mapping:newlib]
archive: libnewlib.a archive: libnewlib.a
entries: entries:
if HEAP_PLACE_FUNCTION_INTO_FLASH = n: if LIBC_MISC_IN_IRAM = y:
heap (noflash) if HEAP_PLACE_FUNCTION_INTO_FLASH = n:
abort (noflash) heap (noflash)
assert (noflash) abort (noflash)
stdatomic (noflash) assert (noflash)
stdatomic (noflash)
if STDATOMIC_S32C1I_SPIRAM_WORKAROUND = y: if STDATOMIC_S32C1I_SPIRAM_WORKAROUND = y:
stdatomic_s32c1i (noflash) stdatomic_s32c1i (noflash)

View File

@@ -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

View File

@@ -30,6 +30,15 @@ tools/test_apps/system/eh_frame:
tools/test_apps/system/esp_intr_dump: 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: tools/test_apps/system/g0_components:
enable: enable:
- if: INCLUDE_DEFAULT == 1 or IDF_TARGET in ["esp32c5", "esp32c61", "esp32h21", "esp32h4"] # preview targets - if: INCLUDE_DEFAULT == 1 or IDF_TARGET in ["esp32c5", "esp32c61", "esp32h21", "esp32h4"] # preview targets

View File

@@ -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)

View File

@@ -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 |
| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- |

View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "flash_auto_suspend_iram_reduction.c"
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
void app_main(void)
{
printf("Hello World!\n");
}

View File

@@ -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)

View File

@@ -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