QSPI EEPROM for SAMD51 (#17292)

This commit is contained in:
Giuliano Zaro 2020-03-27 23:29:17 +01:00 committed by GitHub
parent 3655e240f5
commit 129b270628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 413 additions and 179 deletions

View File

@ -25,7 +25,7 @@
#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE) #if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
bool PersistentStore::access_start() { return true; } bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }

View File

@ -57,7 +57,7 @@
#if ENABLED(FLASH_EEPROM_EMULATION) #if ENABLED(FLASH_EEPROM_EMULATION)
#include "../shared/Marduino.h" #include "../shared/Marduino.h"
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#define EEPROMSize 4096 #define EEPROMSize 4096
#define PagesPerGroup 128 #define PagesPerGroup 128

View File

@ -27,7 +27,7 @@
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#if !defined(E2END) && ENABLED(FLASH_EEPROM_EMULATION) #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)

View File

@ -21,7 +21,7 @@
*/ */
#pragma once #pragma once
#if USE_EMULATED_EEPROM #if USE_FALLBACK_EEPROM
#undef SRAM_EEPROM_EMULATION #undef SRAM_EEPROM_EMULATION
#undef SDCARD_EEPROM_EMULATION #undef SDCARD_EEPROM_EMULATION
#define FLASH_EEPROM_EMULATION #define FLASH_EEPROM_EMULATION

View File

@ -26,7 +26,7 @@
#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION) #if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#include "EEPROM.h" #include "EEPROM.h"
#define EEPROM_SIZE 4096 #define EEPROM_SIZE 4096

View File

@ -22,6 +22,6 @@
#pragma once #pragma once
// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation // If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
#if ENABLED(EEPROM_SETTINGS) && NONE(USE_REAL_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION) #if ENABLED(EEPROM_SETTINGS) && NONE(USE_WIRED_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
#define SDCARD_EEPROM_EMULATION #define SDCARD_EEPROM_EMULATION
#endif #endif

View File

@ -26,7 +26,7 @@
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#include <stdio.h> #include <stdio.h>
#define LINUX_EEPROM_SIZE (E2END + 1) #define LINUX_EEPROM_SIZE (E2END + 1)

View File

@ -21,6 +21,6 @@
*/ */
#pragma once #pragma once
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#define FLASH_EEPROM_EMULATION #define FLASH_EEPROM_EMULATION

View File

