From dc43b45f33eac0d09ff1269177fbc1bb43fbd7fd Mon Sep 17 00:00:00 2001 From: technyon Date: Sat, 21 Dec 2024 07:44:07 +0100 Subject: [PATCH] add psram check for RMII workaround --- clion/CMakeLists.txt | 3 +++ src/Config.h | 2 +- src/networkDevices/EthernetDevice.cpp | 9 ++++++++- src/util/PSRAM.cpp | 12 ++++++++++++ src/util/PSRAM.h | 11 +++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/util/PSRAM.cpp create mode 100644 src/util/PSRAM.h diff --git a/clion/CMakeLists.txt b/clion/CMakeLists.txt index f1c081d..26640d6 100644 --- a/clion/CMakeLists.txt +++ b/clion/CMakeLists.txt @@ -54,6 +54,8 @@ set(SRCFILES ../src/NukiOfficial.cpp ../src/NukiPublisher.cpp ../src/EspMillis.h + ../src/util/PSRAM.cpp + ../src/util/PSRAM.h ) file(GLOB_RECURSE SRCFILESREC @@ -79,6 +81,7 @@ include_directories( ../lib/MqttLogger/src ../lib/nuki_ble/src ../lib/PsychicHttp/src + ../src ) add_executable(dummy diff --git a/src/Config.h b/src/Config.h index aa3e0ed..0f4f63a 100644 --- a/src/Config.h +++ b/src/Config.h @@ -5,7 +5,7 @@ #define NUKI_HUB_VERSION "9.05" #define NUKI_HUB_VERSION_INT (uint32_t)905 #define NUKI_HUB_BUILD "unknownbuildnr" -#define NUKI_HUB_DATE "2024-12-20" +#define NUKI_HUB_DATE "2024-12-21" #define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest" #define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json" diff --git a/src/networkDevices/EthernetDevice.cpp b/src/networkDevices/EthernetDevice.cpp index 9123c01..bf497ff 100644 --- a/src/networkDevices/EthernetDevice.cpp +++ b/src/networkDevices/EthernetDevice.cpp @@ -6,6 +6,9 @@ #ifdef CONFIG_IDF_TARGET_ESP32 #include "esp_private/esp_gpio_reserve.h" +#include "util/PSRAM.h" +#include + #endif extern bool ethCriticalFailure; @@ -97,7 +100,11 @@ void EthernetDevice::initialize() // sources: // https://github.com/arendst/Tasmota/commit/f8fbe153000591727e40b5007e0de78c33833131 // https://github.com/arendst/Tasmota/commit/f8fbe153000591727e40b5007e0de78c33833131#diff-32fc0eefbf488dd507b3bef52189bbe37158737aba6f96fe98a8746dc5021955R417 - esp_gpio_revoke(0xFFFFFFFFFFFFFFFF); + uint32_t pkg_version = bootloader_common_get_chip_ver_pkg(); + if(PSRAM::found && pkg_version <= 3) + { + esp_gpio_revoke(0xFFFFFFFFFFFFFFFF); + } ethCriticalFailure = true; _hardwareInitialized = ETH.begin(_type, _phy_addr, _mdc, _mdio, _power, _clock_mode); diff --git a/src/util/PSRAM.cpp b/src/util/PSRAM.cpp new file mode 100644 index 0000000..1b97be3 --- /dev/null +++ b/src/util/PSRAM.cpp @@ -0,0 +1,12 @@ +#include "esp_psram.h" +#include "esp32-hal.h" +#include "PSRAM.h" + +const bool PSRAM::found(void) +{ +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || DISABLE_PSRAMCHECK || CORE32SOLO1 + return psramFound(); +#else + return psramFound() && esp_psram_is_initialized(); +#endif +} diff --git a/src/util/PSRAM.h b/src/util/PSRAM.h new file mode 100644 index 0000000..356c3fb --- /dev/null +++ b/src/util/PSRAM.h @@ -0,0 +1,11 @@ +#pragma once + +class PSRAM +{ + public: + // this function is a replacement for `psramFound()`. +// `psramFound()` can return true even if no PSRAM is actually installed +// This new version also checks `esp_spiram_is_initialized` to know if the PSRAM is initialized + static const bool found(void); + +};