diff --git a/Marlin/src/HAL/AVR/eeprom.cpp b/Marlin/src/HAL/AVR/eeprom.cpp index ee416b7a12..e946668054 100644 --- a/Marlin/src/HAL/AVR/eeprom.cpp +++ b/Marlin/src/HAL/AVR/eeprom.cpp @@ -27,7 +27,8 @@ #include "../shared/eeprom_api.h" -bool PersistentStore::access_start() { return true; } +size_t PersistentStore::capacity() { return E2END + 1; } +bool PersistentStore::access_start() { return true; } bool PersistentStore::access_finish() { return true; } bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { @@ -61,7 +62,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; // always assume success for AVR's } -size_t PersistentStore::capacity() { return E2END + 1; } - #endif // EEPROM_SETTINGS || SD_FIRMWARE_UPDATE #endif // __AVR__ diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 42f6f175fb..0624c5b401 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -30,6 +30,7 @@ #define CPU_32_BIT #include "../shared/Marduino.h" +#include "../shared/eeprom_if.h" #include "../shared/math_32bit.h" #include "../shared/HAL_SPI.h" #include "fastio.h" @@ -130,14 +131,6 @@ void sei(); // Enable interrupts void HAL_clear_reset_source(); // clear reset reason uint8_t HAL_get_reset_source(); // get reset reason -// -// EEPROM -// -void eeprom_write_byte(uint8_t *pos, unsigned char value); -uint8_t eeprom_read_byte(uint8_t *pos); -void eeprom_read_block (void *__dst, const void *__src, size_t __n); -void eeprom_update_block (const void *__src, void *__dst, size_t __n); - // // ADC // diff --git a/Marlin/src/HAL/DUE/eeprom.cpp b/Marlin/src/HAL/DUE/eeprom_flash.cpp similarity index 87% rename from Marlin/src/HAL/DUE/eeprom.cpp rename to Marlin/src/HAL/DUE/eeprom_flash.cpp index ec9ef51ffc..7076dd03db 100644 --- a/Marlin/src/HAL/DUE/eeprom.cpp +++ b/Marlin/src/HAL/DUE/eeprom_flash.cpp @@ -22,25 +22,26 @@ */ #ifdef ARDUINO_ARCH_SAM -#include "../../inc/MarlinConfigPre.h" +#include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) +#if ENABLED(FLASH_EEPROM_EMULATION) #include "../../inc/MarlinConfig.h" + +#include "../shared/eeprom_if.h" #include "../shared/eeprom_api.h" -#if !defined(E2END) && ENABLED(FLASH_EEPROM_EMULATION) +#if !defined(E2END) #define E2END 0xFFF // Default to Flash emulated EEPROM size (EepromEmulation_Due.cpp) #endif extern void eeprom_flush(); -bool PersistentStore::access_start() { return true; } +size_t PersistentStore::capacity() { return E2END + 1; } +bool PersistentStore::access_start() { return true; } bool PersistentStore::access_finish() { - #if ENABLED(FLASH_EEPROM_EMULATION) - eeprom_flush(); - #endif + eeprom_flush(); return true; } @@ -76,7 +77,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -size_t PersistentStore::capacity() { return E2END + 1; } - #endif // EEPROM_SETTINGS #endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/DUE/EepromEmulation.cpp b/Marlin/src/HAL/DUE/eeprom_if_flash.cpp similarity index 99% rename from Marlin/src/HAL/DUE/EepromEmulation.cpp rename to Marlin/src/HAL/DUE/eeprom_if_flash.cpp index 8be9affa68..8464ed62bb 100644 --- a/Marlin/src/HAL/DUE/EepromEmulation.cpp +++ b/Marlin/src/HAL/DUE/eeprom_if_flash.cpp @@ -57,6 +57,7 @@ #if ENABLED(FLASH_EEPROM_EMULATION) #include "../shared/Marduino.h" +#include "../shared/eeprom_if.h" #include "../shared/eeprom_api.h" #define EEPROMSize 4096 diff --git a/Marlin/src/HAL/DUE/eeprom_wired.cpp b/Marlin/src/HAL/DUE/eeprom_wired.cpp new file mode 100644 index 0000000000..429d8df374 --- /dev/null +++ b/Marlin/src/HAL/DUE/eeprom_wired.cpp @@ -0,0 +1,69 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com + * + * 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_SAM + +#include "../../inc/MarlinConfig.h" + +#if USE_WIRED_EEPROM + +#include "../shared/eeprom_if.h" +#include "../shared/eeprom_api.h" + +size_t PersistentStore::capacity() { return E2END + 1; } +bool PersistentStore::access_start() { return true; } +bool PersistentStore::access_finish() { return true; } + +bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { + while (size--) { + uint8_t * const p = (uint8_t * const)pos; + uint8_t v = *value; + // EEPROM has only ~100,000 write cycles, + // so only write bytes that have changed! + if (v != eeprom_read_byte(p)) { + eeprom_write_byte(p, v); + delay(2); + if (eeprom_read_byte(p) != v) { + SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); + return true; + } + } + crc16(crc, &v, 1); + pos++; + value++; + }; + return false; +} + +bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { + do { + uint8_t c = eeprom_read_byte((uint8_t*)pos); + if (writing) *value = c; + crc16(crc, &c, 1); + pos++; + value++; + } while (--size); + return false; +} + +#endif // USE_WIRED_EEPROM +#endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/DUE/inc/Conditionals_post.h b/Marlin/src/HAL/DUE/inc/Conditionals_post.h index 8a305009ce..9b76c25102 100644 --- a/Marlin/src/HAL/DUE/inc/Conditionals_post.h +++ b/Marlin/src/HAL/DUE/inc/Conditionals_post.h @@ -22,7 +22,7 @@ #pragma once #if USE_FALLBACK_EEPROM - #undef SRAM_EEPROM_EMULATION - #undef SDCARD_EEPROM_EMULATION #define FLASH_EEPROM_EMULATION +#elif EITHER(I2C_EEPROM, SPI_EEPROM) + #define USE_SHARED_EEPROM 1 #endif diff --git a/Marlin/src/HAL/ESP32/HAL.h b/Marlin/src/HAL/ESP32/HAL.h index a04343b69e..4b1ccbf20f 100644 --- a/Marlin/src/HAL/ESP32/HAL.h +++ b/Marlin/src/HAL/ESP32/HAL.h @@ -109,12 +109,6 @@ int freeMemory(); void analogWrite(pin_t pin, int value); -// EEPROM -void eeprom_write_byte(uint8_t *pos, unsigned char value); -uint8_t eeprom_read_byte(uint8_t *pos); -void eeprom_read_block (void *__dst, const void *__src, size_t __n); -void eeprom_update_block (const void *__src, void *__dst, size_t __n); - // ADC #define HAL_ANALOG_SELECT(pin) diff --git a/Marlin/src/HAL/ESP32/eeprom.cpp b/Marlin/src/HAL/ESP32/eeprom.cpp index 8b75dc51e8..35cebb592f 100644 --- a/Marlin/src/HAL/ESP32/eeprom.cpp +++ b/Marlin/src/HAL/ESP32/eeprom.cpp @@ -23,7 +23,7 @@ #include "../../inc/MarlinConfig.h" -#if USE_WIRED_EEPROM +#if ENABLED(EEPROM_SETTINGS) #include "../shared/eeprom_api.h" #include @@ -58,5 +58,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t size_t PersistentStore::capacity() { return EEPROM_SIZE; } -#endif // USE_WIRED_EEPROM +#endif // EEPROM_SETTINGS #endif // ARDUINO_ARCH_ESP32 diff --git a/Marlin/src/HAL/ESP32/inc/Conditionals_post.h b/Marlin/src/HAL/ESP32/inc/Conditionals_post.h index 8849c06e93..0285c52ee3 100644 --- a/Marlin/src/HAL/ESP32/inc/Conditionals_post.h +++ b/Marlin/src/HAL/ESP32/inc/Conditionals_post.h @@ -20,8 +20,3 @@ * */ #pragma once - -#undef USE_WIRED_EEPROM -#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION) - #define USE_WIRED_EEPROM 1 -#endif diff --git a/Marlin/src/HAL/LINUX/arduino.cpp b/Marlin/src/HAL/LINUX/arduino.cpp index d9fa84ac7c..122a1a4a18 100644 --- a/Marlin/src/HAL/LINUX/arduino.cpp +++ b/Marlin/src/HAL/LINUX/arduino.cpp @@ -75,20 +75,6 @@ uint16_t analogRead(pin_t adc_pin) { return Gpio::get(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin)); } -// ************************** -// Persistent Config Storage -// ************************** - -void eeprom_write_byte(unsigned char *pos, unsigned char value) { - -} - -unsigned char eeprom_read_byte(uint8_t * pos) { return '\0'; } - -void eeprom_read_block(void *__dst, const void *__src, size_t __n) { } - -void eeprom_update_block(const void *__src, void *__dst, size_t __n) { } - char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s) { char format_string[20]; snprintf(format_string, 20, "%%%d.%df", __width, __prec); diff --git a/Marlin/src/HAL/LINUX/include/Arduino.h b/Marlin/src/HAL/LINUX/include/Arduino.h index 55bf0f95ee..928f551fb4 100644 --- a/Marlin/src/HAL/LINUX/include/Arduino.h +++ b/Marlin/src/HAL/LINUX/include/Arduino.h @@ -106,12 +106,6 @@ bool digitalRead(pin_t); void analogWrite(pin_t, int); uint16_t analogRead(pin_t); -// EEPROM -void eeprom_write_byte(unsigned char *pos, unsigned char value); -unsigned char eeprom_read_byte(unsigned char *pos); -void eeprom_read_block(void *__dst, const void *__src, size_t __n); -void eeprom_update_block(const void *__src, void *__dst, size_t __n); - int32_t random(int32_t); int32_t random(int32_t, int32_t); void randomSeed(uint32_t); diff --git a/Marlin/src/HAL/LPC1768/eeprom_flash.cpp b/Marlin/src/HAL/LPC1768/eeprom_flash.cpp index ea4ef7c66c..3bcda68adb 100644 --- a/Marlin/src/HAL/LPC1768/eeprom_flash.cpp +++ b/Marlin/src/HAL/LPC1768/eeprom_flash.cpp @@ -58,6 +58,8 @@ static uint8_t ram_eeprom[EEPROM_SIZE] __attribute__((aligned(4))) = {0}; static bool eeprom_dirty = false; static int current_slot = 0; +size_t PersistentStore::capacity() { return EEPROM_SIZE; } + bool PersistentStore::access_start() { uint32_t first_nblank_loc, first_nblank_val; IAP_STATUS_CODE status; @@ -122,7 +124,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; // return true for any error } -size_t PersistentStore::capacity() { return EEPROM_SIZE; } - #endif // FLASH_EEPROM_EMULATION #endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp b/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp index ce76a5a439..aac41ab307 100644 --- a/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp +++ b/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp @@ -38,6 +38,8 @@ FATFS fat_fs; FIL eeprom_file; bool eeprom_file_open = false; +size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM + bool PersistentStore::access_start() { const char eeprom_erase_value = 0xFF; MSC_Aquire_Lock(); @@ -168,7 +170,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin return bytes_read != size; // return true for any error } -size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM - #endif // SDCARD_EEPROM_EMULATION #endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/LPC1768/eeprom_wired.cpp b/Marlin/src/HAL/LPC1768/eeprom_wired.cpp index 3395601a24..f5db53434d 100644 --- a/Marlin/src/HAL/LPC1768/eeprom_wired.cpp +++ b/Marlin/src/HAL/LPC1768/eeprom_wired.cpp @@ -19,19 +19,14 @@ * along with this program. If not, see . * */ - -/** - * I2C/SPI EEPROM interface for LPC1768 - */ - #ifdef TARGET_LPC1768 #include "../../inc/MarlinConfig.h" #if USE_WIRED_EEPROM +#include "../shared/eeprom_if.h" #include "../shared/eeprom_api.h" -#include #ifndef EEPROM_SIZE #define EEPROM_SIZE 0x8000 // 32kB‬ diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h index 25c3b79cd1..24ff12cf19 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h @@ -21,8 +21,6 @@ */ #pragma once -#undef I2C_EEPROM // Arduino framework provides code for I2C - #if USE_FALLBACK_EEPROM #define FLASH_EEPROM_EMULATION #endif diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index f2ee02a22f..322489e193 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -113,12 +113,6 @@ typedef int8_t pin_t; void HAL_clear_reset_source(); // clear reset reason uint8_t HAL_get_reset_source(); // get reset reason -// -// EEPROM -// -void eeprom_write_byte(uint8_t *pos, unsigned char value); -uint8_t eeprom_read_byte(uint8_t *pos); - // // ADC // diff --git a/Marlin/src/HAL/SAMD51/eeprom.cpp b/Marlin/src/HAL/SAMD51/eeprom_wired.cpp similarity index 87% rename from Marlin/src/HAL/SAMD51/eeprom.cpp rename to Marlin/src/HAL/SAMD51/eeprom_wired.cpp index e167515bff..9dc83f37e6 100644 --- a/Marlin/src/HAL/SAMD51/eeprom.cpp +++ b/Marlin/src/HAL/SAMD51/eeprom_wired.cpp @@ -18,18 +18,17 @@ * along with this program. If not, see . * */ - #ifdef __SAMD51__ #include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) && NONE(QSPI_EEPROM, FLASH_EEPROM_EMULATION) +#if USE_WIRED_EEPROM +#include "../shared/eeprom_if.h" #include "../shared/eeprom_api.h" -size_t PersistentStore::capacity() { return E2END + 1; } - -bool PersistentStore::access_start() { return true; } +size_t PersistentStore::capacity() { return E2END + 1; } +bool PersistentStore::access_start() { return true; } bool PersistentStore::access_finish() { return true; } bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { @@ -62,5 +61,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -#endif // EEPROM_SETTINGS && !(QSPI_EEPROM || FLASH_EEPROM_EMULATION) +#endif // USE_WIRED_EEPROM #endif // __SAMD51__ diff --git a/Marlin/src/HAL/SAMD51/inc/Conditionals_post.h b/Marlin/src/HAL/SAMD51/inc/Conditionals_post.h index 24ff12cf19..9b76c25102 100644 --- a/Marlin/src/HAL/SAMD51/inc/Conditionals_post.h +++ b/Marlin/src/HAL/SAMD51/inc/Conditionals_post.h @@ -23,4 +23,6 @@ #if USE_FALLBACK_EEPROM #define FLASH_EEPROM_EMULATION +#elif EITHER(I2C_EEPROM, SPI_EEPROM) + #define USE_SHARED_EEPROM 1 #endif diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index c310cca74e..4c64d95153 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -191,16 +191,6 @@ static inline int freeMemory() { #pragma GCC diagnostic pop -// -// EEPROM -// - -// Wire library should work for i2c EEPROMs -void eeprom_write_byte(uint8_t *pos, unsigned char value); -uint8_t eeprom_read_byte(uint8_t *pos); -void eeprom_read_block(void *__dst, const void *__src, size_t __n); -void eeprom_update_block(const void *__src, void *__dst, size_t __n); - // // ADC // diff --git a/Marlin/src/HAL/STM32/eeprom_flash.cpp b/Marlin/src/HAL/STM32/eeprom_flash.cpp index 765e847420..49862957e8 100644 --- a/Marlin/src/HAL/STM32/eeprom_flash.cpp +++ b/Marlin/src/HAL/STM32/eeprom_flash.cpp @@ -24,7 +24,7 @@ #include "../../inc/MarlinConfig.h" -#if BOTH(EEPROM_SETTINGS, FLASH_EEPROM_EMULATION) +#if ENABLED(FLASH_EEPROM_EMULATION) #include "../shared/eeprom_api.h" @@ -235,13 +235,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { do { - const uint8_t c = ( - #if ENABLED(FLASH_EEPROM_LEVELING) - ram_eeprom[pos] - #else - eeprom_buffered_read_byte(pos) - #endif - ); + const uint8_t c = TERN(FLASH_EEPROM_LEVELING, ram_eeprom[pos], eeprom_buffered_read_byte(pos)); if (writing) *value = c; crc16(crc, &c, 1); pos++; @@ -251,14 +245,8 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t } size_t PersistentStore::capacity() { - return ( - #if ENABLED(FLASH_EEPROM_LEVELING) - EEPROM_SIZE - #else - E2END + 1 - #endif - ); + return TERN(FLASH_EEPROM_LEVELING, EEPROM_SIZE, E2END + 1); } -#endif // EEPROM_SETTINGS && FLASH_EEPROM_EMULATION +#endif // FLASH_EEPROM_EMULATION #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC diff --git a/Marlin/src/HAL/STM32/eeprom_sram.cpp b/Marlin/src/HAL/STM32/eeprom_sram.cpp new file mode 100644 index 0000000000..0993dee33d --- /dev/null +++ b/Marlin/src/HAL/STM32/eeprom_sram.cpp @@ -0,0 +1,64 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com + * + * 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_STM32) && !defined(STM32GENERIC) + +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SRAM_EEPROM_EMULATION) + +#include "../shared/eeprom_if.h" +#include "../shared/eeprom_api.h" + +size_t PersistentStore::capacity() { return 4096; } // 4K of SRAM +bool PersistentStore::access_start() { return true; } +bool PersistentStore::access_finish() { return true; } + +bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { + while (size--) { + uint8_t v = *value; + + // Save to Backup SRAM + *(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v; + + crc16(crc, &v, 1); + pos++; + value++; + }; + + return false; +} + +bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { + do { + // Read from either external EEPROM, program flash or Backup SRAM + const uint8_t c = ( *(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)) ); + if (writing) *value = c; + crc16(crc, &c, 1); + pos++; + value++; + } while (--size); + return false; +} + +#endif // SRAM_EEPROM_EMULATION +#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC diff --git a/Marlin/src/HAL/STM32/eeprom_wired.cpp b/Marlin/src/HAL/STM32/eeprom_wired.cpp index b83a2eb2bb..465cf44a25 100644 --- a/Marlin/src/HAL/STM32/eeprom_wired.cpp +++ b/Marlin/src/HAL/STM32/eeprom_wired.cpp @@ -24,10 +24,13 @@ #include "../../inc/MarlinConfig.h" -#if EITHER(USE_WIRED_EEPROM, SRAM_EEPROM_EMULATION) +#if USE_WIRED_EEPROM + +#include "../shared/eeprom_if.h" #include "../shared/eeprom_api.h" +size_t PersistentStore::capacity() { return E2END + 1; } bool PersistentStore::access_start() { return true; } bool PersistentStore::access_finish() { return true; } @@ -35,21 +38,16 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui while (size--) { uint8_t v = *value; - // Save to either external EEPROM, program flash or Backup SRAM - #if USE_WIRED_EEPROM - // EEPROM has only ~100,000 write cycles, - // so only write bytes that have changed! - uint8_t * const p = (uint8_t * const)pos; - if (v != eeprom_read_byte(p)) { - eeprom_write_byte(p, v); - if (eeprom_read_byte(p) != v) { - SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); - return true; - } + // EEPROM has only ~100,000 write cycles, + // so only write bytes that have changed! + uint8_t * const p = (uint8_t * const)pos; + if (v != eeprom_read_byte(p)) { + eeprom_write_byte(p, v); + if (eeprom_read_byte(p) != v) { + SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); + return true; } - #else - *(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v; - #endif + } crc16(crc, &v, 1); pos++; @@ -62,14 +60,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { do { // Read from either external EEPROM, program flash or Backup SRAM - const uint8_t c = ( - #if USE_WIRED_EEPROM - eeprom_read_byte((uint8_t*)pos) - #else - (*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos))) - #endif - ); - + const uint8_t c = eeprom_read_byte((uint8_t*)pos); if (writing) *value = c; crc16(crc, &c, 1); pos++; @@ -78,9 +69,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -size_t PersistentStore::capacity() { - return TERN(USE_WIRED_EEPROM, E2END + 1, 4096); // 4K for emulated -} - -#endif // USE_WIRED_EEPROM || SRAM_EEPROM_EMULATION +#endif // USE_WIRED_EEPROM #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC diff --git a/Marlin/src/HAL/STM32/inc/Conditionals_post.h b/Marlin/src/HAL/STM32/inc/Conditionals_post.h index 27e814a0a6..efe4d72a6f 100644 --- a/Marlin/src/HAL/STM32/inc/Conditionals_post.h +++ b/Marlin/src/HAL/STM32/inc/Conditionals_post.h @@ -24,4 +24,6 @@ // If no real or emulated EEPROM selected, fall back to SD emulation #if USE_FALLBACK_EEPROM #define SDCARD_EEPROM_EMULATION +#elif EITHER(I2C_EEPROM, SPI_EEPROM) + #define USE_SHARED_EEPROM 1 #endif diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 629e455871..c69d62e125 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -248,19 +248,6 @@ static int freeMemory() { #pragma GCC diagnostic pop -// -// EEPROM -// - -/** - * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort. - * Wire library should work for i2c EEPROMs. - */ -void eeprom_write_byte(uint8_t *pos, unsigned char value); -uint8_t eeprom_read_byte(uint8_t *pos); -void eeprom_read_block(void *__dst, const void *__src, size_t __n); -void eeprom_update_block(const void *__src, void *__dst, size_t __n); - // // ADC // diff --git a/Marlin/src/HAL/STM32F1/eeprom_wired.cpp b/Marlin/src/HAL/STM32F1/eeprom_wired.cpp index 8527f175a6..e53e9d8674 100644 --- a/Marlin/src/HAL/STM32F1/eeprom_wired.cpp +++ b/Marlin/src/HAL/STM32F1/eeprom_wired.cpp @@ -23,8 +23,11 @@ #if USE_WIRED_EEPROM +#include "../shared/eeprom_if.h" #include "../shared/eeprom_api.h" +size_t PersistentStore::capacity() { return E2END + 1; } + bool PersistentStore::access_start() { #if ENABLED(SPI_EEPROM) #if SPI_CHAN_EEPROM1 == 1 @@ -70,7 +73,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -size_t PersistentStore::capacity() { return E2END + 1; } - #endif // USE_WIRED_EEPROM #endif // __STM32F1__ diff --git a/Marlin/src/HAL/STM32F1/inc/Conditionals_post.h b/Marlin/src/HAL/STM32F1/inc/Conditionals_post.h index 32ad3a57b9..be011af35e 100644 --- a/Marlin/src/HAL/STM32F1/inc/Conditionals_post.h +++ b/Marlin/src/HAL/STM32F1/inc/Conditionals_post.h @@ -24,4 +24,6 @@ // If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation #if USE_FALLBACK_EEPROM #define SDCARD_EEPROM_EMULATION +#elif EITHER(I2C_EEPROM, SPI_EEPROM) + #define USE_SHARED_EEPROM 1 #endif diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.h b/Marlin/src/HAL/STM32_F4_F7/HAL.h index b5d8ac29cf..37bb5552ab 100644 --- a/Marlin/src/HAL/STM32_F4_F7/HAL.h +++ b/Marlin/src/HAL/STM32_F4_F7/HAL.h @@ -51,6 +51,8 @@ #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." #elif SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB +#elif SERIAL_PORT == 0 + #define MYSERIAL0 Serial1 #elif SERIAL_PORT == 1 #define MYSERIAL0 SerialUART1 #elif SERIAL_PORT == 2 @@ -74,6 +76,8 @@ #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #elif SERIAL_PORT_2 == -1 #define MYSERIAL1 SerialUSB + #elif SERIAL_PORT_2 == 0 + #define MYSERIAL1 Serial1 #elif SERIAL_PORT_2 == 1 #define MYSERIAL1 SerialUART1 #elif SERIAL_PORT_2 == 2 @@ -103,6 +107,8 @@ #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #elif DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL SerialUSB + #elif DGUS_SERIAL_PORT == 0 + #define DGUS_SERIAL Serial1 #elif DGUS_SERIAL_PORT == 1 #define DGUS_SERIAL SerialUART1 #elif DGUS_SERIAL_PORT == 2 @@ -206,19 +212,6 @@ static inline int freeMemory() { #pragma GCC diagnostic pop -// -// EEPROM -// - -/** - * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort. - * Wire library should work for i2c EEPROMs. - */ -void eeprom_write_byte(uint8_t *pos, unsigned char value); -uint8_t eeprom_read_byte(uint8_t *pos); -void eeprom_read_block (void *__dst, const void *__src, size_t __n); -void eeprom_update_block (const void *__src, void *__dst, size_t __n); - // // ADC // diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp b/Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp index deb14f2cfe..673ab3372b 100644 --- a/Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp +++ b/Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp @@ -20,6 +20,7 @@ * along with this program. If not, see . * */ +#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7)) /** * Software SPI functions originally from Arduino Sd2Card Library @@ -30,8 +31,6 @@ * Adapted to the Marlin STM32F4/7 HAL */ -#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7)) - #include "../../inc/MarlinConfig.h" #include @@ -121,7 +120,7 @@ uint8_t spiRec() { */ void spiRead(uint8_t* buf, uint16_t nbyte) { SPI.beginTransaction(spiConfig); - #ifdef STM32GENERIC + #ifndef STM32GENERIC SPI.dmaTransfer(0, const_cast(buf), nbyte); #else SPI.transfer((uint8_t*)buf, nbyte); @@ -153,7 +152,7 @@ void spiSend(uint8_t b) { void spiSendBlock(uint8_t token, const uint8_t* buf) { SPI.beginTransaction(spiConfig); SPI.transfer(token); - #ifdef STM32GENERIC + #ifndef STM32GENERIC SPI.dmaSend(const_cast(buf), 512); #else SPI.transfer((uint8_t*)buf, nullptr, 512); diff --git a/Marlin/src/HAL/STM32_F4_F7/eeprom.cpp b/Marlin/src/HAL/STM32_F4_F7/eeprom.cpp index 0b0aa4475e..370d2885ae 100644 --- a/Marlin/src/HAL/STM32_F4_F7/eeprom.cpp +++ b/Marlin/src/HAL/STM32_F4_F7/eeprom.cpp @@ -22,13 +22,15 @@ */ #if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7)) -#include "../../inc/MarlinConfigPre.h" +#include "../../inc/MarlinConfig.h" #if ENABLED(EEPROM_SETTINGS) +#include "../shared/eeprom_if.h" #include "../shared/eeprom_api.h" -bool PersistentStore::access_start() { return true; } +size_t PersistentStore::capacity() { return E2END + 1; } +bool PersistentStore::access_start() { return true; } bool PersistentStore::access_finish() { return true; } bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { @@ -62,7 +64,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -size_t PersistentStore::capacity() { return E2END + 1; } - #endif // EEPROM_SETTINGS #endif // STM32GENERIC && (STM32F4 || STM32F7) diff --git a/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.cpp b/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.cpp index 3358fa3df7..cb4811d2aa 100644 --- a/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.cpp +++ b/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.cpp @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file EEPROM/EEPROM_Emulation/src/eeprom.c + * @file eeprom_emul.cpp * @author MCD Application Team * @version V1.2.6 * @date 04-November-2016 @@ -49,6 +49,10 @@ */ #if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7)) +#include "../../inc/MarlinConfigPre.h" + +#if ENABLED(FLASH_EEPROM_EMULATION) + /* Includes ------------------------------------------------------------------*/ #include "eeprom_emul.h" @@ -518,6 +522,7 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) { return HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, VALID_PAGE); } +#endif // FLASH_EEPROM_EMULATION #endif // STM32GENERIC && (STM32F4 || STM32F7) /** diff --git a/Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp b/Marlin/src/HAL/STM32_F4_F7/eeprom_if_flash.cpp similarity index 97% rename from Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp rename to Marlin/src/HAL/STM32_F4_F7/eeprom_if_flash.cpp index 3249ef2b7c..86b80f2b8b 100644 --- a/Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp +++ b/Marlin/src/HAL/STM32_F4_F7/eeprom_if_flash.cpp @@ -16,12 +16,10 @@ * along with this program. If not, see . * */ - #if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7)) /** - * Description: Functions for a Flash emulated EEPROM - * Not platform dependent. + * Arduino-style interface for Flash emulated EEPROM */ // Include configs and pins to get all EEPROM flags @@ -35,6 +33,7 @@ #include "HAL.h" #include "eeprom_emul.h" +#include "../shared/eeprom_if.h" // ------------------------ // Local defines diff --git a/Marlin/src/HAL/TEENSY35_36/eeprom.cpp b/Marlin/src/HAL/TEENSY35_36/eeprom.cpp index bd597c2ded..ff8fa3626d 100644 --- a/Marlin/src/HAL/TEENSY35_36/eeprom.cpp +++ b/Marlin/src/HAL/TEENSY35_36/eeprom.cpp @@ -29,7 +29,8 @@ #include "../shared/eeprom_api.h" #include -bool PersistentStore::access_start() { return true; } +size_t PersistentStore::capacity() { return E2END + 1; } +bool PersistentStore::access_start() { return true; } bool PersistentStore::access_finish() { return true; } bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { @@ -63,7 +64,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t return false; } -size_t PersistentStore::capacity() { return E2END + 1; } - #endif // USE_WIRED_EEPROM #endif // __MK64FX512__ || __MK66FX1M0__ diff --git a/Marlin/src/HAL/shared/eeprom_if.h b/Marlin/src/HAL/shared/eeprom_if.h new file mode 100644 index 0000000000..e6e7046011 --- /dev/null +++ b/Marlin/src/HAL/shared/eeprom_if.h @@ -0,0 +1,30 @@ +/** + * Marlin 3D Printer Firmware + * + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com + * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com + * + * 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 . + * + */ +#pragma once + +// +// EEPROM +// +void eeprom_write_byte(uint8_t *pos, unsigned char value); +uint8_t eeprom_read_byte(uint8_t *pos); +void eeprom_read_block(void *__dst, const void *__src, size_t __n); +void eeprom_update_block(const void *__src, void *__dst, size_t __n); diff --git a/Marlin/src/HAL/shared/eeprom_i2c.cpp b/Marlin/src/HAL/shared/eeprom_if_i2c.cpp similarity index 93% rename from Marlin/src/HAL/shared/eeprom_i2c.cpp rename to Marlin/src/HAL/shared/eeprom_if_i2c.cpp index cc60c8d196..a4ad9763ba 100644 --- a/Marlin/src/HAL/shared/eeprom_i2c.cpp +++ b/Marlin/src/HAL/shared/eeprom_if_i2c.cpp @@ -21,20 +21,19 @@ */ /** - * Description: functions for I2C connected external EEPROM. - * Not platform dependent. - * - * TODO: Some platform Arduino libraries define these functions - * so Marlin needs to add a glue layer to prevent the conflict. + * Platform-independent Arduino functions for I2C EEPROM. + * Enable USE_SHARED_EEPROM if not supplied by the framework. */ #include "../../inc/MarlinConfig.h" -#if ENABLED(I2C_EEPROM) +#if BOTH(USE_SHARED_EEPROM, I2C_EEPROM) #include "../HAL.h" #include +#include "eeprom_if.h" + #ifndef EEPROM_WRITE_DELAY #define EEPROM_WRITE_DELAY 5 #endif @@ -126,4 +125,4 @@ void eeprom_read_block(void* pos, const void *__dst, size_t n) { if (Wire.available()) *((uint8_t*)pos + c) = Wire.read(); } -#endif // I2C_EEPROM +#endif // USE_SHARED_EEPROM && I2C_EEPROM diff --git a/Marlin/src/HAL/shared/eeprom_spi.cpp b/Marlin/src/HAL/shared/eeprom_if_spi.cpp similarity index 93% rename from Marlin/src/HAL/shared/eeprom_spi.cpp rename to Marlin/src/HAL/shared/eeprom_if_spi.cpp index 73602feaaf..4c3a92e020 100644 --- a/Marlin/src/HAL/shared/eeprom_spi.cpp +++ b/Marlin/src/HAL/shared/eeprom_if_spi.cpp @@ -21,15 +21,16 @@ */ /** - * Description: functions for SPI connected external EEPROM. - * Not platform dependent. + * Platform-independent Arduino functions for SPI EEPROM. + * Enable USE_SHARED_EEPROM if not supplied by the framework. */ #include "../../inc/MarlinConfig.h" -#if ENABLED(SPI_EEPROM) +#if BOTH(USE_SHARED_EEPROM, SPI_EEPROM) #include "../HAL.h" +#include "eeprom_if.h" #define CMD_WREN 6 // WREN #define CMD_READ 2 // WRITE @@ -119,4 +120,4 @@ void eeprom_update_block(const void* src, void* eeprom_address, size_t n) { delay(EEPROM_WRITE_DELAY); // wait for page write to complete } -#endif // SPI_EEPROM +#endif // USE_SHARED_EEPROM && I2C_EEPROM diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 9a2b9f2a0b..2dd9f95d81 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -337,3 +337,8 @@ #else #define SD_CONNECTION_IS(...) 0 #endif + +// Flag if an EEPROM type is pre-selected +#if ENABLED(EEPROM_SETTINGS) && NONE(I2C_EEPROM, SPI_EEPROM, QSPI_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SDCARD_EEPROM_EMULATION) + #define NO_EEPROM_SELECTED 1 +#endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 03701c7cc3..c420740125 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2054,8 +2054,12 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal /** * Make sure only one EEPROM type is enabled */ -#if ENABLED(EEPROM_SETTINGS) && 1 < ENABLED(SDCARD_EEPROM_EMULATION) + ENABLED(FLASH_EEPROM_EMULATION) + ENABLED(SRAM_EEPROM_EMULATION) - #error "Please select only one of SDCARD, FLASH, or SRAM_EEPROM_EMULATION." +#if ENABLED(EEPROM_SETTINGS) + #if 1 < 0 \ + + ENABLED(I2C_EEPROM) + ENABLED(SPI_EEPROM) + ENABLED(QSPI_EEPROM) \ + + ENABLED(SDCARD_EEPROM_EMULATION) + ENABLED(FLASH_EEPROM_EMULATION) + ENABLED(SRAM_EEPROM_EMULATION) + #error "Please select only one method of EEPROM Persistent Storage." + #endif #endif /** diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 39a237cc44..bb4cf3c795 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -28,12 +28,8 @@ // Print debug messages with M111 S2 //#define DEBUG_PRINTCOUNTER -#if USE_WIRED_EEPROM - // round up address to next page boundary (assuming 32 byte pages) - #define STATS_EEPROM_ADDRESS 0x40 -#else - #define STATS_EEPROM_ADDRESS 0x32 -#endif +// Round up I2C / SPI address to next page boundary (assuming 32 byte pages) +#define STATS_EEPROM_ADDRESS TERN(USE_WIRED_EEPROM, 0x40, 0x32) struct printStatistics { // 16 bytes //const uint8_t magic; // Magic header, it will always be 0x16 @@ -57,7 +53,7 @@ class PrintCounter: public Stopwatch { private: typedef Stopwatch super; - #if USE_WIRED_EEPROM || defined(CPU_32_BIT) + #if EITHER(USE_WIRED_EEPROM, CPU_32_BIT) typedef uint32_t eeprom_address_t; #else typedef uint16_t eeprom_address_t; diff --git a/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h b/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h index c9c87d49b9..129a3175bd 100644 --- a/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h +++ b/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h @@ -31,7 +31,9 @@ // // EEPROM Emulation // -#define FLASH_EEPROM_EMULATION +#if NO_EEPROM_SELECTED + #define FLASH_EEPROM_EMULATION +#endif // // SD CARD SPI diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h index ea5fdaa6da..d7c677e3ff 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h @@ -33,11 +33,13 @@ // Ignore temp readings during development. //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 -#define FLASH_EEPROM_EMULATION -#define EEPROM_PAGE_SIZE (0x800U) // 2KB -#define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) -#undef E2END -#define E2END (EEPROM_PAGE_SIZE - 1) // 2KB +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define EEPROM_PAGE_SIZE (0x800U) // 2KB + #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) + #undef E2END + #define E2END (EEPROM_PAGE_SIZE - 1) // 2KB +#endif // // Servos diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3.h index 6658f1fd8f..a8c295c134 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3.h @@ -31,11 +31,13 @@ // Ignore temp readings during development. //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 -#define FLASH_EEPROM_EMULATION -#define EEPROM_PAGE_SIZE (0x800U) // 2KB -#define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) -#undef E2END -#define E2END (EEPROM_PAGE_SIZE - 1) // 2KB +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define EEPROM_PAGE_SIZE (0x800U) // 2KB + #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) + #undef E2END + #define E2END (EEPROM_PAGE_SIZE - 1) // 2KB +#endif // // Servos diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_V1_1.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_V1_1.h index 39c70f0417..6d42b83957 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_V1_1.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_V1_1.h @@ -33,10 +33,12 @@ // Ignore temp readings during development. //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 -#define FLASH_EEPROM_EMULATION -#define EEPROM_PAGE_SIZE (0x800U) // 2KB -#define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) -#define E2END (EEPROM_PAGE_SIZE - 1) +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define EEPROM_PAGE_SIZE (0x800U) // 2KB + #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) + #define E2END (EEPROM_PAGE_SIZE - 1) +#endif // // Limit Switches diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h index ab6757d682..b40306e22d 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h @@ -38,11 +38,13 @@ // // Flash EEPROM Emulation // -#define FLASH_EEPROM_EMULATION -#define EEPROM_PAGE_SIZE (0x800U) // 2KB -#define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) -#undef E2END -#define E2END (EEPROM_PAGE_SIZE - 1) // 2KB +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define EEPROM_PAGE_SIZE (0x800U) // 2KB + #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) + #undef E2END + #define E2END (EEPROM_PAGE_SIZE - 1) // 2KB +#endif // // Limit Switches diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h index b2cdd1c5db..63377f8e16 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h @@ -35,11 +35,13 @@ #define DISABLE_JTAG -#define FLASH_EEPROM_EMULATION -#define EEPROM_PAGE_SIZE (0x800U) // 2KB -#define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) -#undef E2END -#define E2END (EEPROM_PAGE_SIZE - 1) // 2KB +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define EEPROM_PAGE_SIZE (0x800U) // 2KB + #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) + #undef E2END + #define E2END (EEPROM_PAGE_SIZE - 1) // 2KB +#endif // // Servos diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h b/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h index 3fd0b5ae46..908a100341 100644 --- a/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h @@ -52,8 +52,10 @@ //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 // Enable EEPROM Emulation for this board as it doesn't have EEPROM -#define FLASH_EEPROM_EMULATION -#define E2END 0xFFF // 4KB +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define E2END 0xFFF // 4KB +#endif // // Limit Switches diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h b/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h index 9a12cfd7b0..ca1c2894cb 100644 --- a/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h +++ b/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h @@ -52,8 +52,10 @@ //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 // Enable EEPROM Emulation for this board as it doesn't have EEPROM -#define FLASH_EEPROM_EMULATION -#define E2END 0xFFF // 4KB +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define E2END 0xFFF // 4KB +#endif // // Limit Switches diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h b/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h index 3fd0b5ae46..908a100341 100644 --- a/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h +++ b/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h @@ -52,8 +52,10 @@ //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 // Enable EEPROM Emulation for this board as it doesn't have EEPROM -#define FLASH_EEPROM_EMULATION -#define E2END 0xFFF // 4KB +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define E2END 0xFFF // 4KB +#endif // // Limit Switches diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h b/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h index f885db7fed..8d7687f520 100644 --- a/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h +++ b/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h @@ -52,8 +52,10 @@ //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 // Enable EEPROM Emulation for this board as it doesn't have EEPROM -#define FLASH_EEPROM_EMULATION -#define E2END 0xFFF // 4KB +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + #define E2END 0xFFF // 4KB +#endif // // Limit Switches diff --git a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h index 0a4382894f..340e405302 100644 --- a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h +++ b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h @@ -44,9 +44,11 @@ //#define I2C_EEPROM // AT24C64 //#define E2END 0x7FFFUL // 64KB + //#define FLASH_EEPROM_EMULATION //#define E2END 0xFFFUL // 4KB //#define E2END (EEPROM_START_ADDRESS + (EEPROM_PAGE_SIZE) * 2UL - 1UL) + //#define EEPROM_CHITCHAT //#define DEBUG_EEPROM_READWRITE diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h index 50ac8c94be..8f5619aa69 100644 --- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h +++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h @@ -147,8 +147,10 @@ // Persistent Storage // If no option is selected below the SD Card will be used // -//#define SPI_EEPROM -#define FLASH_EEPROM_EMULATION +#if NO_EEPROM_SELECTED + //#define SPI_EEPROM + #define FLASH_EEPROM_EMULATION +#endif #undef E2END #if ENABLED(SPI_EEPROM) diff --git a/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h b/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h index 9829018d8d..00dd2e1184 100644 --- a/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h +++ b/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h @@ -31,10 +31,10 @@ #define BOARD_INFO_NAME "Malyan M200" -// Enable EEPROM Emulation for this board -// This setting should probably be in configuration.h -// but it is literally the only board which uses it. -#define FLASH_EEPROM_EMULATION +// Assume Flash EEPROM +#if NO_EEPROM_SELECTED + #define FLASH_EEPROM_EMULATION +#endif #define SDSS SS_PIN diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h index ff210c4cff..6f3897814d 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h @@ -38,11 +38,13 @@ // #define DISABLE_DEBUG -#define FLASH_EEPROM_EMULATION -// 2K in a AT24C16N -#define EEPROM_PAGE_SIZE (0x800U) // 2KB -#define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) -#define E2END (EEPROM_PAGE_SIZE - 1) +#if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) + #define FLASH_EEPROM_EMULATION + // 2K in a AT24C16N + #define EEPROM_PAGE_SIZE (0x800U) // 2KB + #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) + #define E2END (EEPROM_PAGE_SIZE - 1) +#endif // // Note: MKS Robin mini board is using SPI2 interface. diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 5a4ac26617..06369fbd27 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -41,8 +41,10 @@ // // EEPROM // -//#define FLASH_EEPROM_EMULATION -#define SDCARD_EEPROM_EMULATION +#if NO_EEPROM_SELECTED + //#define FLASH_EEPROM_EMULATION + #define SDCARD_EEPROM_EMULATION +#endif // // Limit Switches diff --git a/Marlin/src/pins/stm32f4/pins_BTT_BTT002_V1_0.h b/Marlin/src/pins/stm32f4/pins_BTT_BTT002_V1_0.h index ee5c4da1fe..838a5e9447 100644 --- a/Marlin/src/pins/stm32f4/pins_BTT_BTT002_V1_0.h +++ b/Marlin/src/pins/stm32f4/pins_BTT_BTT002_V1_0.h @@ -30,8 +30,10 @@ #define BOARD_INFO_NAME "BIGTREE Btt002 1.0" // Use one of these or SDCard-based Emulation will be used -//#define SRAM_EEPROM_EMULATION // Use BackSRAM-based EEPROM emulation -#define FLASH_EEPROM_EMULATION // Use Flash-based EEPROM emulation +#if NO_EEPROM_SELECTED + //#define SRAM_EEPROM_EMULATION // Use BackSRAM-based EEPROM emulation + #define FLASH_EEPROM_EMULATION // Use Flash-based EEPROM emulation +#endif // Ignore temp readings during development. //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 diff --git a/Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h b/Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h index ac8b731aae..a61ef1afaf 100644 --- a/Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h +++ b/Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h @@ -32,9 +32,11 @@ #define BOARD_INFO_NAME "BIGTREE GTR 1.0" // Use one of these or SDCard-based Emulation will be used -//#define I2C_EEPROM -//#define SRAM_EEPROM_EMULATION // Use BackSRAM-based EEPROM emulation -//#define FLASH_EEPROM_EMULATION // Use Flash-based EEPROM emulation +#if NO_EEPROM_SELECTED + //#define I2C_EEPROM + //#define SRAM_EEPROM_EMULATION // Use BackSRAM-based EEPROM emulation + //#define FLASH_EEPROM_EMULATION // Use Flash-based EEPROM emulation +#endif #define TP // Enable to define servo and probe pins @@ -389,3 +391,5 @@ //#define DOGLCD_MOSI PB15 #endif // HAS_SPI_LCD + +#undef TP diff --git a/Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_V1_1.h b/Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_V1_1.h index 02f2c9071b..8d68ca3f9f 100644 --- a/Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_V1_1.h +++ b/Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_V1_1.h @@ -30,8 +30,10 @@ #define BOARD_INFO_NAME "BIGTREE SKR Pro 1.1" // redefined? // Use one of these or SDCard-based Emulation will be used -//#define SRAM_EEPROM_EMULATION // Use BackSRAM-based EEPROM emulation -#define FLASH_EEPROM_EMULATION // Use Flash-based EEPROM emulation +#if NO_EEPROM_SELECTED + //#define SRAM_EEPROM_EMULATION // Use BackSRAM-based EEPROM emulation + #define FLASH_EEPROM_EMULATION // Use Flash-based EEPROM emulation +#endif // // Servos diff --git a/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h b/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h index bdadbe36c2..e3f02bb73a 100644 --- a/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h +++ b/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h @@ -34,19 +34,21 @@ #define DEFAULT_MACHINE_NAME BOARD_INFO_NAME #endif -// change the prio to 3 , 2 is for software serial +// Change the priority to 3. Priority 2 is for software serial. //#define TEMP_TIMER_IRQ_PRIO 3 // // EEPROM Emulation // -#define FLASH_EEPROM_EMULATION +#if NO_EEPROM_SELECTED + #define FLASH_EEPROM_EMULATION + //#define SRAM_EEPROM_EMULATION + //#define I2C_EEPROM +#endif + #if ENABLED(FLASH_EEPROM_EMULATION) #define FLASH_EEPROM_LEVELING -#endif -//#define SRAM_EEPROM_EMULATION -//#define I2C_EEPROM -#ifdef I2C_EEPROM +#elif ENABLED(I2C_EEPROM) #undef E2END // Defined in Arduino Core STM32 to be used with EEPROM emulation. This board uses a real EEPROM. #define E2END 0xFFF // 4KB #endif diff --git a/Marlin/src/pins/stm32f7/pins_REMRAM_V1.h b/Marlin/src/pins/stm32f7/pins_REMRAM_V1.h index ac337092f6..3fba28161e 100644 --- a/Marlin/src/pins/stm32f7/pins_REMRAM_V1.h +++ b/Marlin/src/pins/stm32f7/pins_REMRAM_V1.h @@ -28,7 +28,9 @@ #define BOARD_INFO_NAME "RemRam v1" #define DEFAULT_MACHINE_NAME "RemRam" -#define SRAM_EEPROM_EMULATION // Emulate the EEPROM using Backup SRAM +#if NO_EEPROM_SELECTED + #define SRAM_EEPROM_EMULATION // Emulate the EEPROM using Backup SRAM +#endif #if HOTENDS > 1 || E_STEPPERS > 1 #error "RemRam supports only one hotend / E-stepper."