diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 3fc55e625..4f65da5c2 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -40,7 +40,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix #endif // USE_DEVICE_GROUPS D_CMND_SENSOR "|" D_CMND_DRIVER #ifdef ESP32 - "|" D_CMND_TOUCH_CAL "|" D_CMND_TOUCH_THRES "|" D_CMND_TOUCH_NUM "|" D_CMND_CPU_FREQUENCY + "|Info|" D_CMND_TOUCH_CAL "|" D_CMND_TOUCH_THRES "|" D_CMND_TOUCH_NUM "|" D_CMND_CPU_FREQUENCY #endif //ESP32 ; @@ -67,7 +67,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = { #endif // USE_DEVICE_GROUPS &CmndSensor, &CmndDriver #ifdef ESP32 - ,&CmndTouchCal, &CmndTouchThres, &CmndTouchNum, &CmndCpuFrequency + , &CmndInfo, &CmndTouchCal, &CmndTouchThres, &CmndTouchNum, &CmndCpuFrequency #endif //ESP32 }; @@ -2061,6 +2061,11 @@ void CmndDriver(void) #ifdef ESP32 +void CmndInfo(void) { + NvsInfo(); + ResponseCmndDone(); +} + void CmndCpuFrequency(void) { if ((80 == XdrvMailbox.payload) || (160 == XdrvMailbox.payload) || (240 == XdrvMailbox.payload)) { setCpuFrequencyMhz(XdrvMailbox.payload); diff --git a/tasmota/support_esp32.ino b/tasmota/support_esp32.ino index 0a804551c..e84cc06d9 100644 --- a/tasmota/support_esp32.ino +++ b/tasmota/support_esp32.ino @@ -108,25 +108,50 @@ void NvmSave(const char *sNvsName, const char *sName, const void *pSettings, uns interrupts(); } -void NvmErase(const char *sNvsName) { +esp_err_t NvmErase(const char *sNvsName) { nvs_handle handle; noInterrupts(); - nvs_open(sNvsName, NVS_READWRITE, &handle); - nvs_erase_all(handle); - nvs_commit(handle); + esp_err_t result = nvs_open(sNvsName, NVS_READWRITE, &handle); + if (ESP_OK == result) { result = nvs_erase_all(handle); } + if (ESP_OK == result) { result = nvs_commit(handle); } nvs_close(handle); interrupts(); + return result; } void SettingsErase(uint8_t type) { - if (1 == type) { // SDK parameter area - } else if (2 == type) { // Tasmota parameter area (0x0F3xxx - 0x0FBFFF) - } else if (3 == type) { // Tasmota and SDK parameter area (0x0F3xxx - 0x0FFFFF) + // All SDK and Tasmota data is held in default NVS partition + // + + esp_err_t r1, r2, r3; + switch (type) { + case 0: // Reset 2, 5, 6 = Erase all flash from program end to end of physical flash +// nvs_flash_erase(); // Erase RTC, PHY, sta.mac, ap.sndchan, ap.mac, Tasmota etc. + r1 = NvmErase("qpc"); + r2 = NvmErase("main"); +// NvmErase("cal_data"); + AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " Tasmota data (%d,%d)"), r1, r2); + break; + case 1: case 4: // Reset 3 or WIFI_FORCE_RF_CAL_ERASE = SDK parameter area +// r1 = esp_phy_erase_cal_data_in_nvs(); + r1 = NvmErase("cal_data"); + AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " PHY data (%d)"), r1); + break; + case 2: // Not used = QPC and Tasmota parameter area (0x0F3xxx - 0x0FBFFF) + r1 = NvmErase("qpc"); + r2 = NvmErase("main"); + AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " Tasmota data (%d,%d)"), r1, r2); + break; + case 3: // QPC Reached = QPC, Tasmota and SDK parameter area (0x0F3xxx - 0x0FFFFF) +// nvs_flash_erase(); // Erase RTC, PHY, sta.mac, ap.sndchan, ap.mac, Tasmota etc. + r1 = NvmErase("qpc"); + r2 = NvmErase("main"); +// r3 = esp_phy_erase_cal_data_in_nvs(); +// r3 = NvmErase("cal_data"); +// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " Tasmota (%d,%d) and PHY data (%d)"), r1, r2, r3); + AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " Tasmota data (%d,%d)"), r1, r2); + break; } - - NvmErase("main"); - - AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " t=%d"), type); } void SettingsRead(void *data, size_t size) { @@ -157,6 +182,13 @@ void ZigbeeWrite(const void *pSettings, unsigned nSettingsLen) { NvmSave("zb", "zigbee", pSettings, nSettingsLen); } +void NvsInfo(void) { + nvs_stats_t nvs_stats; + nvs_get_stats(NULL, &nvs_stats); + AddLog_P(LOG_LEVEL_INFO, PSTR("INF: NVS Used %d, Free %d, Total %d, Namspaces %d"), + nvs_stats.used_entries, nvs_stats.free_entries, nvs_stats.total_entries, nvs_stats.namespace_count); +} + // // Crash stuff //