@ -40,7 +40,7 @@
#if ENABLED(FLASH_EEPROM_EMULATION) #if ENABLED(FLASH_EEPROM_EMULATION)
#include "persistent_store_api.h" #include "eeprom_api.h"
extern "C" { extern "C" {
#include <lpc17xx_iap.h> #include <lpc17xx_iap.h>

View File

@ -26,7 +26,7 @@
#if ENABLED(SDCARD_EEPROM_EMULATION) #if ENABLED(SDCARD_EEPROM_EMULATION)
#include "persistent_store_api.h" #include "eeprom_api.h"
#include <chanfs/diskio.h> #include <chanfs/diskio.h>
#include <chanfs/ff.h> #include <chanfs/ff.h>

View File

@ -21,6 +21,6 @@
*/ */
#pragma once #pragma once
#if USE_EMULATED_EEPROM && NONE(SDCARD_EEPROM_EMULATION, SRAM_EEPROM_EMULATION) #if USE_FALLBACK_EEPROM && NONE(SDCARD_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
#define FLASH_EEPROM_EMULATION #define FLASH_EEPROM_EMULATION
#endif #endif

View File

@ -0,0 +1,78 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include "../../inc/MarlinConfig.h"
#if ENABLED(QSPI_EEPROM)
#include "QSPIFlash.h"
#define INVALID_ADDR 0xffffffff
#define SECTOR_OF(a) (a & ~(SFLASH_SECTOR_SIZE - 1))
#define OFFSET_OF(a) (a & (SFLASH_SECTOR_SIZE - 1))
Adafruit_SPIFlashBase * QSPIFlash::_flashBase = nullptr;
uint8_t QSPIFlash::_buf[SFLASH_SECTOR_SIZE];
uint32_t QSPIFlash::_addr = INVALID_ADDR;
void QSPIFlash::begin() {
if (_flashBase != nullptr) return;
_flashBase = new Adafruit_SPIFlashBase(new Adafruit_FlashTransport_QSPI());
_flashBase->begin(NULL);
}
size_t QSPIFlash::size() {
return _flashBase->size();
}
uint8_t QSPIFlash::readByte(const uint32_t address) {
if (SECTOR_OF(address) == _addr) return _buf[OFFSET_OF(address)];
return _flashBase->read8(address);
}
void QSPIFlash::writeByte(const uint32_t address, const uint8_t value) {
uint32_t const sector_addr = SECTOR_OF(address);
// Page changes, flush old and update new cache
if (sector_addr != _addr) {
flush();
_addr = sector_addr;
// read a whole page from flash
_flashBase->readBuffer(sector_addr, _buf, SFLASH_SECTOR_SIZE);
}
_buf[OFFSET_OF(address)] = value;
}
void QSPIFlash::flush() {
if (_addr == INVALID_ADDR) return;
_flashBase->eraseSector(_addr / SFLASH_SECTOR_SIZE);
_flashBase->writeBuffer(_addr, _buf, SFLASH_SECTOR_SIZE);
_addr = INVALID_ADDR;
}
#endif // QSPI_EEPROM

View File

@ -0,0 +1,51 @@
/**
* @file QSPIFlash.h
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach and Dean Miller for Adafruit Industries LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Derived from Adafruit_SPIFlash class with no SdFat references
*
*/
#pragma once
#include "Adafruit_SPIFlashBase.h"
// This class extends Adafruit_SPIFlashBase by adding caching support.
//
// This class will use 4096 Bytes of RAM as a block cache.
class QSPIFlash {
public:
static void begin();
static size_t size();
static uint8_t readByte(const uint32_t address);
static void writeByte(const uint32_t address, const uint8_t v);
static void flush();
private:
static Adafruit_SPIFlashBase * _flashBase;
static uint8_t _buf[SFLASH_SECTOR_SIZE];
static uint32_t _addr;
};
extern QSPIFlash qspi;

View File

@ -0,0 +1,66 @@
/**
* Marlin 3D Printer Firmware
*
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
#if ENABLED(EEPROM_SETTINGS) && NONE(QSPI_EEPROM, FLASH_EEPROM_EMULATION)
#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--) {
const uint8_t v = *value;
uint8_t * const p = (uint8_t * const)pos;
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*/) {
while (size--) {
uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c;
crc16(crc, &c, 1);
pos++;
value++;
}
return false;
}
#endif // EEPROM_SETTINGS && !(QSPI_EEPROM || FLASH_EEPROM_EMULATION)
#endif // __SAMD51__

View File

@ -0,0 +1,96 @@
/**
* Marlin 3D Printer Firmware
*
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
#if ENABLED(FLASH_EEPROM_EMULATION)
#include "../shared/eeprom_api.h"
#define NVMCTRL_CMD(c) do{ \
SYNC(!NVMCTRL->STATUS.bit.READY); \
NVMCTRL->INTFLAG.bit.DONE = true; \
NVMCTRL->CTRLB.reg = c | NVMCTRL_CTRLB_CMDEX_KEY; \
SYNC(NVMCTRL->INTFLAG.bit.DONE); \
}while(0)
#define NVMCTRL_FLUSH() do{ \
if (NVMCTRL->SEESTAT.bit.LOAD) \
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_SEEFLUSH); \
}while(0)
size_t PersistentStore::capacity() {
const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ,
sblk = NVMCTRL->SEESTAT.bit.SBLK;
return (!psz && !sblk) ? 0
: (psz <= 2) ? (0x200 << psz)
: (sblk == 1 || psz == 3) ? 4096
: (sblk == 2 || psz == 4) ? 8192
: (sblk <= 4 || psz == 5) ? 16384
: (sblk >= 9 && psz == 7) ? 65536
: 32768;
}
bool PersistentStore::access_start() {
NVMCTRL->SEECFG.reg = NVMCTRL_SEECFG_WMODE_BUFFERED; // Buffered mode and segment reallocation active
if (NVMCTRL->SEESTAT.bit.RLOCK)
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_USEE); // Unlock E2P data write access
return true;
}
bool PersistentStore::access_finish() {
NVMCTRL_FLUSH();
if (!NVMCTRL->SEESTAT.bit.LOCK)
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_LSEE); // Lock E2P data write access
return true;
}
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
while (size--) {
const uint8_t v = *value;
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);
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*/) {
while (size--) {
SYNC(NVMCTRL->SEESTAT.bit.BUSY);
uint8_t c = ((volatile uint8_t *)SEEPROM_ADDR)[pos];
if (writing) *value = c;
crc16(crc, &c, 1);
pos++;
value++;
}
return false;
}
#endif // FLASH_EEPROM_EMULATION
#endif // __SAMD51__

