Skip to content

Commit ff2c17a

Browse files
committed
fix(psram): Do not abort if PSRAM is not found
Also add to heap in app_main
1 parent 5a06dd9 commit ff2c17a

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
@@ -253,14 +253,20 @@ extern bool btInUse();
253253
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
254254
#ifndef CONFIG_SPIRAM_BOOT_INIT
255255
ESP_SYSTEM_INIT_FN(init_psram_new, BIT(0), 99) {
256-
return psramInit() ? ESP_OK : ESP_FAIL;
256+
psramInit();
257+
return ESP_OK;
257258
}
258259
#endif
259260
#endif
260261

261262
void initArduino() {
262263
//init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz)
263264
//ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1;
265+
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
266+
#ifndef CONFIG_SPIRAM_BOOT_INIT
267+
psramAddToHeap();
268+
#endif
269+
#endif
264270
#ifdef CONFIG_APP_ROLLBACK_ENABLE
265271
if (!verifyRollbackLater()) {
266272
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
@@ -79,17 +79,25 @@ bool psramInit() {
7979
ESP_EARLY_LOGE(TAG, "PSRAM test failed!");
8080
return false;
8181
}
82+
ESP_EARLY_LOGI(TAG, "PSRAM enabled");
83+
#endif /* CONFIG_SPIRAM_BOOT_INIT */
84+
spiramDetected = true;
85+
return true;
86+
}
87+
88+
bool psramAddToHeap() {
89+
if (!spiramDetected) {
90+
log_e("PSRAM not initialized!");
91+
return false;
92+
}
8293
if (esp_psram_extram_add_to_heap_allocator() != ESP_OK) {
83-
spiramFailed = true;
84-
ESP_EARLY_LOGE(TAG, "PSRAM could not be added to the heap!");
94+
log_e("PSRAM could not be added to the heap!");
8595
return false;
8696
}
8797
#if CONFIG_SPIRAM_USE_MALLOC && !CONFIG_ARDUINO_ISR_IRAM
8898
heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL);
8999
#endif
90-
ESP_EARLY_LOGI(TAG, "PSRAM enabled");
91-
#endif /* CONFIG_SPIRAM_BOOT_INIT */
92-
spiramDetected = true;
100+
log_i("PSRAM added to the heap.");
93101
return true;
94102
}
95103

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)