More explicit EEPROM types (#17127)

This commit is contained in:
Scott Lahteine 2020-03-11 16:41:18 -05:00 committed by GitHub
parent 924fa6045c
commit 112245ee48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 92 additions and 60 deletions

View File

@ -54,7 +54,7 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if ENABLED(EEPROM_SETTINGS) && NONE(I2C_EEPROM, SPI_EEPROM) #if ENABLED(FLASH_EEPROM_EMULATION)
#include "../shared/Marduino.h" #include "../shared/Marduino.h"
#include "../shared/persistent_store_api.h" #include "../shared/persistent_store_api.h"
@ -1016,5 +1016,5 @@ void eeprom_flush() {
ee_Flush(); ee_Flush();
} }
#endif // EEPROM_SETTINGS && (!I2C_EEPROM && !SPI_EEPROM) #endif // FLASH_EEPROM_EMULATION
#endif // ARDUINO_ARCH_AVR #endif // ARDUINO_ARCH_AVR

View File

@ -20,3 +20,9 @@
* *
*/ */
#pragma once #pragma once
#if USE_EMULATED_EEPROM
#undef SRAM_EEPROM_EMULATION
#undef SDCARD_EEPROM_EMULATION
#define FLASH_EEPROM_EMULATION 1
#endif

View File

