Skip to content

Commit ff0408c

Browse files
feat(esp_system): Adds Kconfigs to place code in IRAM
1 parent ba2b0fd commit ff0408c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+216
-132
lines changed

components/esp_system/Kconfig

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ menu "ESP System Settings"
99

1010
orsource "./port/soc/$IDF_TARGET/Kconfig.tracemem"
1111

12+
config ESP_SYSTEM_IN_IRAM
13+
bool "Place system functions in IRAM" if SPI_FLASH_AUTO_SUSPEND
14+
default y
15+
help
16+
The following system functions will be placed in IRAM if this option is enabled:
17+
- system startup
18+
- system time
19+
- system error
20+
- system restart
21+
- system crosscore
22+
- system debug
23+
- system APB backup DMA lock
24+
- system application tick hook
25+
- Unified Behavior Sanitizer (UBSAN) hook
26+
- Interrupt watchdog handler
27+
- XTAL32K watchdog timer
28+
- USB CDC functions for the esp_rom_printf (if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF=y)
29+
- IPC and IPC ISR
30+
1231
choice ESP_SYSTEM_PANIC
1332
prompt "Panic handler behaviour"
1433
default ESP_SYSTEM_PANIC_PRINT_REBOOT
@@ -635,6 +654,11 @@ endmenu # ESP System Settings
635654

636655
menu "IPC (Inter-Processor Call)"
637656

657+
config ESP_IPC_ENABLE
658+
bool
659+
default y
660+
depends on !ESP_SYSTEM_SINGLE_CORE_MODE || APPTRACE_GCOV_ENABLE
661+
638662
config ESP_IPC_TASK_STACK_SIZE
639663
int "Inter-Processor Call (IPC) task stack size"
640664
range 512 65536 if !APPTRACE_ENABLE
@@ -651,7 +675,7 @@ menu "IPC (Inter-Processor Call)"
651675
config ESP_IPC_USES_CALLERS_PRIORITY
652676
bool "IPC runs at caller's priority"
653677
default y
654-
depends on !FREERTOS_UNICORE
678+
depends on ESP_IPC_ENABLE
655679
help
656680
If this option is not enabled then the IPC task will keep behavior same as prior to that of ESP-IDF v4.0,
657681
hence IPC task will run at (configMAX_PRIORITIES - 1) priority.

components/esp_system/crosscore_int.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
#include "sdkconfig.h"
77
#include <stdint.h>
8-
#include "esp_attr.h"
8+
#include "esp_private/esp_system_attr.h"
99
#include "esp_err.h"
1010
#include "esp_cpu.h"
1111
#include "esp_intr_alloc.h"
@@ -34,12 +34,12 @@ static volatile uint32_t reason[CONFIG_FREERTOS_NUMBER_OF_CORES];
3434
ToDo: There is a small chance the CPU already has yielded when this ISR is serviced. In that case, it's running the intended task but
3535
the ISR will cause it to switch _away_ from it. portYIELD_FROM_ISR will probably just schedule the task again, but have to check that.
3636
*/
37-
static inline void IRAM_ATTR esp_crosscore_isr_handle_yield(void)
37+
static inline void ESP_SYSTEM_IRAM_ATTR esp_crosscore_isr_handle_yield(void)
3838
{
3939
portYIELD_FROM_ISR();
4040
}
4141

42-
static void IRAM_ATTR esp_crosscore_isr(void *arg)
42+
static void ESP_SYSTEM_IRAM_ATTR esp_crosscore_isr(void *arg)
4343
{
4444
uint32_t my_reason_val;
4545
//A pointer to the correct reason array item is passed to this ISR.
@@ -93,19 +93,23 @@ void esp_crosscore_int_init(void)
9393
reason[esp_cpu_get_core_id()] = 0;
9494
portEXIT_CRITICAL(&reason_spinlock);
9595
esp_err_t err __attribute__((unused)) = ESP_OK;
96+
int flags = 0;
97+
#if CONFIG_ESP_SYSTEM_IN_IRAM
98+
flags |= ESP_INTR_FLAG_IRAM;
99+
#endif
96100
#if CONFIG_FREERTOS_NUMBER_OF_CORES > 1
97101
if (esp_cpu_get_core_id() == 0) {
98-
err = esp_intr_alloc(SYS_CPU_INTR_FROM_CPU_0_SOURCE, ESP_INTR_FLAG_IRAM, esp_crosscore_isr, (void*)&reason[0], NULL);
102+
err = esp_intr_alloc(SYS_CPU_INTR_FROM_CPU_0_SOURCE, flags, esp_crosscore_isr, (void*)&reason[0], NULL);
99103
} else {
100-
err = esp_intr_alloc(SYS_CPU_INTR_FROM_CPU_1_SOURCE, ESP_INTR_FLAG_IRAM, esp_crosscore_isr, (void*)&reason[1], NULL);
104+
err = esp_intr_alloc(SYS_CPU_INTR_FROM_CPU_1_SOURCE, flags, esp_crosscore_isr, (void*)&reason[1], NULL);
101105
}
102106
#else
103-
err = esp_intr_alloc(SYS_CPU_INTR_FROM_CPU_0_SOURCE, ESP_INTR_FLAG_IRAM, esp_crosscore_isr, (void*)&reason[0], NULL);
107+
err = esp_intr_alloc(SYS_CPU_INTR_FROM_CPU_0_SOURCE, flags, esp_crosscore_isr, (void*)&reason[0], NULL);
104108
#endif
105109
ESP_ERROR_CHECK(err);
106110
}
107111

