Skip to content

Commit

Permalink
Update support_esp32.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Nov 10, 2023
1 parent ede5e39 commit 098e29d
Showing 1 changed file with 31 additions and 36 deletions.
67 changes: 31 additions & 36 deletions tasmota/tasmota_support/support_esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
#define ESP32_ARCH ""
#endif

// Handle 20k of NVM

#include <nvs.h>

// See libraries\ESP32\examples\ResetReason.ino
#if ESP_IDF_VERSION_MAJOR > 3 // IDF 4+
#include "esp_chip_info.h"
Expand All @@ -64,18 +60,17 @@
#include "rom/rtc.h"
#endif

#if ESP_IDF_VERSION_MAJOR >= 5
#include "esp_chip_info.h"
#endif

// Set the Stacksize for Arduino core. Default is 8192, some builds may need a bigger one
size_t getArduinoLoopTaskStackSize(void) {
return SET_ESP32_STACK_SIZE;
return SET_ESP32_STACK_SIZE;
}


#include <esp_phy_init.h>

// Handle 20k of NVM

#include <nvs.h>

bool NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen) {
nvs_handle_t handle;
esp_err_t result = nvs_open(sNvsName, NVS_READONLY, &handle);
Expand Down Expand Up @@ -593,6 +588,32 @@ bool UsePSRAM(void) {
return FoundPSRAM() && can_use_psram;
}

/*
* ESP32 v1 and v2 needs some special patches to use PSRAM.
* Standard Tasmota 32 do not include those patches.
* If using ESP32 v1, please add: `-mfix-esp32-psram-cache-issue -lc-psram-workaround -lm-psram-workaround`
*
* This function returns true if the chip supports PSRAM natively (v3) or if the
* patches are present.
*/
bool CanUsePSRAM(void) {
if (!FoundPSRAM()) return false;
#ifdef HAS_PSRAM_FIX
return true;
#endif
#ifdef CONFIG_IDF_TARGET_ESP32
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
uint32_t chip_revision = chip_info.revision;
// idf5 efuse_hal_chip_revision(void)
if (chip_revision < 100) { chip_revision *= 100; } // Make <idf5 idf5
if ((CHIP_ESP32 == chip_info.model) && (chip_revision < 300)) {
return false;
}
#endif // CONFIG_IDF_TARGET_ESP32
return true;
}

void *special_malloc(uint32_t size) {
if (UsePSRAM()) {
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
Expand Down Expand Up @@ -927,32 +948,6 @@ String GetCodeCores(void) {
#endif
}

/*
* ESP32 v1 and v2 needs some special patches to use PSRAM.
* Standard Tasmota 32 do not include those patches.
* If using ESP32 v1, please add: `-mfix-esp32-psram-cache-issue -lc-psram-workaround -lm-psram-workaround`
*
* This function returns true if the chip supports PSRAM natively (v3) or if the
* patches are present.
*/
bool CanUsePSRAM(void) {
if (!FoundPSRAM()) return false;
#ifdef HAS_PSRAM_FIX
return true;
#endif
#ifdef CONFIG_IDF_TARGET_ESP32
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
uint32_t chip_revision = chip_info.revision;
// idf5 efuse_hal_chip_revision(void)
if (chip_revision < 100) { chip_revision *= 100; } // Make <idf5 idf5
if ((CHIP_ESP32 == chip_info.model) && (chip_revision < 300)) {
return false;
}
#endif // CONFIG_IDF_TARGET_ESP32
return true;
}

/*********************************************************************************************\
* High entropy hardware random generator
* Thanks to DigitalAlchemist
Expand Down

0 comments on commit 098e29d

Please sign in to comment.