/* FirstBoot - platform initialization and context switching emulation Copyright (c) 2019 jj Noui. All rights reserved. This file is part of the esp8266 core for Arduino environment. This source is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This source 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ********************************************************************************** * * The first boot after downloading programm take above 5s. * Next boot takes under 0.3s. * * So when we are at first boot, we can force programmatly a hard reset. * * * To do this : * * * choose your forceResetPin ( but dont use a reserved pin ;) ). * HARDWARE * * connect the 'forceResetPin' to RST pin. * * * * SOFTWARE * * (*) define the 'forceResetPin' (for ex : #define forceResetPin D7). * * * at the begining of setup() (RESPECT THE SEQUENCE TO AVOID AN IMMEDIATE RESET) * (**) - set the 'forceResetPin' to HIGH, * (***) - configure the 'forceResetPin' to output mode. * * Then, a little further : * (****)if this is the first boot, force reset by pulling down the 'forceResetPin' to LOW. * */ #include extern "C" { #include "user_interface.h" } #define wdtBugSolved void setup() { #ifdef wdtBugSolved #define forceResetPin D7 /* (*) */ bool isFirstBoot; isFirstBoot = system_get_time() > 1000000 ? true : false; // time is in µs digitalWrite(forceResetPin, HIGH); /* (**) */ pinMode(forceResetPin, OUTPUT); /* (***) */ #endif Serial.begin(74880); delay(50); #ifdef wdtBugSolved Serial.println("\n\n\n"); if (isFirstBoot) { digitalWrite(forceResetPin, LOW); /* (****) */ delay(1000); } else { Serial.println(F("\n\n\n *********** now wdt will work")); } #endif } void loop() { while(1); }