108-
static void IRAM_ATTR esp_crosscore_int_send(int core_id, uint32_t reason_mask)
112+
static void ESP_SYSTEM_IRAM_ATTR esp_crosscore_int_send(int core_id, uint32_t reason_mask)
109113
{
110114
assert(core_id < CONFIG_FREERTOS_NUMBER_OF_CORES);
111115
//Mark the reason we interrupt the other CPU
@@ -116,28 +120,28 @@ static void IRAM_ATTR esp_crosscore_int_send(int core_id, uint32_t reason_mask)
116120
crosscore_int_ll_trigger_interrupt(core_id);
117121
}
118122

119-
void IRAM_ATTR esp_crosscore_int_send_yield(int core_id)
123+
void ESP_SYSTEM_IRAM_ATTR esp_crosscore_int_send_yield(int core_id)
120124
{
121125
esp_crosscore_int_send(core_id, REASON_YIELD);
122126
}
123127

124-
void IRAM_ATTR esp_crosscore_int_send_freq_switch(int core_id)
128+
void ESP_SYSTEM_IRAM_ATTR esp_crosscore_int_send_freq_switch(int core_id)
125129
{
126130
esp_crosscore_int_send(core_id, REASON_FREQ_SWITCH);
127131
}
128132

129-
void IRAM_ATTR esp_crosscore_int_send_gdb_call(int core_id)
133+
void ESP_SYSTEM_IRAM_ATTR esp_crosscore_int_send_gdb_call(int core_id)
130134
{
131135
esp_crosscore_int_send(core_id, REASON_GDB_CALL);
132136
}
133137

134-
void IRAM_ATTR esp_crosscore_int_send_print_backtrace(int core_id)
138+
void ESP_SYSTEM_IRAM_ATTR esp_crosscore_int_send_print_backtrace(int core_id)
135139
{
136140
esp_crosscore_int_send(core_id, REASON_PRINT_BACKTRACE);
137141
}
138142

139143
#if CONFIG_ESP_TASK_WDT_EN
140-
void IRAM_ATTR esp_crosscore_int_send_twdt_abort(int core_id)
144+
void ESP_SYSTEM_IRAM_ATTR esp_crosscore_int_send_twdt_abort(int core_id)
141145
{
142146
esp_crosscore_int_send(core_id, REASON_TWDT_ABORT);
143147
}

components/esp_system/esp_ipc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -12,7 +12,7 @@
1212
#include "esp_err.h"
1313
#include "esp_ipc.h"
1414
#include "esp_private/esp_ipc_isr.h"
15-
#include "esp_attr.h"
15+
#include "esp_private/esp_system_attr.h"
1616
#include "esp_cpu.h"
1717

1818
#include "freertos/FreeRTOS.h"
@@ -21,7 +21,7 @@
2121

2222
#define IPC_MAX_PRIORITY (configMAX_PRIORITIES - 1)
2323

24-
#if !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE)
24+
#if CONFIG_ESP_IPC_ENABLE
2525

2626
#if CONFIG_COMPILER_OPTIMIZATION_NONE
2727
#define IPC_STACK_SIZE (CONFIG_ESP_IPC_TASK_STACK_SIZE + 0x100)
@@ -49,7 +49,7 @@ static volatile esp_ipc_func_t s_no_block_func[portNUM_PROCESSORS] = { 0 };
4949
static volatile bool s_no_block_func_and_arg_are_ready[portNUM_PROCESSORS] = { 0 };
5050
static void * volatile s_no_block_func_arg[portNUM_PROCESSORS];
5151

