From 452c6fabb05f5700e59c4d9bb90eb4b0cafada47 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sat, 17 Sep 2022 15:53:58 +0200 Subject: [PATCH] Tasmota Core 2.0.5 * Flash real size is now in core * Flash chip magic size now in Tasmota `ESP_getFlashChipMagicSize` * Tasmota Core 2.0.5 --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- boards/esp32s3cdc-cam.json | 12 ++- platformio_tasmota32.ini | 6 +- tasmota/tasmota_support/settings.ino | 4 +- tasmota/tasmota_support/support_command.ino | 5 +- tasmota/tasmota_support/support_esp.ino | 75 +++++++++---------- .../xdrv_01_9_webserver.ino | 10 ++- .../xdrv_52_3_berry_tasmota.ino | 4 +- 8 files changed, 68 insertions(+), 50 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 44032a982..88dc78c9d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -7,7 +7,7 @@ - [ ] Only relevant files were touched - [ ] Only one feature/fix was added per PR and the code change compiles without warnings - [ ] The code change is tested and works with Tasmota core ESP8266 V.2.7.4.9 - - [ ] The code change is tested and works with Tasmota core ESP32 V.2.0.4.1 + - [ ] The code change is tested and works with Tasmota core ESP32 V.2.0.5 - [ ] I accept the [CLA](https://github.com/arendst/Tasmota/blob/development/CONTRIBUTING.md#contributor-license-agreement-cla). _NOTE: The code change must pass CI tests. **Your PR cannot be merged unless tests pass**_ diff --git a/boards/esp32s3cdc-cam.json b/boards/esp32s3cdc-cam.json index 6d72384da..761236e61 100644 --- a/boards/esp32s3cdc-cam.json +++ b/boards/esp32s3cdc-cam.json @@ -9,6 +9,12 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], "mcu": "esp32s3", "variant": "esp32s3", "partitions": "partitions/esp32_partition_app2944k_fs10M.csv" @@ -19,13 +25,17 @@ "ethernet" ], "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], "openocd_target": "esp32s3.cfg" }, "frameworks": [ "espidf", "arduino" ], - "name": "LilyGo T-SIMCAM ESP32-S3 16M Flash 8MB PSRAM, Tasmota 2944k Code/OTA, 10M FS", + "name": "LilyGo T-SIMCAM ESP32-S3 16M Flash 8MB OPI PSRAM, Tasmota 2944k Code/OTA, 10M FS", "upload": { "flash_size": "16MB", "maximum_ram_size": 327680, diff --git a/platformio_tasmota32.ini b/platformio_tasmota32.ini index cb4b74838..73e0a7271 100644 --- a/platformio_tasmota32.ini +++ b/platformio_tasmota32.ini @@ -40,20 +40,20 @@ extra_scripts = pre:pio-tools/add_c_flags.py ${esp_defaults.extra_scripts} [core32] -platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.4.1/platform-espressif32-2.0.4.1.zip +platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.5/platform-espressif32-2.0.5.zip platform_packages = build_unflags = ${esp32_defaults.build_unflags} build_flags = ${esp32_defaults.build_flags} [core32solo1] -platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.4.1/platform-espressif32-solo1-2.0.4.1.zip +platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.5/platform-espressif32-solo1-2.0.5.zip platform_packages = build_unflags = ${esp32_defaults.build_unflags} build_flags = ${esp32_defaults.build_flags} [core32itead] -platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.4.1/platform-espressif32-ITEAD-2.0.4.1.zip +platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.5/platform-espressif32-ITEAD-2.0.5.zip platform_packages = build_unflags = ${esp32_defaults.build_unflags} build_flags = ${esp32_defaults.build_flags} diff --git a/tasmota/tasmota_support/settings.ino b/tasmota/tasmota_support/settings.ino index eade4dff6..7501fdf82 100644 --- a/tasmota/tasmota_support/settings.ino +++ b/tasmota/tasmota_support/settings.ino @@ -749,7 +749,7 @@ uint32_t CfgTime(void) { void SettingsErase(uint8_t type) { /* For Arduino core and SDK: - Erase only works from flash start address to SDK recognized flash end address (flashchip->chip_size = ESP.getFlashChipSize). + Erase only works from flash start address to SDK recognized flash end address (flashchip->chip_size = ESP_getFlashChipSize). Addresses above SDK recognized size (up to ESP.getFlashChipRealSize) are not accessable. For Esptool: The only way to erase whole flash is esptool which uses direct SPI writes to flash. @@ -779,7 +779,7 @@ void SettingsErase(uint8_t type) { */ EsptoolErase(_sectorStart, FLASH_FS_START); _sectorStart = EEPROM_LOCATION; - _sectorEnd = ESP.getFlashChipSize() / SPI_FLASH_SEC_SIZE; // Flash size as seen by SDK + _sectorEnd = ESP_getFlashChipSize() / SPI_FLASH_SEC_SIZE; // Flash size as seen by SDK } else if (3 == type) { // QPC Reached = QPC and Tasmota and SDK parameter area (0x0F3xxx - 0x0FFFFF) #ifdef USE_UFILESYS diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index 83cfa5ff5..c7fb195d8 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -774,8 +774,11 @@ void CmndStatus(void) ESP_getSketchSize()/1024, ESP_getFreeSketchSpace()/1024, ESP_getFreeHeap1024(), #ifdef ESP32 uxTaskGetStackHighWaterMark(nullptr) / 1024, ESP.getPsramSize()/1024, ESP.getFreePsram()/1024, + ESP_getFlashChipMagicSize()/1024, ESP.getFlashChipSize()/1024 #endif // ESP32 - ESP.getFlashChipSize()/1024, ESP_getFlashChipRealSize()/1024 +#ifdef ESP8266 + ESP_getFlashChipSize()/1024, ESP.getFlashChipRealSize()/1024 +#endif // ESP8266 , ESP_getFlashChipId() , ESP.getFlashChipSpeed()/1000000, ESP_getFlashChipMode().c_str()); ResponseAppendFeatures(); diff --git a/tasmota/tasmota_support/support_esp.ino b/tasmota/tasmota_support/support_esp.ino index 16662dc3d..34a0cd1e7 100644 --- a/tasmota/tasmota_support/support_esp.ino +++ b/tasmota/tasmota_support/support_esp.ino @@ -65,6 +65,10 @@ uint32_t ESP_getFlashChipRealSize(void) { return ESP.getFlashChipRealSize(); } +uint32_t ESP_getFlashChipSize(void) { + return ESP.getFlashChipSize(); +} + void ESP_Restart(void) { // ESP.restart(); // This results in exception 3 on restarts on core 2.3.0 ESP.reset(); @@ -312,17 +316,22 @@ extern "C" { #if ESP_IDF_VERSION_MAJOR > 3 // IDF 4+ #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 #include "esp32/rom/spi_flash.h" + #define ESP_FLASH_IMAGE_BASE 0x1000 // Flash offset containing magic flash size and spi mode #elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 #include "esp32s2/rom/spi_flash.h" + #define ESP_FLASH_IMAGE_BASE 0x1000 // Flash offset containing magic flash size and spi mode #elif CONFIG_IDF_TARGET_ESP32S3 // ESP32-S3 #include "esp32s3/rom/spi_flash.h" + #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32s3 is located at 0x0000 #elif CONFIG_IDF_TARGET_ESP32C3 // ESP32-C3 #include "esp32c3/rom/spi_flash.h" + #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32c3 is located at 0x0000 #else #error Target CONFIG_IDF_TARGET is not supported #endif #else // ESP32 Before IDF 4.0 #include "rom/spi_flash.h" + #define ESP_FLASH_IMAGE_BASE 0x1000 #endif uint32_t EspProgramSize(const char *label) { @@ -520,6 +529,33 @@ uint32_t ESP_getChipId(void) { return id; } +uint32_t ESP_getFlashChipMagicSize(void) +{ + esp_image_header_t fhdr; + if(ESP.flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) { + return 0; + } + return ESP_magicFlashChipSize(fhdr.spi_size); +} + +uint32_t ESP_magicFlashChipSize(uint8_t byte) +{ + switch(byte & 0x0F) { + case 0x0: // 8 MBit (1MB) + return 1048576; + case 0x1: // 16 MBit (2MB) + return 2097152; + case 0x2: // 32 MBit (4MB) + return 4194304; + case 0x3: // 64 MBit (8MB) + return 8388608; + case 0x4: // 128 MBit (16MB) + return 16777216; + default: // fail? + return 0; + } +} + uint32_t ESP_getSketchSize(void) { static uint32_t sketchsize = 0; @@ -558,20 +594,6 @@ int32_t ESP_getHeapFragmentation(void) { return free_maxmem; } -uint32_t ESP_getFlashChipId(void) -{ -// uint32_t id = bootloader_read_flash_id(); - uint32_t id = g_rom_flashchip.device_id; - id = ((id & 0xff) << 16) | ((id >> 16) & 0xff) | (id & 0xff00); - return id; -} - -uint32_t ESP_getFlashChipRealSize(void) -{ - uint32_t id = (ESP_getFlashChipId() >> 16) & 0xFF; - return 2 << (id - 1); -} - void ESP_Restart(void) { ESP.restart(); } @@ -983,30 +1005,7 @@ typedef enum { } FlashMode_t; */ String ESP_getFlashChipMode(void) { -#if ESP8266 uint32_t flash_mode = ESP.getFlashChipMode(); -#else - #if CONFIG_IDF_TARGET_ESP32S2 - const uint32_t spi_ctrl = REG_READ(PERIPHS_SPI_FLASH_CTRL); - #else - const uint32_t spi_ctrl = REG_READ(SPI_CTRL_REG(0)); - #endif - uint32_t flash_mode; - /* Not all of the following constants are already defined in older versions of spi_reg.h, so do it manually for now*/ - if (spi_ctrl & BIT(24)) { //SPI_FREAD_QIO - flash_mode = 0; - } else if (spi_ctrl & BIT(20)) { //SPI_FREAD_QUAD - flash_mode = 1; - } else if (spi_ctrl & BIT(23)) { //SPI_FREAD_DIO - flash_mode = 2; - } else if (spi_ctrl & BIT(14)) { // SPI_FREAD_DUAL - flash_mode = 3; - } else if (spi_ctrl & BIT(13)) { //SPI_FASTRD_MODE - flash_mode = 4; - } else { - flash_mode = 5; - } -#endif if (flash_mode > 5) { flash_mode = 3; } char stemp[6]; return GetTextIndexed(stemp, sizeof(stemp), flash_mode, kFlashModes); @@ -1035,4 +1034,4 @@ uint32_t HwRandom(void) { last_ccount = ccount; return result ^ *(volatile uint32_t *)_RAND_ADDR; #undef _RAND_ADDR -} +} \ No newline at end of file diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino index f85a1660e..60ddf13c0 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino @@ -2445,8 +2445,14 @@ void HandleInformation(void) WSContentSend_P(PSTR("}1}2 ")); // Empty line WSContentSend_P(PSTR("}1" D_ESP_CHIP_ID "}2%d (%s)"), ESP_getChipId(), GetDeviceHardwareRevision().c_str()); WSContentSend_P(PSTR("}1" D_FLASH_CHIP_ID "}20x%06X (%s)"), ESP_getFlashChipId(), ESP_getFlashChipMode().c_str()); - WSContentSend_P(PSTR("}1" D_FLASH_CHIP_SIZE "}2%d KB"), ESP_getFlashChipRealSize() / 1024); - WSContentSend_P(PSTR("}1" D_PROGRAM_FLASH_SIZE "}2%d KB"), ESP.getFlashChipSize() / 1024); +#ifdef ESP32 + WSContentSend_P(PSTR("}1" D_FLASH_CHIP_SIZE "}2%d KB"), ESP.getFlashChipSize() / 1024); + WSContentSend_P(PSTR("}1" D_PROGRAM_FLASH_SIZE "}2%d KB"), ESP_getFlashChipMagicSize() / 1024); +#endif // ESP32 +#ifdef ESP8266 + WSContentSend_P(PSTR("}1" D_FLASH_CHIP_SIZE "}2%d KB"), ESP.getFlashChipRealSize() / 1024); + WSContentSend_P(PSTR("}1" D_PROGRAM_FLASH_SIZE "}2%d KB"), ESP_getFlashChipSize() / 1024); +#endif // ESP8266 WSContentSend_P(PSTR("}1" D_PROGRAM_SIZE "}2%d KB"), ESP_getSketchSize() / 1024); WSContentSend_P(PSTR("}1" D_FREE_PROGRAM_SPACE "}2%d KB"), ESP_getFreeSketchSpace() / 1024); #ifdef ESP32 diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino index 8aa495345..a90a25916 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino @@ -182,8 +182,8 @@ extern "C" { int32_t top = be_top(vm); // Get the number of arguments if (top == 1) { // no argument (instance only) be_newobject(vm, "map"); - be_map_insert_int(vm, "flash", ESP.getFlashChipSize() / 1024); - be_map_insert_int(vm, "flash_real", ESP_getFlashChipRealSize() / 1024); + be_map_insert_int(vm, "flash", ESP_getFlashChipMagicSize() / 1024); + be_map_insert_int(vm, "flash_real", ESP.getFlashChipSize() / 1024); be_map_insert_int(vm, "program", ESP_getSketchSize() / 1024); be_map_insert_int(vm, "program_free", ESP_getFreeSketchSpace() / 1024); be_map_insert_int(vm, "heap_free", ESP_getFreeHeap() / 1024);