Skip to content

Commit 9b5405d

Browse files
committed
fix(psram): Do not abort if PSRAM is not found
Also add to heap in app_main
1 parent 85d8a9e commit 9b5405d

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

cores/esp32/esp32-hal-misc.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,20 @@ extern bool btInUse();
255255
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
256256
#ifndef CONFIG_SPIRAM_BOOT_INIT
257257
ESP_SYSTEM_INIT_FN(init_psram_new, CORE, BIT(0), 99) {
258-
return psramInit() ? ESP_OK : ESP_FAIL;
258+
psramInit();
259+
return ESP_OK;
259260
}
260261
#endif
261262
#endif
262263

263264
void initArduino() {
264265
//init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz)
265266
//ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1;
267+
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
268+
#ifndef CONFIG_SPIRAM_BOOT_INIT
269+
psramAddToHeap();
270+
#endif
271+
#endif
266272
#ifdef CONFIG_APP_ROLLBACK_ENABLE
267273
if (!verifyRollbackLater()) {
268274
const esp_partition_t *running = esp_ota_get_running_partition();

cores/esp32/esp32-hal-psram.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,25 @@ bool psramInit() {
8181
ESP_EARLY_LOGE(TAG, "PSRAM test failed!");
8282
return false;
8383
}
84+
ESP_EARLY_LOGI(TAG, "PSRAM enabled");
85+
#endif /* CONFIG_SPIRAM_BOOT_INIT */
86+
spiramDetected = true;
87+
return true;
88+
}
89+
90+
bool psramAddToHeap() {
91+
if (!spiramDetected) {
92+
log_e("PSRAM not initialized!");
93+
return false;
94+
}
8495
if (esp_psram_extram_add_to_heap_allocator() != ESP_OK) {
85-
spiramFailed = true;
86-
ESP_EARLY_LOGE(TAG, "PSRAM could not be added to the heap!");
96+
log_e("PSRAM could not be added to the heap!");
8797
return false;
8898
}
8999
#if CONFIG_SPIRAM_USE_MALLOC && !CONFIG_ARDUINO_ISR_IRAM
90100
heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL);
91101
#endif
92-
ESP_EARLY_LOGI(TAG, "PSRAM enabled");
93-
#endif /* CONFIG_SPIRAM_BOOT_INIT */
94-
spiramDetected = true;
102+
log_i("PSRAM added to the heap.");
95103
return true;
96104
}
97105

cores/esp32/esp32-hal-psram.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern "C" {
3131
#endif
3232

3333
bool psramInit();
34+
bool psramAddToHeap();
3435
bool psramFound();
3536

3637
void *ps_malloc(size_t size);

0 commit comments

Comments
 (0)