Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrangle some EEPROM types #17127

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Marlin/src/HAL/HAL_DUE/EepromEmulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1016,5 +1016,5 @@ void eeprom_flush() {
ee_Flush();
}

#endif // EEPROM_SETTINGS && (!I2C_EEPROM && !SPI_EEPROM)
#endif // FLASH_EEPROM_EMULATION
#endif // ARDUINO_ARCH_AVR
6 changes: 6 additions & 0 deletions Marlin/src/HAL/HAL_DUE/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@
*
*/
#pragma once

#if USE_EMULATED_EEPROM
#undef SRAM_EEPROM_EMULATION
#undef SDCARD_EEPROM_EMULATION
#define FLASH_EEPROM_EMULATION 1
#endif
4 changes: 2 additions & 2 deletions Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions Marlin/src/HAL/HAL_LPC1768/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions Marlin/src/HAL/HAL_LPC1768/persistent_store_flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
}
Expand Down Expand Up @@ -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
10 changes: 3 additions & 7 deletions Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions Marlin/src/HAL/HAL_SAMD51/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@
*
*/
#pragma once

#if USE_EMULATED_EEPROM
#undef SRAM_EEPROM_EMULATION
#undef SDCARD_EEPROM_EMULATION
#define FLASH_EEPROM_EMULATION 1
#endif
2 changes: 1 addition & 1 deletion Marlin/src/HAL/HAL_SAMD51/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 17 additions & 17 deletions Marlin/src/HAL/HAL_SAMD51/persistent_store_eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand All @@ -41,15 +41,15 @@
#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

return true;
}

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
Expand All @@ -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);
Expand All @@ -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++;
Expand All @@ -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);
Expand All @@ -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;

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

Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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;
Expand All @@ -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)))
Expand All @@ -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
6 changes: 3 additions & 3 deletions Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions Marlin/src/HAL/HAL_STM32F1/persistent_store_eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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__
4 changes: 2 additions & 2 deletions Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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__
10 changes: 2 additions & 8 deletions Marlin/src/HAL/HAL_STM32_F4_F7/EmulatedEeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
8 changes: 8 additions & 0 deletions Marlin/src/HAL/HAL_STM32_F4_F7/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/printcounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Loading