@ -29,7 +29,7 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#include "../shared/persistent_store_api.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) #define E2END 0xFFF // Default to Flash emulated EEPROM size (EepromEmulation_Due.cpp)
#endif #endif
@ -38,7 +38,7 @@ extern void eeprom_flush();
bool PersistentStore::access_start() { return true; } bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { bool PersistentStore::access_finish() {
#if NONE(I2C_EEPROM, SPI_EEPROM) #if ENABLED(FLASH_EEPROM_EMULATION)
eeprom_flush(); eeprom_flush();
#endif #endif
return true; return true;

View File

@ -20,3 +20,11 @@
* *
*/ */
#pragma once #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

View File

@ -38,13 +38,11 @@
*/ */
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(FLASH_EEPROM_EMULATION)
#include "persistent_store_api.h" #include "persistent_store_api.h"
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if ENABLED(FLASH_EEPROM_EMULATION)
extern "C" { extern "C" {
#include <lpc17xx_iap.h> #include <lpc17xx_iap.h>
} }
@ -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; } size_t PersistentStore::capacity() { return EEPROM_SIZE; }
#endif // FLASH_EEPROM_EMULATION #endif // FLASH_EEPROM_EMULATION
#endif // EEPROM_SETTINGS
#endif // TARGET_LPC1768 #endif // TARGET_LPC1768

View File

@ -22,14 +22,11 @@
*/ */
#ifdef TARGET_LPC1768 #ifdef TARGET_LPC1768
#include "../../inc/MarlinConfigPre.h"
#if ENABLED(EEPROM_SETTINGS)
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#include "persistent_store_api.h"
#if DISABLED(FLASH_EEPROM_EMULATION) #if ENABLED(SDCARD_EEPROM_EMULATION)
#include "persistent_store_api.h"
#include <chanfs/diskio.h> #include <chanfs/diskio.h>
#include <chanfs/ff.h> #include <chanfs/ff.h>
@ -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 size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM
#endif // !FLASH_EEPROM_EMULATION #endif // SDCARD_EEPROM_EMULATION
#endif // EEPROM_SETTINGS
#endif // TARGET_LPC1768 #endif // TARGET_LPC1768

View File

@ -20,3 +20,9 @@
* *
*/ */
#pragma once #pragma once
#if USE_EMULATED_EEPROM
#undef SRAM_EEPROM_EMULATION
#undef SDCARD_EEPROM_EMULATION
#define FLASH_EEPROM_EMULATION 1
#endif

View File

@ -23,7 +23,7 @@
* Test SAMD51 specific configuration values for errors at compile-time. * 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" #warning "Did you activate the SmartEEPROM? See https://github.com/GMagician/SAMD51-SmartEEprom-Manager/releases"
#endif #endif

View File

@ -27,7 +27,7 @@
#include "../shared/persistent_store_api.h" #include "../shared/persistent_store_api.h"
#if NONE(SPI_EEPROM, I2C_EEPROM) #if ENABLED(FLASH_EEPROM_EMULATION)
#define NVMCTRL_CMD(c) do{ \ #define NVMCTRL_CMD(c) do{ \
SYNC(!NVMCTRL->STATUS.bit.READY); \ SYNC(!NVMCTRL->STATUS.bit.READY); \
NVMCTRL->INTFLAG.bit.DONE = true; \ NVMCTRL->INTFLAG.bit.DONE = true; \
@ -41,7 +41,7 @@
#endif #endif
bool PersistentStore::access_start() { 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 NVMCTRL->SEECFG.reg = NVMCTRL_SEECFG_WMODE_BUFFERED; // Buffered mode and segment reallocation active
#endif #endif
@ -49,7 +49,7 @@ bool PersistentStore::access_start() {
} }
bool PersistentStore::access_finish() { bool PersistentStore::access_finish() {
#if NONE(SPI_EEPROM, I2C_EEPROM) #if ENABLED(FLASH_EEPROM_EMULATION)
NVMCTRL_FLUSH(); NVMCTRL_FLUSH();
if (!NVMCTRL->SEESTAT.bit.LOCK) if (!NVMCTRL->SEESTAT.bit.LOCK)
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_LSEE); // Lock E2P data write access 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) { 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) if (NVMCTRL->SEESTAT.bit.RLOCK)
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_USEE); // Unlock E2P data write access NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_USEE); // Unlock E2P data write access
#endif #endif
while (size--) { while (size--) {
const uint8_t v = *value; 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; uint8_t * const p = (uint8_t * const)pos;
if (v != eeprom_read_byte(p)) { if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v); 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; 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 #endif
crc16(crc, &v, 1); crc16(crc, &v, 1);
pos++; 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*/) { bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
while (size--) { while (size--) {
uint8_t c; uint8_t c;
#if ANY(SPI_EEPROM, I2C_EEPROM) #if ENABLED(FLASH_EEPROM_EMULATION)
c = eeprom_read_byte((uint8_t*)pos);
#else
SYNC(NVMCTRL->SEESTAT.bit.BUSY); SYNC(NVMCTRL->SEESTAT.bit.BUSY);
c = ((volatile uint8_t *)SEEPROM_ADDR)[pos]; c = ((volatile uint8_t *)SEEPROM_ADDR)[pos];
#else
c = eeprom_read_byte((uint8_t*)pos);
#endif #endif
if (writing) *value = c; if (writing) *value = c;
crc16(crc, &c, 1); 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() { size_t PersistentStore::capacity() {
#if ANY(SPI_EEPROM, I2C_EEPROM) #if ENABLED(FLASH_EEPROM_EMULATION)
return E2END + 1;
#else
const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ, const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ,
sblk = NVMCTRL->SEESTAT.bit.SBLK; sblk = NVMCTRL->SEESTAT.bit.SBLK;
@ -121,6 +119,8 @@ size_t PersistentStore::capacity() {
else if (sblk <= 4 || psz == 5) return 16384; else if (sblk <= 4 || psz == 5) return 16384;
else if (sblk >= 9 && psz == 7) return 65536; else if (sblk >= 9 && psz == 7) return 65536;
else return 32768; else return 32768;
#else
return E2END + 1;
#endif #endif
} }

View File

@ -24,7 +24,7 @@
#include "../../inc/MarlinConfig.h" #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" #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; uint8_t v = *value;
// Save to either external EEPROM, program flash or Backup SRAM // 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, // EEPROM has only ~100,000 write cycles,
// so only write bytes that have changed! // so only write bytes that have changed!
uint8_t * const p = (uint8_t * const)pos; 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 { do {
// Read from either external EEPROM, program flash or Backup SRAM // Read from either external EEPROM, program flash or Backup SRAM
const uint8_t c = ( const uint8_t c = (
#if EITHER(SPI_EEPROM, I2C_EEPROM) #if USE_REAL_EEPROM
eeprom_read_byte((uint8_t*)pos) eeprom_read_byte((uint8_t*)pos)
#else #else
(*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos))) (*(__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() { size_t PersistentStore::capacity() {
return ( return (
#if ENABLED(SRAM_EEPROM_EMULATION) #if USE_REAL_EEPROM
4096 // 4kB
#else
E2END + 1 E2END + 1
#else
4096 // 4kB
#endif #endif
); );
} }
#endif // EEPROM_SETTINGS && (SRAM_EEPROM_EMULATION || SPI_EEPROM || I2C_EEPROM) #endif // USE_REAL_EEPROM || SRAM_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

View File

@ -28,7 +28,7 @@
#include "../../inc/MarlinConfig.h" #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" #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; } size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; }
#endif // EEPROM_SETTINGS #endif // SDCARD_EEPROM_EMULATION
#endif // STM32 #endif // STM32 && !STM32GENERIC

View File

@ -22,7 +22,7 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if ENABLED(EEPROM_SETTINGS) && EITHER(SPI_EEPROM, I2C_EEPROM) #if USE_REAL_EEPROM
#include "../shared/persistent_store_api.h" #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; } size_t PersistentStore::capacity() { return E2END + 1; }
#endif // EEPROM_SETTINGS && EITHER(SPI_EEPROM, I2C_EEPROM) #endif // USE_REAL_EEPROM
#endif // __STM32F1__ #endif // __STM32F1__

View File

@ -29,7 +29,7 @@
#include "../../inc/MarlinConfig.h" #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" #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; } size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; }
#endif // EEPROM_SETTINGS #endif // SDCARD_EEPROM_EMULATION
#endif // __STM32F1__ #endif // __STM32F1__

View File

@ -27,13 +27,7 @@
// Include configs and pins to get all EEPROM flags // Include configs and pins to get all EEPROM flags
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#ifdef STM32F7 #if ENABLED(FLASH_EEPROM_EMULATION)
#define HAS_EMULATED_EEPROM 1
#else
#define HAS_EMULATED_EEPROM NONE(I2C_EEPROM, SPI_EEPROM)
#endif
#if HAS_EMULATED_EEPROM && ENABLED(EEPROM_SETTINGS)
// ------------------------ // ------------------------
// Includes // 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) #endif // STM32GENERIC && (STM32F4 || STM32F7)

View File

@ -20,3 +20,11 @@
* *
*/ */
#pragma once #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

View File

@ -35,6 +35,23 @@
#define HAS_LINEAR_E_JERK 1 #define HAS_LINEAR_E_JERK 1
#endif #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 #ifdef TEENSYDUINO
#undef max #undef max
#define max(a,b) ((a)>(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b))

View File

@ -28,7 +28,7 @@
// Print debug messages with M111 S2 // Print debug messages with M111 S2
//#define DEBUG_PRINTCOUNTER //#define DEBUG_PRINTCOUNTER
#if EITHER(I2C_EEPROM, SPI_EEPROM) #if USE_REAL_EEPROM
// round up address to next page boundary (assuming 32 byte pages) // round up address to next page boundary (assuming 32 byte pages)
#define STATS_EEPROM_ADDRESS 0x40 #define STATS_EEPROM_ADDRESS 0x40
#else #else
@ -57,7 +57,7 @@ class PrintCounter: public Stopwatch {
private: private:
typedef Stopwatch super; 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; typedef uint32_t eeprom_address_t;
#else #else
typedef uint16_t eeprom_address_t; typedef uint16_t eeprom_address_t;

View File

@ -370,7 +370,7 @@ void CardReader::mount() {
else { else {
flag.mounted = true; flag.mounted = true;
SERIAL_ECHO_MSG(STR_SD_CARD_OK); 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(); settings.first_load();
#endif #endif
} }
@ -622,7 +622,7 @@ void CardReader::checkautostart() {
if (autostart_index < 0 || flag.sdprinting) return; if (autostart_index < 0 || flag.sdprinting) return;
if (!isMounted()) mount(); if (!isMounted()) mount();
#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) #if ENABLED(SDCARD_EEPROM_EMULATION)
else settings.first_load(); else settings.first_load();
#endif #endif