diff --git a/Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp b/Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp index 926307935..f1ae224bf 100644 --- a/Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp +++ b/Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp @@ -54,7 +54,7 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) && NONE(I2C_EEPROM, SPI_EEPROM) +#if ENABLED(FLASH_EEPROM_EMULATION) #include "../shared/Marduino.h" #include "../shared/persistent_store_api.h" @@ -1016,5 +1016,5 @@ void eeprom_flush() { ee_Flush(); } -#endif // EEPROM_SETTINGS && (!I2C_EEPROM && !SPI_EEPROM) +#endif // FLASH_EEPROM_EMULATION #endif // ARDUINO_ARCH_AVR diff --git a/Marlin/src/HAL/HAL_DUE/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_DUE/inc/Conditionals_post.h index 0285c52ee..223890d79 100644 --- a/Marlin/src/HAL/HAL_DUE/inc/Conditionals_post.h +++ b/Marlin/src/HAL/HAL_DUE/inc/Conditionals_post.h @@ -20,3 +20,9 @@ * */ #pragma once + +#if USE_EMULATED_EEPROM + #undef SRAM_EEPROM_EMULATION + #undef SDCARD_EEPROM_EMULATION + #define FLASH_EEPROM_EMULATION 1 +#endif diff --git a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp index 9fdcca785..fbdc760e4 100644 --- a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp @@ -29,7 +29,7 @@ #include "../../inc/MarlinConfig.h" #include "../shared/persistent_store_api.h" -#if !defined(E2END) && NONE(I2C_EEPROM, SPI_EEPROM) +#if !defined(E2END) && ENABLED(FLASH_EEPROM_EMULATION) #define E2END 0xFFF // Default to Flash emulated EEPROM size (EepromEmulation_Due.cpp) #endif @@ -38,7 +38,7 @@ extern void eeprom_flush(); bool PersistentStore::access_start() { return true; } bool PersistentStore::access_finish() { - #if NONE(I2C_EEPROM, SPI_EEPROM) + #if ENABLED(FLASH_EEPROM_EMULATION) eeprom_flush(); #endif return true; diff --git a/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_post.h index 0285c52ee..263717454 100644 --- a/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_post.h +++ b/Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_post.h @@ -20,3 +20,11 @@ * */ #pragma once + +#if ENABLED(EEPROM_SETTINGS) + #undef USE_REAL_EEPROM + #define USE_EMULATED_EEPROM 1 + #if DISABLED(FLASH_EEPROM_EMULATION) + #define SDCARD_EEPROM_EMULATION 1 + #endif +#endif diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp index c7cad4d96..5525f818a 100644 --- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp @@ -38,13 +38,11 @@ */ #include "../../inc/MarlinConfigPre.h" -#if ENABLED(EEPROM_SETTINGS) +#if ENABLED(FLASH_EEPROM_EMULATION) #include "persistent_store_api.h" #include "../../inc/MarlinConfig.h" -#if ENABLED(FLASH_EEPROM_EMULATION) - extern "C" { #include } @@ -128,5 +126,4 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t size_t PersistentStore::capacity() { return EEPROM_SIZE; } #endif // FLASH_EEPROM_EMULATION -#endif // EEPROM_SETTINGS #endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp index 50d52fb86..aa61938b0 100644 --- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp @@ -22,15 +22,12 @@ */ #ifdef TARGET_LPC1768 -#include "../../inc/MarlinConfigPre.h" +#include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) +#if ENABLED(SDCARD_EEPROM_EMULATION) -#include "../../inc/MarlinConfig.h" #include "persistent_store_api.h" -#if DISABLED(FLASH_EEPROM_EMULATION) - #include #include @@ -178,6 +175,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM -#endif // !FLASH_EEPROM_EMULATION -#endif // EEPROM_SETTINGS +#endif // SDCARD_EEPROM_EMULATION #endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_post.h index 0285c52ee..223890d79 100644 --- a/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_post.h +++ b/Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_post.h @@ -20,3 +20,9 @@ * */ #pragma once + +#if USE_EMULATED_EEPROM + #undef SRAM_EEPROM_EMULATION + #undef SDCARD_EEPROM_EMULATION + #define FLASH_EEPROM_EMULATION 1 +#endif diff --git a/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h b/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h index 04c137c34..cc7a10e7a 100644 --- a/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h +++ b/Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h @@ -23,7 +23,7 @@ * Test SAMD51 specific configuration values for errors at compile-time. */ -#if ENABLED(EEPROM_SETTINGS) && NONE(SPI_EEPROM, I2C_EEPROM) +#if ENABLED(FLASH_EEPROM_EMULATION) #warning "Did you activate the SmartEEPROM? See https://github.com/GMagician/SAMD51-SmartEEprom-Manager/releases" #endif diff --git a/Marlin/src/HAL/HAL_SAMD51/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_SAMD51/persistent_store_eeprom.cpp index c450599d7..6b7326bb2 100644 --- a/Marlin/src/HAL/HAL_SAMD51/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_SAMD51/persistent_store_eeprom.cpp @@ -27,7 +27,7 @@ #include "../shared/persistent_store_api.h" -#if NONE(SPI_EEPROM, I2C_EEPROM) +#if ENABLED(FLASH_EEPROM_EMULATION) #define NVMCTRL_CMD(c) do{ \ SYNC(!NVMCTRL->STATUS.bit.READY); \ NVMCTRL->INTFLAG.bit.DONE = true; \ @@ -41,7 +41,7 @@ #endif bool PersistentStore::access_start() { - #if NONE(SPI_EEPROM, I2C_EEPROM) + #if ENABLED(FLASH_EEPROM_EMULATION) NVMCTRL->SEECFG.reg = NVMCTRL_SEECFG_WMODE_BUFFERED; // Buffered mode and segment reallocation active #endif @@ -49,7 +49,7 @@ bool PersistentStore::access_start() { } bool PersistentStore::access_finish() { - #if NONE(SPI_EEPROM, I2C_EEPROM) + #if ENABLED(FLASH_EEPROM_EMULATION) NVMCTRL_FLUSH(); if (!NVMCTRL->SEESTAT.bit.LOCK) NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_LSEE); // Lock E2P data write access @@ -59,14 +59,20 @@ bool PersistentStore::access_finish() { } bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) { - #if NONE(SPI_EEPROM, I2C_EEPROM) + #if ENABLED(FLASH_EEPROM_EMULATION) if (NVMCTRL->SEESTAT.bit.RLOCK) NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_USEE); // Unlock E2P data write access #endif while (size--) { const uint8_t v = *value; - #if ANY(SPI_EEPROM, I2C_EEPROM) + #if ENABLED(FLASH_EEPROM_EMULATION) + SYNC(NVMCTRL->SEESTAT.bit.BUSY); + if (NVMCTRL->INTFLAG.bit.SEESFULL) + NVMCTRL_FLUSH(); // Next write will trigger a sector reallocation. I need to flush 'pagebuffer' + ((volatile uint8_t *)SEEPROM_ADDR)[pos] = v; + SYNC(!NVMCTRL->INTFLAG.bit.SEEWRC); + #else uint8_t * const p = (uint8_t * const)pos; if (v != eeprom_read_byte(p)) { eeprom_write_byte(p, v); @@ -76,12 +82,6 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui return true; } } - #else - SYNC(NVMCTRL->SEESTAT.bit.BUSY); - if (NVMCTRL->INTFLAG.bit.SEESFULL) - NVMCTRL_FLUSH(); // Next write will trigger a sector reallocation. I need to flush 'pagebuffer' - ((volatile uint8_t *)SEEPROM_ADDR)[pos] = v; - SYNC(!NVMCTRL->INTFLAG.bit.SEEWRC); #endif crc16(crc, &v, 1); pos++; @@ -93,11 +93,11 @@ 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*/) { while (size--) { uint8_t c; - #if ANY(SPI_EEPROM, I2C_EEPROM) - c = eeprom_read_byte((uint8_t*)pos); - #else + #if ENABLED(FLASH_EEPROM_EMULATION) SYNC(NVMCTRL->SEESTAT.bit.BUSY); c = ((volatile uint8_t *)SEEPROM_ADDR)[pos]; + #else + c = eeprom_read_byte((uint8_t*)pos); #endif if (writing) *value = c; crc16(crc, &c, 1); @@ -108,9 +108,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t } size_t PersistentStore::capacity() { - #if ANY(SPI_EEPROM, I2C_EEPROM) - return E2END + 1; - #else + #if ENABLED(FLASH_EEPROM_EMULATION) const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ, sblk = NVMCTRL->SEESTAT.bit.SBLK; @@ -121,6 +119,8 @@ size_t PersistentStore::capacity() { else if (sblk <= 4 || psz == 5) return 16384; else if (sblk >= 9 && psz == 7) return 65536; else return 32768; + #else + return E2END + 1; #endif } diff --git a/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp index b4e58a795..d9538741d 100644 --- a/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp +++ b/Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp @@ -24,7 +24,7 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) && ANY(SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) +#if EITHER(USE_REAL_EEPROM, SRAM_EEPROM_EMULATION) #include "../shared/persistent_store_api.h" @@ -41,7 +41,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui uint8_t v = *value; // Save to either external EEPROM, program flash or Backup SRAM - #if EITHER(SPI_EEPROM, I2C_EEPROM) + #if USE_REAL_EEPROM // EEPROM has only ~100,000 write cycles, // so only write bytes that have changed! uint8_t * const p = (uint8_t * const)pos; @@ -68,7 +68,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t do { // Read from either external EEPROM, program flash or Backup SRAM const uint8_t c = ( - #if EITHER(SPI_EEPROM, I2C_EEPROM) + #if USE_REAL_EEPROM eeprom_read_byte((uint8_t*)pos) #else (*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos))) @@ -85,13 +85,13 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t size_t PersistentStore::capacity() { return ( - #if ENABLED(SRAM_EEPROM_EMULATION) - 4096 // 4kB - #else + #if USE_REAL_EEPROM E2END + 1 + #else + 4096 // 4kB #endif ); } -#endif // EEPROM_SETTINGS && (SRAM_EEPROM_EMULATION || SPI_EEPROM || I2C_EEPROM) +#endif // USE_REAL_EEPROM || SRAM_EEPROM_EMULATION #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC diff --git a/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp index 2df90d232..c5afc557e 100644 --- a/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp @@ -28,7 +28,7 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) +#if ENABLED(SDCARD_EEPROM_EMULATION) #include "../shared/persistent_store_api.h" @@ -99,5 +99,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; } -#endif // EEPROM_SETTINGS -#endif // STM32 +#endif // SDCARD_EEPROM_EMULATION +#endif // STM32 && !STM32GENERIC diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp index f2a1cb031..1b3714c56 100644 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp @@ -22,7 +22,7 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) && EITHER(SPI_EEPROM, I2C_EEPROM) +#if USE_REAL_EEPROM #include "../shared/persistent_store_api.h" @@ -73,5 +73,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t size_t PersistentStore::capacity() { return E2END + 1; } -#endif // EEPROM_SETTINGS && EITHER(SPI_EEPROM, I2C_EEPROM) +#endif // USE_REAL_EEPROM #endif // __STM32F1__ diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp index 0a0d71271..8b5d89ad8 100644 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp @@ -29,7 +29,7 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) +#if ENABLED(SDCARD_EEPROM_EMULATION) #include "../shared/persistent_store_api.h" @@ -100,6 +100,6 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; } -#endif // EEPROM_SETTINGS +#endif // SDCARD_EEPROM_EMULATION #endif // __STM32F1__ diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/EmulatedEeprom.cpp b/Marlin/src/HAL/HAL_STM32_F4_F7/EmulatedEeprom.cpp index 4852234ba..4e76e9712 100644 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/EmulatedEeprom.cpp +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/EmulatedEeprom.cpp @@ -27,13 +27,7 @@ // Include configs and pins to get all EEPROM flags #include "../../inc/MarlinConfig.h" -#ifdef STM32F7 - #define HAS_EMULATED_EEPROM 1 -#else - #define HAS_EMULATED_EEPROM NONE(I2C_EEPROM, SPI_EEPROM) -#endif - -#if HAS_EMULATED_EEPROM && ENABLED(EEPROM_SETTINGS) +#if ENABLED(FLASH_EEPROM_EMULATION) // ------------------------ // Includes @@ -118,5 +112,5 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n) { } -#endif // EEPROM_SETTINGS +#endif // FLASH_EEPROM_EMULATION #endif // STM32GENERIC && (STM32F4 || STM32F7) diff --git a/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_post.h b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_post.h index 0285c52ee..6e2cf6210 100644 --- a/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_post.h +++ b/Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_post.h @@ -20,3 +20,11 @@ * */ #pragma once + +#if ENABLED(EEPROM_SETTINGS) && defined(STM32F7) + #undef USE_REAL_EEPROM + #define USE_EMULATED_EEPROM 1 + #undef SRAM_EEPROM_EMULATION + #undef SDCARD_EEPROM_EMULATION + #define FLASH_EEPROM_EMULATION 1 +#endif diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 8b2cd0efd..e5dc7262a 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -35,6 +35,23 @@ #define HAS_LINEAR_E_JERK 1 #endif +#if ENABLED(EEPROM_SETTINGS) + #if NONE(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SDCARD_EEPROM_EMULATION) && EITHER(I2C_EEPROM, SPI_EEPROM) + #define USE_REAL_EEPROM 1 + #else + #define USE_EMULATED_EEPROM 1 + #endif + #if NONE(USE_REAL_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION) + #define SDCARD_EEPROM_EMULATION 1 + #endif +#else + #undef I2C_EEPROM + #undef SPI_EEPROM + #undef SDCARD_EEPROM_EMULATION + #undef SRAM_EEPROM_EMULATION + #undef FLASH_EEPROM_EMULATION +#endif + #ifdef TEENSYDUINO #undef max #define max(a,b) ((a)>(b)?(a):(b)) diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 1630de988..261cdf058 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -28,7 +28,7 @@ // Print debug messages with M111 S2 //#define DEBUG_PRINTCOUNTER -#if EITHER(I2C_EEPROM, SPI_EEPROM) +#if USE_REAL_EEPROM // round up address to next page boundary (assuming 32 byte pages) #define STATS_EEPROM_ADDRESS 0x40 #else @@ -57,7 +57,7 @@ class PrintCounter: public Stopwatch { private: typedef Stopwatch super; - #if EITHER(I2C_EEPROM, SPI_EEPROM) || defined(CPU_32_BIT) + #if USE_REAL_EEPROM || defined(CPU_32_BIT) typedef uint32_t eeprom_address_t; #else typedef uint16_t eeprom_address_t; diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index ee3513ab4..5e12aeef2 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -370,7 +370,7 @@ void CardReader::mount() { else { flag.mounted = true; SERIAL_ECHO_MSG(STR_SD_CARD_OK); - #if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) + #if ENABLED(SDCARD_EEPROM_EMULATION) settings.first_load(); #endif } @@ -622,7 +622,7 @@ void CardReader::checkautostart() { if (autostart_index < 0 || flag.sdprinting) return; if (!isMounted()) mount(); - #if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) + #if ENABLED(SDCARD_EEPROM_EMULATION) else settings.first_load(); #endif