More explicit EEPROM types (#17127)

2.0.x
Scott Lahteine 5 years ago committed by GitHub
parent 924fa6045c
commit 112245ee48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

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

@ -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;

@ -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

@ -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 <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; }
#endif // FLASH_EEPROM_EMULATION
#endif // EEPROM_SETTINGS
#endif // TARGET_LPC1768

@ -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 <chanfs/diskio.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
#endif // !FLASH_EEPROM_EMULATION
#endif // EEPROM_SETTINGS
#endif // SDCARD_EEPROM_EMULATION
#endif // TARGET_LPC1768

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

@ -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

@ -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
}

@ -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

@ -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

@ -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__

@ -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__

@ -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)

@ -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

@ -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))

@ -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;

@ -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

Loading…
Cancel
Save