Skip to content

Commit 5a06dd9

Browse files
fix(psram): Init PSRAM before app_main to fix mmu_map (#10390)
* fix(psram): Init PSRAM before app_main to fix mmu_map Makes sure that PSRAM is part of the map before app_main is called. * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent a4cbdaf commit 5a06dd9

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

cores/esp32/esp32-hal-log.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern "C" {
2020

2121
#include "sdkconfig.h"
2222
#include "esp_timer.h"
23+
#include "rom/ets_sys.h"
2324

2425
#define ARDUHAL_LOG_LEVEL_NONE (0)
2526
#define ARDUHAL_LOG_LEVEL_ERROR (1)

cores/esp32/esp32-hal-misc.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#ifdef CONFIG_APP_ROLLBACK_ENABLE
2525
#include "esp_ota_ops.h"
2626
#endif //CONFIG_APP_ROLLBACK_ENABLE
27+
#include "esp_private/startup_internal.h"
2728
#ifdef CONFIG_BT_ENABLED
2829
#include "esp_bt.h"
2930
#endif //CONFIG_BT_ENABLED
@@ -249,12 +250,17 @@ extern bool btInUse();
249250
#endif
250251
#endif
251252

253+
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
254+
#ifndef CONFIG_SPIRAM_BOOT_INIT
255+
ESP_SYSTEM_INIT_FN(init_psram_new, BIT(0), 99) {
256+
return psramInit() ? ESP_OK : ESP_FAIL;
257+
}
258+
#endif
259+
#endif
260+
252261
void initArduino() {
253262
//init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz)
254263
//ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1;
255-
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
256-
psramInit();
257-
#endif
258264
#ifdef CONFIG_APP_ROLLBACK_ENABLE
259265
if (!verifyRollbackLater()) {
260266
const esp_partition_t *running = esp_ota_get_running_partition();

cores/esp32/esp32-hal-psram.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#error Target CONFIG_IDF_TARGET is not supported
3232
#endif
3333

34+
#define TAG "arduino-psram"
35+
3436
static volatile bool spiramDetected = false;
3537
static volatile bool spiramFailed = false;
3638

@@ -52,7 +54,7 @@ bool psramInit() {
5254
uint32_t pkg_ver = chip_ver & 0x7;
5355
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) {
5456
spiramFailed = true;
55-
log_w("PSRAM not supported!");
57+
ESP_EARLY_LOGW(TAG, "PSRAM not supported!");
5658
return false;
5759
}
5860
#elif CONFIG_IDF_TARGET_ESP32S2
@@ -62,7 +64,7 @@ bool psramInit() {
6264
#endif
6365
if (esp_psram_init() != ESP_OK) {
6466
spiramFailed = true;
65-
log_w("PSRAM init failed!");
67+
ESP_EARLY_LOGW(TAG, "PSRAM init failed!");
6668
#if CONFIG_IDF_TARGET_ESP32
6769
if (pkg_ver != EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) {
6870
pinMatrixOutDetach(16, false, false);
@@ -71,23 +73,22 @@ bool psramInit() {
7173
#endif
7274
return false;
7375
}
74-
7576
//testSPIRAM() allows user to bypass SPI RAM test routine
7677
if (!testSPIRAM()) {
7778
spiramFailed = true;
78-
log_e("PSRAM test failed!");
79+
ESP_EARLY_LOGE(TAG, "PSRAM test failed!");
7980
return false;
8081
}
8182
if (esp_psram_extram_add_to_heap_allocator() != ESP_OK) {
8283
spiramFailed = true;
83-
log_e("PSRAM could not be added to the heap!");
84+
ESP_EARLY_LOGE(TAG, "PSRAM could not be added to the heap!");
8485
return false;
8586
}
8687
#if CONFIG_SPIRAM_USE_MALLOC && !CONFIG_ARDUINO_ISR_IRAM
8788
heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL);
8889
#endif
90+
ESP_EARLY_LOGI(TAG, "PSRAM enabled");
8991
#endif /* CONFIG_SPIRAM_BOOT_INIT */
90-
log_i("PSRAM enabled");
9192
spiramDetected = true;
9293
return true;
9394
}

0 commit comments

Comments
 (0)