From cdb1740d5965752e0f7f6d23a5e1b8d552b83cef Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Sun, 15 Dec 2019 16:11:10 +0100 Subject: [PATCH 1/4] Improve platformio.ini for ESP32 Remove Debug output by default Set monitor speed same as others boards Prepare flag for OTA (commented by default) Prepare flash flag (commented by default) --- platformio.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 4cb7eb7f0d54..b49f9c94ab7d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -694,9 +694,11 @@ monitor_speed = 250000 [env:esp32] platform = espressif32 board = esp32dev +build_flags = ${common.build_flags} -DCORE_DEBUG_LEVEL=0 upload_speed = 115200 -monitor_speed = 115200 -upload_port = /dev/ttyUSB0 +monitor_speed = 250000 +#upload_port = marlinesp.local +#board_build.flash_mode = qio lib_deps = AsyncTCP=https://github.com/me-no-dev/AsyncTCP/archive/master.zip ESPAsyncWebServer=https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip From b4c5c692ce59cd0776926146a02cddae3adf283d Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Sun, 15 Dec 2019 16:11:34 +0100 Subject: [PATCH 2/4] Add esp32 watchdog reset function --- Marlin/src/HAL/HAL_ESP32/watchdog.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Marlin/src/HAL/HAL_ESP32/watchdog.h b/Marlin/src/HAL/HAL_ESP32/watchdog.h index 6647ecefe660..2963f6246b01 100644 --- a/Marlin/src/HAL/HAL_ESP32/watchdog.h +++ b/Marlin/src/HAL/HAL_ESP32/watchdog.h @@ -21,8 +21,16 @@ */ #pragma once +#ifdef __cplusplus +extern "C" { +#endif +esp_err_t esp_task_wdt_reset(); +#ifdef __cplusplus +} +#endif + // Initialize watchdog with a 4 second interrupt time void watchdog_init(); // Reset watchdog. -inline void HAL_watchdog_refresh() {} +inline void HAL_watchdog_refresh() { esp_task_wdt_reset(); } From 51d1a51a0e86f833fcc9ef919144d35f8b45bdbc Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Sun, 15 Dec 2019 16:12:55 +0100 Subject: [PATCH 3/4] Use EEPROM esp32 NVS instead of SPIFFS --- Marlin/src/HAL/HAL_ESP32/HAL.cpp | 4 +- .../HAL/HAL_ESP32/persistent_store_impl.cpp | 65 +++++++++++ .../HAL/HAL_ESP32/persistent_store_spiffs.cpp | 106 ------------------ Marlin/src/HAL/HAL_ESP32/spiffs.cpp | 2 +- 4 files changed, 68 insertions(+), 109 deletions(-) create mode 100644 Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp delete mode 100644 Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp diff --git a/Marlin/src/HAL/HAL_ESP32/HAL.cpp b/Marlin/src/HAL/HAL_ESP32/HAL.cpp index 81567eeede8f..c3e6f096497f 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL.cpp +++ b/Marlin/src/HAL/HAL_ESP32/HAL.cpp @@ -30,7 +30,7 @@ #include "../../inc/MarlinConfigPre.h" -#if EITHER(EEPROM_SETTINGS, WEBSUPPORT) +#if ENABLED(WEBSUPPORT) #include "spiffs.h" #endif @@ -83,7 +83,7 @@ void HAL_init() { } void HAL_init_board() { - #if EITHER(EEPROM_SETTINGS, WEBSUPPORT) + #if ENABLED(WEBSUPPORT) spiffs_init(); #endif diff --git a/Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp new file mode 100644 index 000000000000..34fe9057e413 --- /dev/null +++ b/Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp @@ -0,0 +1,65 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * 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 . + * + */ +#if defined(ARDUINO_ARCH_ESP32) + +#include "../../inc/MarlinConfig.h" + +#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION) + +#include "../shared/persistent_store_api.h" +#include "EEPROM.h" + +#define EEPROM_SIZE 4096 + +bool PersistentStore::access_start() { + return EEPROM.begin(EEPROM_SIZE); +} + +bool PersistentStore::access_finish() { + EEPROM.end(); + return true; +} + +bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { + + for (size_t i = 0; i < size; i++) { + EEPROM.write(pos, value[i]); + crc16(crc, &value[i], 1); + pos++; + } + return false; +} + +bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { + for (size_t i = 0; i < size; i++) { + uint8_t c = EEPROM.read(pos); + if (writing) value[i] = c; + crc16(crc, &c, 1); + pos++; + } + return false; +} + +size_t PersistentStore::capacity() { return EEPROM_SIZE; } + +#endif // EEPROM_SETTINGS +#endif // ARDUINO_ARCH_ESP32 diff --git a/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp b/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp deleted file mode 100644 index 5227da356860..000000000000 --- a/Marlin/src/HAL/HAL_ESP32/persistent_store_spiffs.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * 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 . - * - */ - -#ifdef ARDUINO_ARCH_ESP32 - -#include "../../inc/MarlinConfig.h" - -#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION) - -#include "../shared/persistent_store_api.h" - -#include -#include -#include "spiffs.h" - -#define HAL_ESP32_EEPROM_SIZE 4096 -#define HAL_ESP32_EEPROM_FILE_PATH "/eeprom.dat" - -File eeprom_file; - -bool PersistentStore::access_start() { - if (spiffs_initialized) { - eeprom_file = SPIFFS.open(HAL_ESP32_EEPROM_FILE_PATH, "r+"); - - size_t file_size = eeprom_file.size(); - if (file_size < HAL_ESP32_EEPROM_SIZE) { - SERIAL_ECHO_MSG("SPIFFS EEPROM settings file " HAL_ESP32_EEPROM_FILE_PATH " is too small or did not exist, expanding."); - SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR(" file size: ", file_size, ", required size: ", HAL_ESP32_EEPROM_SIZE); - - // mode r+ does not allow to expand the file (at least on ESP32 SPIFFS9, so we close, reopen "a", append, close, reopen "r+" - eeprom_file.close(); - - eeprom_file = SPIFFS.open(HAL_ESP32_EEPROM_FILE_PATH, "a"); - for (size_t i = eeprom_file.size(); i < HAL_ESP32_EEPROM_SIZE; i++) - eeprom_file.write(0xFF); - eeprom_file.close(); - - eeprom_file = SPIFFS.open(HAL_ESP32_EEPROM_FILE_PATH, "r+"); - file_size = eeprom_file.size(); - if (file_size < HAL_ESP32_EEPROM_SIZE) { - SERIAL_ERROR_MSG("Failed to expand " HAL_ESP32_EEPROM_FILE_PATH " to required size. SPIFFS partition full?"); - SERIAL_ERROR_START(); SERIAL_ECHOLNPAIR(" file size: ", file_size, ", required size: ", HAL_ESP32_EEPROM_SIZE); - SERIAL_ERROR_START(); SERIAL_ECHOLNPAIR(" SPIFFS used bytes: ", SPIFFS.usedBytes(), ", total bytes: ", SPIFFS.totalBytes()); - } - } - return true; - } - return false; -} - -bool PersistentStore::access_finish() { - eeprom_file.close(); - return true; -} - -bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { - if (!eeprom_file.seek(pos)) return true; // return true for any error - if (eeprom_file.write(value, size) != size) return true; - - crc16(crc, value, size); - pos += size; - - return false; -} - -bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { - if (!eeprom_file.seek(pos)) return true; // return true for any error - - if (writing) { - if (eeprom_file.read(value, size) != size) return true; - crc16(crc, value, size); - } - else { - uint8_t tmp[size]; - if (eeprom_file.read(tmp, size) != size) return true; - crc16(crc, tmp, size); - } - - pos += size; - - return false; -} - -size_t PersistentStore::capacity() { return HAL_ESP32_EEPROM_SIZE; } - -#endif // EEPROM_SETTINGS -#endif // ARDUINO_ARCH_ESP32 diff --git a/Marlin/src/HAL/HAL_ESP32/spiffs.cpp b/Marlin/src/HAL/HAL_ESP32/spiffs.cpp index a3e1bd8a255f..1a542580b0f2 100644 --- a/Marlin/src/HAL/HAL_ESP32/spiffs.cpp +++ b/Marlin/src/HAL/HAL_ESP32/spiffs.cpp @@ -24,7 +24,7 @@ #include "../../inc/MarlinConfigPre.h" -#if EITHER(WEBSUPPORT, EEPROM_SETTINGS) +#if ENABLED(WEBSUPPORT) #include "../../core/serial.h" From d4a3e9f1a5523fc9af2b4f29baf378372f2d4329 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 15 Dec 2019 11:28:21 -0600 Subject: [PATCH 4/4] Minor tweaks --- Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp | 12 +++++------- Marlin/src/HAL/HAL_ESP32/watchdog.h | 8 +++++--- platformio.ini | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp index 34fe9057e413..a65a4301a0e9 100644 --- a/Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp +++ b/Marlin/src/HAL/HAL_ESP32/persistent_store_impl.cpp @@ -19,7 +19,8 @@ * along with this program. If not, see . * */ -#if defined(ARDUINO_ARCH_ESP32) + +#ifdef ARDUINO_ARCH_ESP32 #include "../../inc/MarlinConfig.h" @@ -40,21 +41,18 @@ bool PersistentStore::access_finish() { } bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { - for (size_t i = 0; i < size; i++) { - EEPROM.write(pos, value[i]); - crc16(crc, &value[i], 1); - pos++; + EEPROM.write(pos++, value[i]); + crc16(crc, &value[i], 1); } return false; } bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { for (size_t i = 0; i < size; i++) { - uint8_t c = EEPROM.read(pos); + uint8_t c = EEPROM.read(pos++); if (writing) value[i] = c; crc16(crc, &c, 1); - pos++; } return false; } diff --git a/Marlin/src/HAL/HAL_ESP32/watchdog.h b/Marlin/src/HAL/HAL_ESP32/watchdog.h index 2963f6246b01..9fb39ff9a59b 100644 --- a/Marlin/src/HAL/HAL_ESP32/watchdog.h +++ b/Marlin/src/HAL/HAL_ESP32/watchdog.h @@ -22,11 +22,13 @@ #pragma once #ifdef __cplusplus -extern "C" { + extern "C" { #endif -esp_err_t esp_task_wdt_reset(); + + esp_err_t esp_task_wdt_reset(); + #ifdef __cplusplus -} + } #endif // Initialize watchdog with a 4 second interrupt time diff --git a/platformio.ini b/platformio.ini index b49f9c94ab7d..1b42b63f6cf3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -694,16 +694,16 @@ monitor_speed = 250000 [env:esp32] platform = espressif32 board = esp32dev -build_flags = ${common.build_flags} -DCORE_DEBUG_LEVEL=0 -upload_speed = 115200 -monitor_speed = 250000 -#upload_port = marlinesp.local -#board_build.flash_mode = qio +build_flags = ${common.build_flags} -DCORE_DEBUG_LEVEL=0 lib_deps = AsyncTCP=https://github.com/me-no-dev/AsyncTCP/archive/master.zip ESPAsyncWebServer=https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip lib_ignore = LiquidCrystal, LiquidTWI2, SailfishLCD, SailfishRGB_LED src_filter = ${common.default_src_filter} + +upload_speed = 115200 +monitor_speed = 250000 +#upload_port = marlinesp.local +#board_build.flash_mode = qio # # Native