From 4ee6aee35e88a5e2aa4225442091036bad82eb62 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 29 Dec 2022 14:46:34 +0100 Subject: [PATCH] Fix ESP8266 relay power on spikes Fix ESP8266 set GPIO's to input on power on fixing relay spikes (#17531) --- CHANGELOG.md | 1 + RELEASENOTES.md | 1 + tasmota/tasmota_support/support_cores.ino | 63 ----------------------- tasmota/tasmota_support/support_esp.ino | 48 +++++++++++++++++ 4 files changed, 50 insertions(+), 63 deletions(-) delete mode 100644 tasmota/tasmota_support/support_cores.ino diff --git a/CHANGELOG.md b/CHANGELOG.md index cf26a7a3a..755e1e9b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file. - Shutter default motorstop set to 0 (#17403) - Shutter default tilt configuration (#17484) - Modbus transmit enable GPIO enabled once during write buffer +- ESP8266 set GPIO's to input on power on fixing relay spikes (#17531) ### Removed diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 510405625..341ef87c1 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -127,6 +127,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm ### Fixed - Modbus transmit enable GPIO enabled once during write buffer +- ESP8266 set GPIO's to input on power on fixing relay spikes [#17531](https://github.com/arendst/Tasmota/issues/17531) - Shutter default motorstop set to 0 [#17403](https://github.com/arendst/Tasmota/issues/17403) - Shutter default tilt configuration [#17484](https://github.com/arendst/Tasmota/issues/17484) diff --git a/tasmota/tasmota_support/support_cores.ino b/tasmota/tasmota_support/support_cores.ino deleted file mode 100644 index 547b776dc..000000000 --- a/tasmota/tasmota_support/support_cores.ino +++ /dev/null @@ -1,63 +0,0 @@ -/* - support_cores.ino - Arduino core support for Tasmota - - Copyright (C) 2021 Theo Arends - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/*********************************************************************************************\ - * Core overrides -\*********************************************************************************************/ - -// Add below line to tasmota_globals.h -// extern "C" void resetPins(); -void resetPins() -{ -/* - for (int i = 0; i <= 5; ++i) { - pinMode(i, INPUT); - } - // pins 6-11 are used for the SPI flash interface - for (int i = 12; i <= 16; ++i) { - pinMode(i, INPUT); - } -*/ -} - -/*********************************************************************************************\ - * Hardware related -\*********************************************************************************************/ - -#ifdef ESP8266 - -void HwWdtDisable(void) { - *((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF -} - -void HwWdtEnable(void) { - *((volatile uint32_t*) 0x60000900) |= 1; // Hardware WDT ON -} - -void WdtDisable(void) { - ESP.wdtDisable(); - HwWdtDisable(); -} - -void WdtEnable(void) { - HwWdtEnable(); - ESP.wdtEnable(0); -} - -#endif // ESP8266 diff --git a/tasmota/tasmota_support/support_esp.ino b/tasmota/tasmota_support/support_esp.ino index 935733baf..b272e852b 100644 --- a/tasmota/tasmota_support/support_esp.ino +++ b/tasmota/tasmota_support/support_esp.ino @@ -33,6 +33,54 @@ extern "C" { extern struct rst_info resetInfo; } +/*********************************************************************************************\ + * Core overrides executed directly by core +\*********************************************************************************************/ + +// Add below line to tasmota_globals.h +// extern "C" void resetPins(); +// This function is executed by core init() (as initPins()) in core_esp8266_wiring.cpp +// 20221229 - Re-enabled with additional check to execute on power on only fixing short relay power on/off +// 20?????? - Disabled for unknown reason +void resetPins() { + if ((resetInfo.reason == REASON_DEFAULT_RST) || (resetInfo.reason == REASON_EXT_SYS_RST)) { + // Only perform at power on + for (int i = 0; i <= 5; ++i) { + pinMode(i, INPUT); + } + // pins 6-11 are used for the SPI flash interface + for (int i = 12; i <= 16; ++i) { + pinMode(i, INPUT); + } + } +} + +/*********************************************************************************************\ + * Hardware related +\*********************************************************************************************/ + +void HwWdtDisable(void) { + *((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF +} + +void HwWdtEnable(void) { + *((volatile uint32_t*) 0x60000900) |= 1; // Hardware WDT ON +} + +void WdtDisable(void) { + ESP.wdtDisable(); + HwWdtDisable(); +} + +void WdtEnable(void) { + HwWdtEnable(); + ESP.wdtEnable(0); +} + +/*********************************************************************************************\ + * ESP8266 specifics +\*********************************************************************************************/ + uint32_t ESP_ResetInfoReason(void) { return resetInfo.reason; }