Use MARLIN_EEPROM_SIZE with E2END as fallback (#18059)
This commit is contained in:
@ -32,7 +32,7 @@
|
||||
#include "Servo.h"
|
||||
#define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos()
|
||||
#define RESUME_SERVO_OUTPUT() libServo::resume_all_servos()
|
||||
#else
|
||||
#else
|
||||
#define PAUSE_SERVO_OUTPUT()
|
||||
#define RESUME_SERVO_OUTPUT()
|
||||
#endif
|
||||
@ -59,8 +59,8 @@
|
||||
#define DEBUG_OUT ENABLED(EEPROM_CHITCHAT)
|
||||
#include "src/core/debug_out.h"
|
||||
|
||||
#ifndef EEPROM_SIZE
|
||||
#define EEPROM_SIZE 0x1000 // 4kB
|
||||
#ifndef MARLIN_EEPROM_SIZE
|
||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||
#endif
|
||||
|
||||
#ifndef FLASH_SECTOR
|
||||
@ -70,11 +70,11 @@
|
||||
#define FLASH_UNIT_SIZE 0x20000 // 128kB
|
||||
#endif
|
||||
|
||||
#define FLASH_ADDRESS_START (FLASH_END - ((FLASH_SECTOR_TOTAL - FLASH_SECTOR) * FLASH_UNIT_SIZE) + 1)
|
||||
#define FLASH_ADDRESS_START (FLASH_END - ((FLASH_SECTOR_TOTAL - (FLASH_SECTOR)) * (FLASH_UNIT_SIZE)) + 1)
|
||||
#define FLASH_ADDRESS_END (FLASH_ADDRESS_START + FLASH_UNIT_SIZE - 1)
|
||||
|
||||
#define EEPROM_SLOTS (FLASH_UNIT_SIZE/EEPROM_SIZE)
|
||||
#define SLOT_ADDRESS(slot) (FLASH_ADDRESS_START + (slot * EEPROM_SIZE))
|
||||
#define EEPROM_SLOTS ((FLASH_UNIT_SIZE) / (MARLIN_EEPROM_SIZE))
|
||||
#define SLOT_ADDRESS(slot) (FLASH_ADDRESS_START + (slot * (MARLIN_EEPROM_SIZE)))
|
||||
|
||||
#define UNLOCK_FLASH() if (!flash_unlocked) { \
|
||||
HAL_FLASH_Unlock(); \
|
||||
@ -87,12 +87,12 @@
|
||||
#define EMPTY_UINT32 ((uint32_t)-1)
|
||||
#define EMPTY_UINT8 ((uint8_t)-1)
|
||||
|
||||
static uint8_t ram_eeprom[EEPROM_SIZE] __attribute__((aligned(4))) = {0};
|
||||
static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
|
||||
static int current_slot = -1;
|
||||
|
||||
static_assert(0 == EEPROM_SIZE % 4, "EEPROM_SIZE must be a multiple of 4"); // Ensure copying as uint32_t is safe
|
||||
static_assert(0 == FLASH_UNIT_SIZE % EEPROM_SIZE, "EEPROM_SIZE must divide evenly into your FLASH_UNIT_SIZE");
|
||||
static_assert(FLASH_UNIT_SIZE >= EEPROM_SIZE, "FLASH_UNIT_SIZE must be greater than or equal to your EEPROM_SIZE");
|
||||
static_assert(0 == MARLIN_EEPROM_SIZE % 4, "MARLIN_EEPROM_SIZE must be a multiple of 4"); // Ensure copying as uint32_t is safe
|
||||
static_assert(0 == FLASH_UNIT_SIZE % MARLIN_EEPROM_SIZE, "MARLIN_EEPROM_SIZE must divide evenly into your FLASH_UNIT_SIZE");
|
||||
static_assert(FLASH_UNIT_SIZE >= MARLIN_EEPROM_SIZE, "FLASH_UNIT_SIZE must be greater than or equal to your MARLIN_EEPROM_SIZE");
|
||||
static_assert(IS_FLASH_SECTOR(FLASH_SECTOR), "FLASH_SECTOR is invalid");
|
||||
static_assert(IS_POWER_OF_2(FLASH_UNIT_SIZE), "FLASH_UNIT_SIZE should be a power of 2, please check your chip's spec sheet");
|
||||
|
||||
@ -100,6 +100,11 @@
|
||||
|
||||
static bool eeprom_data_written = false;
|
||||
|
||||
#ifndef MARLIN_EEPROM_SIZE
|
||||
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
||||
#endif
|
||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
||||
|
||||
bool PersistentStore::access_start() {
|
||||
|
||||
#if ENABLED(FLASH_EEPROM_LEVELING)
|
||||
@ -113,20 +118,20 @@ bool PersistentStore::access_start() {
|
||||
while (address <= FLASH_ADDRESS_END) {
|
||||
uint32_t address_value = (*(__IO uint32_t*)address);
|
||||
if (address_value != EMPTY_UINT32) {
|
||||
current_slot = (address - FLASH_ADDRESS_START) / EEPROM_SIZE;
|
||||
current_slot = (address - (FLASH_ADDRESS_START)) / (MARLIN_EEPROM_SIZE);
|
||||
break;
|
||||
}
|
||||
address += sizeof(uint32_t);
|
||||
}
|
||||
if (current_slot == -1) {
|
||||
// We didn't find anything, so we'll just intialize to empty
|
||||
for (int i = 0; i < EEPROM_SIZE; i++) ram_eeprom[i] = EMPTY_UINT8;
|
||||
for (int i = 0; i < MARLIN_EEPROM_SIZE; i++) ram_eeprom[i] = EMPTY_UINT8;
|
||||
current_slot = EEPROM_SLOTS;
|
||||
}
|
||||
else {
|
||||
// load current settings
|
||||
uint8_t *eeprom_data = (uint8_t *)SLOT_ADDRESS(current_slot);
|
||||
for (int i = 0; i < EEPROM_SIZE; i++) ram_eeprom[i] = eeprom_data[i];
|
||||
for (int i = 0; i < MARLIN_EEPROM_SIZE; i++) ram_eeprom[i] = eeprom_data[i];
|
||||
DEBUG_ECHOLNPAIR("EEPROM loaded from slot ", current_slot, ".");
|
||||
}
|
||||
eeprom_data_written = false;
|
||||
@ -146,7 +151,7 @@ bool PersistentStore::access_finish() {
|
||||
// MCU may come up with flash error bits which prevent some flash operations.
|
||||
// Clear flags prior to flash operations to prevent errors.
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ENABLED(FLASH_EEPROM_LEVELING)
|
||||
|
||||
@ -185,7 +190,7 @@ bool PersistentStore::access_finish() {
|
||||
|
||||
uint32_t offset = 0;
|
||||
uint32_t address = SLOT_ADDRESS(current_slot);
|
||||
uint32_t address_end = address + EEPROM_SIZE;
|
||||
uint32_t address_end = address + MARLIN_EEPROM_SIZE;
|
||||
uint32_t data = 0;
|
||||
|
||||
bool success = true;
|
||||
@ -267,9 +272,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t PersistentStore::capacity() {
|
||||
return TERN(FLASH_EEPROM_LEVELING, EEPROM_SIZE, E2END + 1);
|
||||
}
|
||||
|
||||
#endif // FLASH_EEPROM_EMULATION
|
||||
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
|
||||
|
@ -31,53 +31,44 @@
|
||||
#if ENABLED(SDCARD_EEPROM_EMULATION)
|
||||
|
||||
#include "../shared/eeprom_api.h"
|
||||
#include "../../sd/cardreader.h"
|
||||
|
||||
#ifndef E2END
|
||||
#define E2END 0xFFF // 4KB
|
||||
#define EEPROM_FILENAME "eeprom.dat"
|
||||
|
||||
#ifndef MARLIN_EEPROM_SIZE
|
||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||
#endif
|
||||
#define HAL_EEPROM_SIZE int(E2END + 1)
|
||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
||||
|
||||
#define _ALIGN(x) __attribute__ ((aligned(x)))
|
||||
static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
|
||||
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
bool PersistentStore::access_start() {
|
||||
if (!card.isMounted()) return false;
|
||||
|
||||
#include "../../sd/cardreader.h"
|
||||
|
||||
#define EEPROM_FILENAME "eeprom.dat"
|
||||
|
||||
bool PersistentStore::access_start() {
|
||||
if (!card.isMounted()) return false;
|
||||
|
||||
SdFile file, root = card.getroot();
|
||||
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
|
||||
return true;
|
||||
|
||||
int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
||||
if (bytes_read < 0) return false;
|
||||
for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
|
||||
HAL_eeprom_data[bytes_read] = 0xFF;
|
||||
file.close();
|
||||
SdFile file, root = card.getroot();
|
||||
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
|
||||
return true;
|
||||
|
||||
int bytes_read = file.read(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
|
||||
if (bytes_read < 0) return false;
|
||||
for (; bytes_read < MARLIN_EEPROM_SIZE; bytes_read++)
|
||||
HAL_eeprom_data[bytes_read] = 0xFF;
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PersistentStore::access_finish() {
|
||||
if (!card.isMounted()) return false;
|
||||
|
||||
SdFile file, root = card.getroot();
|
||||
int bytes_written = 0;
|
||||
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
|
||||
bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
|
||||
file.close();
|
||||
}
|
||||
|
||||
bool PersistentStore::access_finish() {
|
||||
if (!card.isMounted()) return false;
|
||||
|
||||
SdFile file, root = card.getroot();
|
||||
int bytes_written = 0;
|
||||
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
|
||||
bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
||||
file.close();
|
||||
}
|
||||
return (bytes_written == HAL_EEPROM_SIZE);
|
||||
}
|
||||
|
||||
#else // !SDSUPPORT
|
||||
|
||||
#error "Please define an EEPROM, a SDCARD or disable EEPROM_SETTINGS."
|
||||
|
||||
#endif // !SDSUPPORT
|
||||
return (bytes_written == MARLIN_EEPROM_SIZE);
|
||||
}
|
||||
|
||||
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||
for (size_t i = 0; i < size; i++)
|
||||
@ -97,7 +88,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; }
|
||||
|
||||
#endif // SDCARD_EEPROM_EMULATION
|
||||
#endif // STM32 && !STM32GENERIC
|
||||
|
@ -29,7 +29,11 @@
|
||||
#include "../shared/eeprom_if.h"
|
||||
#include "../shared/eeprom_api.h"
|
||||
|
||||
size_t PersistentStore::capacity() { return 4096; } // 4K of SRAM
|
||||
#ifndef MARLIN_EEPROM_SIZE
|
||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||
#endif
|
||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
||||
|
||||
bool PersistentStore::access_start() { return true; }
|
||||
bool PersistentStore::access_finish() { return true; }
|
||||
|
||||
|
@ -34,13 +34,13 @@
|
||||
#include "../shared/eeprom_if.h"
|
||||
#include "../shared/eeprom_api.h"
|
||||
|
||||
size_t PersistentStore::capacity() { return E2END + 1; }
|
||||
bool PersistentStore::access_finish() { return true; }
|
||||
#ifndef MARLIN_EEPROM_SIZE
|
||||
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
||||
#endif
|
||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
||||
|
||||
bool PersistentStore::access_start() {
|
||||
eeprom_init();
|
||||
return true;
|
||||
}
|
||||
bool PersistentStore::access_start() { eeprom_init(); 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--) {
|
||||
|
Reference in New Issue
Block a user