diff --git a/components/esp_psram/esp_psram.c b/components/esp_psram/esp_psram.c index 1201540dc3..09f2b43dab 100644 --- a/components/esp_psram/esp_psram.c +++ b/components/esp_psram/esp_psram.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -27,7 +27,7 @@ #include "esp_psram.h" #include "esp_private/esp_mmu_map_private.h" #include "esp_mmu_map.h" - +#include "esp_private/startup_internal.h" #if CONFIG_IDF_TARGET_ESP32 #include "esp32/himem.h" #include "esp32/rom/cache.h" @@ -82,6 +82,23 @@ typedef struct { static psram_ctx_t s_psram_ctx; static const char* TAG = "esp_psram"; +ESP_SYSTEM_INIT_FN(init_psram, CORE, BIT(0), 103) +{ +#if CONFIG_SPIRAM_BOOT_INIT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC) + if (esp_psram_is_initialized()) { + esp_err_t r = esp_psram_extram_add_to_heap_allocator(); + if (r != ESP_OK) { + ESP_EARLY_LOGE(TAG, "External RAM could not be added to heap!"); + abort(); + } +#if CONFIG_SPIRAM_USE_MALLOC + heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); +#endif + } +#endif + return ESP_OK; +} + #if CONFIG_IDF_TARGET_ESP32 //If no function in esp_himem.c is used, this function will be linked into the //binary instead of the one in esp_himem.c, automatically making sure no memory diff --git a/components/esp_system/startup_funcs.c b/components/esp_system/startup_funcs.c index db6509889b..a4b33ba653 100644 --- a/components/esp_system/startup_funcs.c +++ b/components/esp_system/startup_funcs.c @@ -44,11 +44,6 @@ #include "hal/brownout_ll.h" #endif -#if CONFIG_SPIRAM -#include "esp_psram.h" -#include "esp_private/esp_psram_extram.h" -#endif - // Using the same tag as in startup.c to keep the logs unchanged static const char* TAG = "cpu_start"; @@ -68,23 +63,6 @@ ESP_SYSTEM_INIT_FN(init_show_cpu_freq, CORE, BIT(0), 10) return ESP_OK; } -ESP_SYSTEM_INIT_FN(init_psram_heap, CORE, BIT(0), 103) -{ -#if CONFIG_SPIRAM_BOOT_INIT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC) - if (esp_psram_is_initialized()) { - esp_err_t r = esp_psram_extram_add_to_heap_allocator(); - if (r != ESP_OK) { - ESP_EARLY_LOGE(TAG, "External RAM could not be added to heap!"); - abort(); - } -#if CONFIG_SPIRAM_USE_MALLOC - heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); -#endif - } -#endif - return ESP_OK; -} - ESP_SYSTEM_INIT_FN(init_brownout, CORE, BIT(0), 104) { // [refactor-todo] leads to call chain rtc_is_register (driver) -> esp_intr_alloc (esp32/esp32s2) -> diff --git a/components/esp_system/system_init_fn.txt b/components/esp_system/system_init_fn.txt index beb3c458df..e633707452 100644 --- a/components/esp_system/system_init_fn.txt +++ b/components/esp_system/system_init_fn.txt @@ -41,7 +41,7 @@ CORE: 100: init_heap in components/heap/heap_caps_init.c on BIT(0) CORE: 101: esp_timer_init_nonos in components/esp_timer/src/esp_timer_init.c on BIT(0) CORE: 102: init_newlib in components/newlib/newlib_init.c on BIT(0) -CORE: 103: init_psram_heap in components/esp_system/startup_funcs.c on BIT(0) +CORE: 103: init_psram in components/esp_psram/esp_psram.c on BIT(0) CORE: 104: init_brownout in components/esp_system/startup_funcs.c on BIT(0) CORE: 105: init_newlib_time in components/esp_system/startup_funcs.c on BIT(0)