View File

@ -0,0 +1,71 @@
/**
* Marlin 3D Printer Firmware
*
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
#if ENABLED(QSPI_EEPROM)
#include "../shared/eeprom_api.h"
#include "QSPIFlash.h"
static bool initialized;
size_t PersistentStore::capacity() { return qspi.size(); }
bool PersistentStore::access_start() {
if (!initialized) {
qspi.begin();
initialized = true;
}
return true;
}
bool PersistentStore::access_finish() {
qspi.flush();
return true;
}
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
while (size--) {
const uint8_t v = *value;
qspi.writeByte(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*/) {
while (size--) {
uint8_t c = qspi.readByte(pos);
if (writing) *value = c;
crc16(crc, &c, 1);
pos++;
value++;
}
return false;
}
#endif // QSPI_EEPROM
#endif // __SAMD51__

View File

@ -21,8 +21,6 @@
*/ */
#pragma once #pragma once
#if USE_EMULATED_EEPROM #if USE_FALLBACK_EEPROM && NONE(SDCARD_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
#undef SRAM_EEPROM_EMULATION
#undef SDCARD_EEPROM_EMULATION
#define FLASH_EEPROM_EMULATION #define FLASH_EEPROM_EMULATION
#endif #endif

View File

@ -1,129 +0,0 @@
/**
* Marlin 3D Printer Firmware
*
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
#if ENABLED(EEPROM_SETTINGS)
#include "../shared/persistent_store_api.h"
#if ENABLED(FLASH_EEPROM_EMULATION)
#define NVMCTRL_CMD(c) do{ \
SYNC(!NVMCTRL->STATUS.bit.READY); \
NVMCTRL->INTFLAG.bit.DONE = true; \
NVMCTRL->CTRLB.reg = c | NVMCTRL_CTRLB_CMDEX_KEY; \
SYNC(NVMCTRL->INTFLAG.bit.DONE); \
}while(0)
#define NVMCTRL_FLUSH() do{ \
if (NVMCTRL->SEESTAT.bit.LOAD) \
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_SEEFLUSH); \
}while(0)
#endif
bool PersistentStore::access_start() {
#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 ENABLED(FLASH_EEPROM_EMULATION)
NVMCTRL_FLUSH();
if (!NVMCTRL->SEESTAT.bit.LOCK)
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_LSEE); // Lock E2P data write access
#endif
return true;
}
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
#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 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);
delay(2);
if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true;
}
}
#endif
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*/) {
while (size--) {
uint8_t c;
#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);
pos++;
value++;
}
return false;
}
size_t PersistentStore::capacity() {
#if ENABLED(FLASH_EEPROM_EMULATION)
const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ,
sblk = NVMCTRL->SEESTAT.bit.SBLK;
if (!psz && !sblk) return 0;
else if (psz <= 2) return (0x200 << psz);
else if (sblk == 1 || psz == 3) return 4096;
else if (sblk == 2 || psz == 4) return 8192;
else if (sblk <= 4 || psz == 5) return 16384;
else if (sblk >= 9 && psz == 7) return 65536;
else return 32768;
#else
return E2END + 1;
#endif
}
#endif // EEPROM_SETTINGS
#endif // __SAMD51__

View File

@ -27,7 +27,7 @@
#if BOTH(EEPROM_SETTINGS, FLASH_EEPROM_EMULATION) #if BOTH(EEPROM_SETTINGS, FLASH_EEPROM_EMULATION)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
// Only STM32F4 can support wear leveling at this time // Only STM32F4 can support wear leveling at this time

View File

@ -24,9 +24,9 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if EITHER(USE_REAL_EEPROM, SRAM_EEPROM_EMULATION) #if EITHER(USE_WIRED_EEPROM, SRAM_EEPROM_EMULATION)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
bool PersistentStore::access_start() { bool PersistentStore::access_start() {
return true; return true;
@ -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 USE_REAL_EEPROM #if USE_WIRED_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 USE_REAL_EEPROM #if USE_WIRED_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,7 +85,7 @@ 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 USE_REAL_EEPROM #if USE_WIRED_EEPROM
E2END + 1 E2END + 1
#else #else
4096 // 4kB 4096 // 4kB
@ -93,5 +93,5 @@ size_t PersistentStore::capacity() {
); );
} }
#endif // USE_REAL_EEPROM || SRAM_EEPROM_EMULATION #endif // USE_WIRED_EEPROM || SRAM_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

