Skip to content

Commit

Permalink
Merge branch 'refactor/move_freertos_related_kconfig_and_test_to_free…
Browse files Browse the repository at this point in the history
…rtos' into 'master'

refactor(freertos): rename SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY

See merge request espressif/esp-idf!32884
  • Loading branch information
suda-morris committed Oct 10, 2024
2 parents 6846245 + aebf700 commit 1b79771
Show file tree
Hide file tree
Showing 52 changed files with 158 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ CONFIG_SPIRAM=y
CONFIG_SPIRAM_XIP_FROM_PSRAM=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ 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
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ 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
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
2 changes: 1 addition & 1 deletion components/esp_hw_support/esp_memory_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool esp_ptr_external_ram(const void *p)
#endif //CONFIG_SPIRAM
}

#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#if CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
bool esp_stack_ptr_in_extram(uint32_t sp)
{
//Check if stack ptr is on PSRAM, and 16 byte aligned.
Expand Down
4 changes: 2 additions & 2 deletions components/esp_hw_support/include/esp_memory_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ inline static bool esp_stack_ptr_in_dram(uint32_t sp)
return !(sp < SOC_DRAM_LOW + 0x10 || sp > SOC_DRAM_HIGH - 0x10 || ((sp & 0xF) != 0));
}

#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#if CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
/**
* @brief Check if the stack pointer is in external ram
*
Expand All @@ -374,7 +374,7 @@ __attribute__((always_inline))
inline static bool esp_stack_ptr_is_sane(uint32_t sp)
{
return esp_stack_ptr_in_dram(sp)
#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#if CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
|| esp_stack_ptr_in_extram(sp)
#endif
#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CONFIG_IDF_TARGET="esp32s2"
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y
CONFIG_SPIRAM_RODATA=y
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CONFIG_IDF_TARGET="esp32s3"
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y
CONFIG_SPIRAM_RODATA=y
13 changes: 0 additions & 13 deletions components/esp_psram/esp32/Kconfig.spiram
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,6 @@ menu "SPI RAM config"
any himem calls, the reservation is not done and the original amount of memory will be available
to malloc/esp_heap_alloc_caps.

config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
bool "Allow external memory as an argument to xTaskCreateStatic"
default n
depends on SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC
help
Because some bits of the ESP32 code environment cannot be recompiled with the cache workaround,
normally tasks cannot be safely run with their stack residing in external memory; for this reason
xTaskCreate (and related task creaton functions) always allocate stack in internal memory and
xTaskCreateStatic will check if the memory passed to it is in internal memory. If you have a task that
needs a large amount of stack and does not call on ROM code in any way (no direct calls, but also no
Bluetooth/WiFi), you can try enable this to cause xTaskCreateStatic to allow tasks stack in external
memory.

choice SPIRAM_OCCUPY_SPI_HOST
prompt "SPI host to use for 32MBit PSRAM"
default SPIRAM_OCCUPY_VSPI_HOST
Expand Down
10 changes: 0 additions & 10 deletions components/esp_psram/esp32c5/Kconfig.spiram
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ menu "SPI RAM config"

endchoice

config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
bool "Allow external memory as an argument to xTaskCreateStatic"
default y
help
Accessing memory in SPIRAM has certain restrictions, so task stacks allocated by xTaskCreate
are by default allocated from internal RAM.

This option allows for passing memory allocated from SPIRAM to be passed to xTaskCreateStatic.
This should only be used for tasks where the stack is never accessed while the cache is disabled.

choice SPIRAM_SPEED
prompt "Set RAM clock speed"
default SPIRAM_SPEED_40M
Expand Down
10 changes: 0 additions & 10 deletions components/esp_psram/esp32c61/Kconfig.spiram
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ menu "SPI RAM config"

endchoice

config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
bool "Allow external memory as an argument to xTaskCreateStatic"
default y
help
Accessing memory in SPIRAM has certain restrictions, so task stacks allocated by xTaskCreate
are by default allocated from internal RAM.

This option allows for passing memory allocated from SPIRAM to be passed to xTaskCreateStatic.
This should only be used for tasks where the stack is never accessed while the cache is disabled.

choice SPIRAM_SPEED
prompt "Set RAM clock speed"
default SPIRAM_SPEED_40M
Expand Down
11 changes: 0 additions & 11 deletions components/esp_psram/esp32p4/Kconfig.spiram
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ menu "PSRAM config"

If enabled, 1/8 of the PSRAM total size will be reserved for error-correcting code.

config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
bool "Allow external memory as an argument to xTaskCreateStatic"
default y
help
Accessing memory in PSRAM has certain restrictions, so task stacks allocated by xTaskCreate
are by default allocated from internal RAM.

This option allows for passing memory allocated from PSRAM to be passed to xTaskCreateStatic.
This should only be used for tasks where the stack is never accessed while the L2Cache is
disabled, e.g. during SPI Flash operations

source "$IDF_PATH/components/esp_psram/Kconfig.spiram.common" # insert non-chip-specific items here

endmenu
10 changes: 0 additions & 10 deletions components/esp_psram/esp32s2/Kconfig.spiram
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ menu "SPI RAM config"
bool "ESP-PSRAM64 or LY68L6400"
endchoice

config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
bool "Allow external memory as an argument to xTaskCreateStatic"
default y
help
Accessing memory in SPIRAM has certain restrictions, so task stacks allocated by xTaskCreate
are by default allocated from internal RAM.

This option allows for passing memory allocated from SPIRAM to be passed to xTaskCreateStatic.
This should only be used for tasks where the stack is never accessed while the cache is disabled.

config SPIRAM_CLK_IO
int
default 30
Expand Down
10 changes: 0 additions & 10 deletions components/esp_psram/esp32s3/Kconfig.spiram
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ menu "SPI RAM config"
bool "ESP-PSRAM64 , LY68L6400 or APS6408"
endchoice

config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
bool "Allow external memory as an argument to xTaskCreateStatic"
default y
help
Accessing memory in SPIRAM has certain restrictions, so task stacks allocated by xTaskCreate
are by default allocated from internal RAM.

This option allows for passing memory allocated from SPIRAM to be passed to xTaskCreateStatic.
This should only be used for tasks where the stack is never accessed while the cache is disabled.

config SPIRAM_CLK_IO
int
default 30
Expand Down
8 changes: 0 additions & 8 deletions components/esp_psram/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ components/esp_psram/test_apps/psram:
- esp_driver_gpio
- esp_driver_spi
- spi_flash


components/esp_psram/test_apps/psram_no_malloc_task_stack:
enable:
- if: IDF_TARGET in ["esp32", "esp32p4"]
depends_components:
- esp_psram
- freertos

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions components/esp_system/port/soc/esp32/system_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ void IRAM_ATTR esp_restart_noos(void)
wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context);

#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
if (esp_ptr_external_ram(esp_cpu_get_sp())) {
// If stack_addr is from External Memory (CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY is used)
// If stack_addr is from External Memory (CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM is used)
// then need to switch SP to Internal Memory otherwise
// we will get the "Cache disabled but cached memory region accessed" error after Cache_Read_Disable.
uint32_t new_sp = SOC_DRAM_LOW + (SOC_DRAM_HIGH - SOC_DRAM_LOW) / 2;
Expand Down
4 changes: 2 additions & 2 deletions components/esp_system/port/soc/esp32s2/system_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ void IRAM_ATTR esp_restart_noos(void)
wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context);

#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
if (esp_ptr_external_ram(esp_cpu_get_sp())) {
// If stack_addr is from External Memory (CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY is used)
// If stack_addr is from External Memory (CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM is used)
// then need to switch SP to Internal Memory otherwise
// we will get the "Cache disabled but cached memory region accessed" error after Cache_Read_Disable.
uint32_t new_sp = ALIGN_DOWN(_bss_end, 16);
Expand Down
4 changes: 2 additions & 2 deletions components/esp_system/port/soc/esp32s3/system_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ void IRAM_ATTR esp_restart_noos(void)
wdt_hal_disable(&wdt1_context);
wdt_hal_write_protect_enable(&wdt1_context);

#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
if (esp_ptr_external_ram(esp_cpu_get_sp())) {
// If stack_addr is from External Memory (CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY is used)
// If stack_addr is from External Memory (CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM is used)
// then need to switch SP to Internal Memory otherwise
// we will get the "Cache disabled but cached memory region accessed" error after Cache_Read_Disable.
uint32_t new_sp = ALIGN_DOWN(_bss_end, 16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ TEST_CASE_MULTIPLE_STAGES("reset reason ESP_RST_BROWNOUT after brownout event",
do_brownout,
check_reset_reason_brownout);

#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#ifdef CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
#ifndef CONFIG_FREERTOS_UNICORE
#if CONFIG_IDF_TARGET_ARCH_XTENSA
#include "xt_instr_macros.h"
Expand Down Expand Up @@ -402,6 +402,6 @@ TEST_CASE_MULTIPLE_STAGES("reset reason ESP_RST_PANIC after an exception in a ta

#endif //CONFIG_IDF_TARGET_ARCH_XTENSA
#endif // CONFIG_FREERTOS_UNICORE
#endif // CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#endif // CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM

/* Not tested here: ESP_RST_SDIO */
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
2 changes: 1 addition & 1 deletion components/espcoredump/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ menu "Core dump"