52-
static void IRAM_ATTR ipc_task(void* arg)
52+
static void ESP_SYSTEM_IRAM_ATTR ipc_task(void* arg)
5353
{
5454
const int cpuid = (int) arg;
5555

@@ -198,4 +198,4 @@ esp_err_t esp_ipc_call_nonblocking(uint32_t cpu_id, esp_ipc_func_t func, void* a
198198
return ESP_FAIL;
199199
}
200200

201-
#endif // !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE)
201+
#endif // CONFIG_ESP_IPC_ENABLE

components/esp_system/fp_unwind.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "sdkconfig.h"
88
#include <string.h>
9+
#include "esp_private/esp_system_attr.h"
910
#include "esp_private/panic_internal.h"
1011
#include "esp_memory_utils.h"
1112
#include "riscv/libunwind-riscv.h"
@@ -52,7 +53,7 @@ static inline bool esp_fp_ptr_is_data(void* ptr)
5253
*
5354
* @returns Number of entries filled in the array.
5455
*/
55-
uint32_t IRAM_ATTR esp_fp_get_callers(uint32_t frame, void** callers, void** stacks, uint32_t depth)
56+
uint32_t ESP_SYSTEM_IRAM_ATTR esp_fp_get_callers(uint32_t frame, void** callers, void** stacks, uint32_t depth)
5657
{
5758
uint32_t written = 0;
5859
uint32_t pc = 0;

components/esp_system/freertos_hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static portMUX_TYPE hooks_spinlock = portMUX_INITIALIZER_UNLOCKED;
2727
static esp_freertos_idle_cb_t idle_cb[CONFIG_FREERTOS_NUMBER_OF_CORES][MAX_HOOKS] = {0};
2828
static esp_freertos_tick_cb_t tick_cb[CONFIG_FREERTOS_NUMBER_OF_CORES][MAX_HOOKS] = {0};
2929

30-
void IRAM_ATTR esp_vApplicationTickHook(void)
30+
void esp_vApplicationTickHook(void)
3131
{
3232
int n;
3333
int core = xPortGetCoreID();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include "esp_attr.h"
10+
#include "sdkconfig.h"
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
#if CONFIG_ESP_SYSTEM_IN_IRAM
17+
#define ESP_SYSTEM_IRAM_ATTR IRAM_ATTR
18+
#else
19+
#define ESP_SYSTEM_IRAM_ATTR
20+
#endif
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif

components/esp_system/int_wdt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "esp_cpu.h"
1818
#include "esp_check.h"
1919
#include "esp_err.h"
20-
#include "esp_attr.h"
20+
#include "esp_private/esp_system_attr.h"
2121
#include "esp_log.h"
2222
#include "esp_intr_alloc.h"
2323
#include "esp_chip_info.h"
@@ -101,7 +101,7 @@ extern uint32_t _lx_intr_livelock_counter, _lx_intr_livelock_max;
101101
volatile bool int_wdt_cpu1_ticked = false;
102102
#endif
103103

104-
static void IRAM_ATTR tick_hook(void)
104+
static void ESP_SYSTEM_IRAM_ATTR tick_hook(void)
105105
{
106106
#if CONFIG_ESP_INT_WDT_CHECK_CPU1
107107
if (esp_cpu_get_core_id() != 0) {

components/esp_system/linker.lf

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,52 @@ entries:
1212
hw_stack_guard:esp_hw_stack_guard_get_fired_cpu (noflash)
1313
hw_stack_guard:esp_hw_stack_guard_get_pc (noflash)
1414

15-
esp_err (noflash)
16-
esp_system_chip:esp_system_abort (noflash)
17-
ubsan (noflash)
18-
19-
if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF:
20-
usb_console:esp_usb_console_write_char (noflash)
21-
usb_console:esp_usb_console_write_buf (noflash)
22-
usb_console:esp_usb_console_flush_internal (noflash)
23-
usb_console:esp_usb_console_osglue_wait_proc (noflash)
24-
usb_console:esp_usb_console_osglue_dis_int (noflash)
25-
usb_console:esp_usb_console_osglue_ena_int (noflash)
26-
usb_console:esp_usb_console_interrupt (noflash)
27-
usb_console:esp_usb_console_poll_interrupts (noflash)
28-
usb_console:esp_usb_console_cdc_acm_cb (noflash)
29-
usb_console:esp_usb_console_dfu_detach_cb (noflash)
30-
usb_console:esp_usb_console_before_restart (noflash)
31-
usb_console:esp_usb_console_on_restart_timeout (noflash)
15+
# These functions are called when the cache is disabled
16+
system_internal:esp_restart_noos (noflash)
17+
system_internal:esp_system_reset_modules_on_exit (noflash)
18+
19+
if ESP_PANIC_HANDLER_IRAM = y || ESP_BROWNOUT_USE_INTR = y:
20+
reset_reason:esp_reset_reason_set_hint (noflash)
21+
22+
# It may be called very frequently, so place it in IRAM to avoid performance degradation
23+
freertos_hooks:esp_vApplicationTickHook (noflash)
24+
25+
if ESP_SYSTEM_IN_IRAM = y:
26+
esp_err (noflash)
27+
esp_system_chip:esp_system_abort (noflash)
28+
panic:panic_abort (noflash)
29+
if IDF_TARGET_ESP32 = y:
30+
esp_system_chip:esp_restart_noos_dig (noflash)
31+
system_time:esp_system_get_time (noflash)
32+
system_time:esp_system_get_time_resolution (noflash)
33+
ubsan (noflash)
34+
if COMPILER_STACK_CHECK = y:
35+
stack_check:__stack_chk_fail (noflash)
36+
37+
if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF:
38+
usb_console:esp_usb_console_write_char (noflash)
39+
usb_console:esp_usb_console_write_buf (noflash)
40+
usb_console:esp_usb_console_flush_internal (noflash)
41+
usb_console:esp_usb_console_osglue_wait_proc (noflash)
42+
usb_console:esp_usb_console_osglue_dis_int (noflash)
43+
usb_console:esp_usb_console_osglue_ena_int (noflash)
44+
usb_console:esp_usb_console_interrupt (noflash)
45+
usb_console:esp_usb_console_poll_interrupts (noflash)
46+
usb_console:esp_usb_console_cdc_acm_cb (noflash)
47+
usb_console:esp_usb_console_dfu_detach_cb (noflash)
48+
usb_console:esp_usb_console_before_restart (noflash)
49+
usb_console:esp_usb_console_on_restart_timeout (noflash)
3250

3351
if APP_BUILD_TYPE_RAM = n:
3452
image_process (noflash)
3553

3654
[mapping:vfs_cdcacm]
3755
archive: libvfs.a
3856
entries:
39-
if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF:
40-
vfs_cdcacm:cdcacm_tx_cb (noflash)
41-
vfs_cdcacm:cdcacm_rx_cb (noflash)
57+
if ESP_SYSTEM_IN_IRAM = y:
58+
if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF:
59+
vfs_cdcacm:cdcacm_tx_cb (noflash)
60+
vfs_cdcacm:cdcacm_rx_cb (noflash)
4261

4362
[mapping:esp_system_hal]
4463
archive: libhal.a

components/esp_system/panic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void esp_panic_handler(panic_info_t *info)
463463
#endif /* CONFIG_ESP_SYSTEM_PANIC_GDBSTUB */
464464
}
465465

466-
void IRAM_ATTR __attribute__((noreturn, no_sanitize_undefined)) panic_abort(const char *details)
466+
void __attribute__((noreturn, no_sanitize_undefined)) panic_abort(const char *details)
467467
{
468468
g_panic_abort = true;
469469
g_panic_abort_details = (char *) details;
@@ -490,11 +490,11 @@ void IRAM_ATTR __attribute__((noreturn, no_sanitize_undefined)) panic_abort(cons
490490
* If these weren't provided, reset reason code would be linked into the app
491491
* even if the app never called esp_reset_reason().
492492
*/
493-
void IRAM_ATTR __attribute__((weak)) esp_reset_reason_set_hint(esp_reset_reason_t hint)
493+
void __attribute__((weak)) esp_reset_reason_set_hint(esp_reset_reason_t hint)
494494
{
495495
}
496496

497-
esp_reset_reason_t IRAM_ATTR __attribute__((weak)) esp_reset_reason_get_hint(void)
497+
esp_reset_reason_t __attribute__((weak)) esp_reset_reason_get_hint(void)
498498
{
499499
return ESP_RST_UNKNOWN;
500500
}

components/esp_system/port/arch/riscv/debug_helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "freertos/task.h"
1212
#include "esp_private/freertos_debug.h"
1313
#include "esp_err.h"
14-
#include "esp_attr.h"
14+
#include "esp_private/esp_system_attr.h"
1515
#include "esp_private/esp_cpu_internal.h"
1616
#include <string.h>
1717

@@ -36,7 +36,7 @@ extern void panic_print_registers(const void *frame, int core);
3636
* exit this handler as fast as possible, then we will simply print
3737
* the interruptee's registers.
3838
*/
39-
esp_err_t IRAM_ATTR esp_backtrace_print(int depth)
39+
esp_err_t ESP_SYSTEM_IRAM_ATTR esp_backtrace_print(int depth)
4040
{
4141
(void)depth;
4242

0 commit comments

Comments
 (0)