View File

@ -30,7 +30,7 @@
#if ENABLED(SDCARD_EEPROM_EMULATION) #if ENABLED(SDCARD_EEPROM_EMULATION)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#ifndef E2END #ifndef E2END
#define E2END 0xFFF // 4KB #define E2END 0xFFF // 4KB

View File

@ -22,6 +22,6 @@
#pragma once #pragma once
// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation // If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
#if ENABLED(EEPROM_SETTINGS) && NONE(USE_REAL_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION) #if ENABLED(EEPROM_SETTINGS) && NONE(USE_WIRED_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
#define SDCARD_EEPROM_EMULATION #define SDCARD_EEPROM_EMULATION
#endif #endif

View File

@ -22,9 +22,9 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if USE_REAL_EEPROM #if USE_WIRED_EEPROM
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
bool PersistentStore::access_start() { bool PersistentStore::access_start() {
#if ENABLED(SPI_EEPROM) #if ENABLED(SPI_EEPROM)
@ -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 // USE_REAL_EEPROM #endif // USE_WIRED_EEPROM
#endif // __STM32F1__ #endif // __STM32F1__

View File

@ -31,10 +31,9 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
// This is for EEPROM emulation in flash #if ENABLED(FLASH_EEPROM_EMULATION)
#if BOTH(EEPROM_SETTINGS, FLASH_EEPROM_EMULATION)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#include <flash_stm32.h> #include <flash_stm32.h>
#include <EEPROM.h> #include <EEPROM.h>
@ -108,5 +107,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
size_t PersistentStore::capacity() { return EEPROM_SIZE; } size_t PersistentStore::capacity() { return EEPROM_SIZE; }
#endif // EEPROM_SETTINGS && EEPROM FLASH #endif // FLASH_EEPROM_EMULATION
#endif // __STM32F1__ #endif // __STM32F1__

View File

@ -31,7 +31,7 @@
#if ENABLED(SDCARD_EEPROM_EMULATION) #if ENABLED(SDCARD_EEPROM_EMULATION)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#ifndef E2END #ifndef E2END
#define E2END 0xFFF // 4KB #define E2END 0xFFF // 4KB
@ -101,5 +101,4 @@ 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 // SDCARD_EEPROM_EMULATION #endif // SDCARD_EEPROM_EMULATION
#endif // __STM32F1__ #endif // __STM32F1__

View File

@ -27,7 +27,7 @@
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
bool PersistentStore::access_start() { return true; } bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }

View File

@ -22,7 +22,7 @@
#pragma once #pragma once
#if ENABLED(EEPROM_SETTINGS) && defined(STM32F7) #if ENABLED(EEPROM_SETTINGS) && defined(STM32F7)
#undef USE_REAL_EEPROM #undef USE_WIRED_EEPROM
#undef SRAM_EEPROM_EMULATION #undef SRAM_EEPROM_EMULATION
#undef SDCARD_EEPROM_EMULATION #undef SDCARD_EEPROM_EMULATION
#define FLASH_EEPROM_EMULATION #define FLASH_EEPROM_EMULATION

View File

@ -22,7 +22,7 @@
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
bool PersistentStore::access_start() { return true; } bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; } bool PersistentStore::access_finish() { return true; }

View File

@ -22,6 +22,6 @@
#pragma once #pragma once
// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation // If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
#if ENABLED(EEPROM_SETTINGS) && NONE(USE_REAL_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION) #if ENABLED(EEPROM_SETTINGS) && NONE(USE_WIRED_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
#define SDCARD_EEPROM_EMULATION #define SDCARD_EEPROM_EMULATION
#endif #endif

View File

@ -27,7 +27,7 @@
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
#include "../shared/persistent_store_api.h" #include "../shared/eeprom_api.h"
#include <avr/eeprom.h> #include <avr/eeprom.h>
bool PersistentStore::access_start() { return true; } bool PersistentStore::access_start() { return true; }

View File

@ -24,7 +24,7 @@
#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE) #if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
#include "persistent_store_api.h" #include "eeprom_api.h"
PersistentStore persistentStore; PersistentStore persistentStore;
#endif #endif

View File

