Enables PSRAM

Supports #1983
Supports #1946
Supports #1815

Could support esphome/feature-requests#2369
This commit is contained in:
Edward Firmo
2024-04-05 00:54:51 +02:00
parent 0e6853f3bf
commit 140cbdd409
3 changed files with 47 additions and 23 deletions

View File

@@ -1,7 +1,8 @@
# __init__.py
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.core import coroutine_with_priority
from esphome.components.esp32 import add_idf_sdkconfig_option, get_esp32_variant
from esphome.core import CORE, coroutine_with_priority
CODEOWNERS = ["@edwardtfn"]
@@ -14,5 +15,17 @@ CONFIG_SCHEMA = cv.All(
@coroutine_with_priority(1.0)
async def to_code(config):
if CORE.using_arduino:
cg.add_build_flag("-DCONFIG_D0WD_PSRAM_CLK_IO=5")
cg.add_build_flag("-DCONFIG_D0WD_PSRAM_CS_IO=18")
if CORE.using_esp_idf:
add_idf_sdkconfig_option("CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST", True)
add_idf_sdkconfig_option("CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY", True)
add_idf_sdkconfig_option("CONFIG_ESP32_REV_MIN_3", True)
add_idf_sdkconfig_option("CONFIG_D0WD_PSRAM_CLK_IO", 5)
add_idf_sdkconfig_option("CONFIG_D0WD_PSRAM_CS_IO", 18)
cg.add_define("USE_NSPANEL_HA_BLUEPRINT")
cg.add_global(nspanel_ha_blueprint_ns.using)

View File

@@ -3,7 +3,8 @@
<!-- markdownlint-disable MD013 MD033 -->
| NSPanel_HA_Blueprint<br><sub><sup>Version</sup></sub> | Home Assistant<br><sub><sup>Min version</sup></sub> | ESPHome<br><sub><sup>Min version</sup></sub> |
| :--: | :--: | :--: |
| v4.3.1 | 2024.3.0 | 2024.3.0 |
| v4.3.3 | 2024.3.0 | 2023.12.0 |
| v4.3.2<br>v4.3.1 | 2024.3.0 | 2024.3.0 |
| v4.3.0 | 2024.3.0 | 2023.12.0 |
| v4.2.2+ | 2023.12.0 | 2023.12.0 |
| v4.2.1<br>v4.2 | 2023.9.0 | 2023.12.0 |

View File

@@ -27,7 +27,7 @@ external_components:
# path: packages/Blackymas/components
type: git
url: https://github.com/Blackymas/NSPanel_HA_Blueprint
ref: v4.3.2
ref: dev # To do: Change to tag when releasing
components:
- nspanel_ha_blueprint
refresh: 300s
@@ -50,16 +50,10 @@ external_components:
esphome:
name: ${name}
friendly_name: ${friendly_name}
min_version: 2024.3.0
min_version: 2023.12.0
platformio_options:
build_flags:
- -Wno-missing-field-initializers
# - -mfix-esp32-psram-cache-issue
# - -fdata-sections
# - -ffunction-sections
# - -Wl,--gc-sections
# - -Os
# - -flto
on_boot:
- priority: 600.0 # This is where most sensors are set up.
@@ -106,6 +100,11 @@ esp32:
framework:
type: esp-idf
debug:
psram:
id: ext_ram
##### WIFI SETUP #####
wifi:
id: wifi_component
@@ -2212,7 +2211,11 @@ script:
- lambda: |-
boot_progress->execute(3);
if (current_page->state == "boot") {
#if ESPHOME_VERSION_CODE < VERSION_CODE(2024, 3, 0) // Code for ESPHome earlier than v2024.3.0
disp1->set_component_text("ip_addr", network::get_ip_address().str().c_str());
#else // Code for ESPHome v2024.3.0 or newer
disp1->set_component_text("ip_addr", network::get_ip_addresses()[0].str().c_str());
#endif // ESPHome version based code
set_brightness->execute(100);
}
- logger.log: Wait for API
@@ -3166,25 +3169,32 @@ script:
// Report ESPHome
ESP_LOGI(TAG, "ESPHome:");
ESP_LOGI(TAG, " Version: ${version}");
ESP_LOGI(TAG, " Compiler: %s", ESPHOME_VERSION);
// Report framework
#ifdef ARDUINO
ESP_LOGI(TAG, " Framework: Arduino");
size_t total_heap_size = ESP.getHeapSize();
size_t free_heap_size = ESP.getFreeHeap();
#elif defined(USE_ESP_IDF)
ESP_LOGI(TAG, " Framework: ESP-IDF");
size_t total_heap_size = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
size_t free_heap_size = esp_get_free_heap_size();
#endif
if (total_heap_size != 0) {
std::string numStr = std::to_string(free_heap_size);
int insertPosition = numStr.length() - 3;
while (insertPosition > 0) {
numStr.insert(insertPosition, " ");
insertPosition -= 3;
}
ESP_LOGI(TAG, " Free heap: %s bytes (%d%%)", numStr.c_str(),
int(round(((float)free_heap_size / total_heap_size) * 100.0f)));
// Report memory
const size_t internal_heap_size = heap_caps_get_total_size(MALLOC_CAP_INTERNAL);
const size_t internal_heap_size_free = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
const size_t psram_heap_size = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
const size_t psram_heap_size_free = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
ESP_LOGI(TAG, " Free heap:");
if (internal_heap_size != 0) {
ESP_LOGI(TAG, " Internal: %7d bytes (%0.1f%%)", internal_heap_size_free,
((float)internal_heap_size_free / internal_heap_size) * 100.0f);
} else {
ESP_LOGI(TAG, " Internal: %7d bytes", internal_heap_size_free);
}
if (psram_heap_size != 0) {
ESP_LOGI(TAG, " PSRAM: %7d bytes (%0.1f%%)", psram_heap_size_free,
((float)psram_heap_size_free / psram_heap_size) * 100.0f);
} else {
ESP_LOGI(TAG, " PSRAM: %7d bytes", psram_heap_size_free);
}
// Report UART
ESP_LOGI(TAG, "UART:");