Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(psram): Do not abort if PSRAM is not found #10395

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cores/esp32/esp32-hal-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,20 @@ extern bool btInUse();
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
#ifndef CONFIG_SPIRAM_BOOT_INIT
ESP_SYSTEM_INIT_FN(init_psram_new, BIT(0), 99) {
return psramInit() ? ESP_OK : ESP_FAIL;
psramInit();
return ESP_OK;
}
#endif
#endif

void initArduino() {
//init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz)
//ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1;
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
#ifndef CONFIG_SPIRAM_BOOT_INIT
psramAddToHeap();
#endif
#endif
#ifdef CONFIG_APP_ROLLBACK_ENABLE
if (!verifyRollbackLater()) {
const esp_partition_t *running = esp_ota_get_running_partition();
Expand Down
18 changes: 13 additions & 5 deletions cores/esp32/esp32-hal-psram.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,25 @@ bool psramInit() {
ESP_EARLY_LOGE(TAG, "PSRAM test failed!");
return false;
}
ESP_EARLY_LOGI(TAG, "PSRAM enabled");
#endif /* CONFIG_SPIRAM_BOOT_INIT */
spiramDetected = true;
return true;
}

bool psramAddToHeap() {
if (!spiramDetected) {
log_e("PSRAM not initialized!");
return false;
}
if (esp_psram_extram_add_to_heap_allocator() != ESP_OK) {
spiramFailed = true;
ESP_EARLY_LOGE(TAG, "PSRAM could not be added to the heap!");
log_e("PSRAM could not be added to the heap!");
return false;
}
#if CONFIG_SPIRAM_USE_MALLOC && !CONFIG_ARDUINO_ISR_IRAM
heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL);
#endif
ESP_EARLY_LOGI(TAG, "PSRAM enabled");
#endif /* CONFIG_SPIRAM_BOOT_INIT */
spiramDetected = true;
log_i("PSRAM added to the heap.");
return true;
}

Expand Down
1 change: 1 addition & 0 deletions cores/esp32/esp32-hal-psram.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" {
#endif

bool psramInit();
bool psramAddToHeap();
bool psramFound();

void *ps_malloc(size_t size);
Expand Down
Loading