@ -27,7 +27,7 @@
#include "../bedlevel.h" #include "../bedlevel.h"
#include "../../../MarlinCore.h" #include "../../../MarlinCore.h"
#include "../../../HAL/shared/persistent_store_api.h" #include "../../../HAL/shared/eeprom_api.h"
#include "../../../libs/hex_print_routines.h" #include "../../../libs/hex_print_routines.h"
#include "../../../module/configuration_store.h" #include "../../../module/configuration_store.h"
#include "../../../lcd/ultralcd.h" #include "../../../lcd/ultralcd.h"

View File

@ -35,16 +35,19 @@
#define HAS_LINEAR_E_JERK 1 #define HAS_LINEAR_E_JERK 1
#endif #endif
// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation // Determine which type of 'EEPROM' is in use
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
#if NONE(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SDCARD_EEPROM_EMULATION) && EITHER(I2C_EEPROM, SPI_EEPROM) // EEPROM type may be defined by compile flags, configs, HALs, or pins
#define USE_REAL_EEPROM 1 // Set additional flags to let HALs choose in their Conditionals_post.h
#if NONE(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SDCARD_EEPROM_EMULATION) && ANY(I2C_EEPROM, SPI_EEPROM, QSPI_EEPROM)
#define USE_WIRED_EEPROM 1
#else #else
#define USE_EMULATED_EEPROM 1 #define USE_FALLBACK_EEPROM 1
#endif #endif
#else #else
#undef I2C_EEPROM #undef I2C_EEPROM
#undef SPI_EEPROM #undef SPI_EEPROM
#undef QSPI_EEPROM
#undef SDCARD_EEPROM_EMULATION #undef SDCARD_EEPROM_EMULATION
#undef SRAM_EEPROM_EMULATION #undef SRAM_EEPROM_EMULATION
#undef FLASH_EEPROM_EMULATION #undef FLASH_EEPROM_EMULATION

View File

@ -252,7 +252,7 @@ void InterfaceSettingsScreen::loadSettings(const char *buff) {
} }
#ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE #ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE
#include "../../../../../HAL/shared/persistent_store_api.h" #include "../../../../../HAL/shared/eeprom_api.h"
bool restoreEEPROM() { bool restoreEEPROM() {
uint8_t data[ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE]; uint8_t data[ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE];

View File

@ -57,7 +57,7 @@
#include "../MarlinCore.h" #include "../MarlinCore.h"
#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE) #if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
#include "../HAL/shared/persistent_store_api.h" #include "../HAL/shared/eeprom_api.h"
#endif #endif
#include "probe.h" #include "probe.h"

View File

@ -24,7 +24,7 @@
#include "../inc/MarlinConfig.h" #include "../inc/MarlinConfig.h"
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
#include "../HAL/shared/persistent_store_api.h" #include "../HAL/shared/eeprom_api.h"
#endif #endif
class MarlinSettings { class MarlinSettings {

View File

@ -35,7 +35,7 @@ Stopwatch print_job_timer; // Global Print Job Timer instance
#include "printcounter.h" #include "printcounter.h"
#include "../MarlinCore.h" #include "../MarlinCore.h"
#include "../HAL/shared/persistent_store_api.h" #include "../HAL/shared/eeprom_api.h"
#if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0 #if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0
#include "../libs/buzzer.h" #include "../libs/buzzer.h"

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 USE_REAL_EEPROM #if USE_WIRED_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 USE_REAL_EEPROM || defined(CPU_32_BIT) #if USE_WIRED_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

@ -44,8 +44,9 @@
// //
// EEPROM // EEPROM
// //
#define E2END 0x7FFF // 32Kb (24lc256) //#define QSPI_EEPROM // Use AGCM4 onboard QSPI EEPROM (Uses 4K of RAM)
#define I2C_EEPROM // EEPROM on I2C-0 #define I2C_EEPROM // EEPROM on I2C-0
#define E2END 0x7FFF // 32K (24lc256)
// //
// Limit Switches // Limit Switches

View File

@ -792,6 +792,7 @@ build_unflags = -std=gnu++11
src_filter = ${common.default_src_filter} +<src/HAL/SAMD51> src_filter = ${common.default_src_filter} +<src/HAL/SAMD51>
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
SoftwareSerialM=https://github.com/FYSETC/SoftwareSerialM/archive/master.zip SoftwareSerialM=https://github.com/FYSETC/SoftwareSerialM/archive/master.zip
Adafruit_SPIFlash=https://github.com/adafruit/Adafruit_SPIFlash/archive/master.zip
debug_tool = jlink debug_tool = jlink
# #