config ESP_COREDUMP_USE_STACK_SIZE
bool
default y if ESP_COREDUMP_ENABLE_TO_FLASH && SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
default y if ESP_COREDUMP_ENABLE_TO_FLASH && FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
default n
help
Force the use of a custom DRAM stack for coredump when Task stacks can be in PSRAM.
Expand Down
6 changes: 3 additions & 3 deletions components/espcoredump/src/port/riscv/core_dump_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const static char TAG[] __attribute__((unused)) = "esp_core_dump_port";
/**
* Union representing the registers of the CPU as they will be written
* in the core dump.
* Registers can be adressed with their names thanks to the structure, or as
* Registers can be addressed with their names thanks to the structure, or as
* an array of 32 words.
*/
#define RISCV_GP_REGS_COUNT 32
Expand Down Expand Up @@ -222,7 +222,7 @@ uint32_t esp_core_dump_get_isr_stack_end(void)
static inline bool esp_core_dump_task_stack_end_is_sane(uint32_t sp)
{
return esp_ptr_in_dram((void *)sp)
#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
#if CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM
|| esp_stack_ptr_in_extram(sp)
#endif
#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
Expand Down Expand Up @@ -315,7 +315,7 @@ bool esp_core_dump_mem_seg_is_sane(uint32_t addr, uint32_t sz)
}

/**
* Get the task's registers dump when the panic occured.
* Get the task's registers dump when the panic occurred.
* Returns the size, in bytes, of the data pointed by reg_dumps.
* The data pointed by reg_dump are allocated statically, thus, they must be
* used (or copied) before calling this function again.
Expand Down
Loading

0 comments on commit 1b79771

Please sign in to comment.