diff --git a/platformio.ini b/platformio.ini index 5ed2082..d2c63d7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,6 +12,6 @@ platform = espressif32 board = wt32-eth01 framework = arduino -lib_deps = siwats/ESPMegaProR3@^2.0.7 +lib_deps = siwats/ESPMegaPROR3@^2.0.7 monitor_speed = 115200 ;build_flags = -DCORE_DEBUG_LEVEL=5 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 738ea80..76bad62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,6 +89,13 @@ void sendExtStopBytes() void setup() { + gpio_config_t gpio_2_conf; + gpio_2_conf.intr_type = GPIO_INTR_DISABLE; + gpio_2_conf.mode = GPIO_MODE_INPUT; + gpio_2_conf.pull_up_en = GPIO_PULLUP_ENABLE; + gpio_config(&gpio_2_conf); + // If GPIO 2 is pulled low, clear the FRAM then reboot (Reset the device to factory defaults) + bool clear_fram = !gpio_get_level(GPIO_NUM_2); Serial.begin(115200); cudDisplayAdapter.begin(CUD_DISPLAY_BAUD_RATE, SERIAL_8N1, CUD_DISPLAY_RX_PIN, CUD_DISPLAY_TX_PIN); sendExtStopBytes(); @@ -100,6 +107,16 @@ void setup() Serial.print("boot_state.txt=\"Core Initializing . . .\""); sendStopBytes(); espmega.begin(); + if (clear_fram) + { + Serial.print("boot_state.txt=\"Factory Resetting . . .\""); + sendStopBytes(); + for (uint16_t i = 0; i < 32768; i++) + { + espmega.fram.write8(i, 0); + } + esp_restart(); + } Serial.print("boot_state.txt=\"IoT Initializing . . .\""); sendStopBytes(); espmega.enableIotModule();