mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-30 23:30:16 +00:00
Add FIELD_TEST to validate storage
This commit is contained in:
parent
5d26f88bd5
commit
3b3b7e09ec
@ -40,6 +40,10 @@
|
|||||||
#define EEPROM_VERSION "V48"
|
#define EEPROM_VERSION "V48"
|
||||||
#define EEPROM_OFFSET 100
|
#define EEPROM_OFFSET 100
|
||||||
|
|
||||||
|
// Check the integrity of data offsets.
|
||||||
|
// Can be disabled for production build.
|
||||||
|
//#define DEBUG_EEPROM_READWRITE
|
||||||
|
|
||||||
#include "configuration_store.h"
|
#include "configuration_store.h"
|
||||||
#include "Marlin.h"
|
#include "Marlin.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
@ -321,7 +325,17 @@ void MarlinSettings::postprocess() {
|
|||||||
#define EEPROM_WRITE(VAR) write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
|
#define EEPROM_WRITE(VAR) write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
|
||||||
#define EEPROM_READ(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
|
#define EEPROM_READ(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
|
||||||
#define EEPROM_READ_ALWAYS(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, true)
|
#define EEPROM_READ_ALWAYS(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, true)
|
||||||
#define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
|
#define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_error = true; }while(0)
|
||||||
|
|
||||||
|
#if ENABLED(DEBUG_EEPROM_READWRITE)
|
||||||
|
#define _FIELD_TEST(FIELD) \
|
||||||
|
EEPROM_ASSERT( \
|
||||||
|
eeprom_error || eeprom_index == offsetof(SettingsData, FIELD), \
|
||||||
|
"Field " STRINGIFY(FIELD) " mismatch." \
|
||||||
|
)
|
||||||
|
#else
|
||||||
|
#define _FIELD_TEST(FIELD) NOOP
|
||||||
|
#endif
|
||||||
|
|
||||||
const char version[4] = EEPROM_VERSION;
|
const char version[4] = EEPROM_VERSION;
|
||||||
|
|
||||||
@ -391,6 +405,8 @@ void MarlinSettings::postprocess() {
|
|||||||
|
|
||||||
working_crc = 0; // clear before first "real data"
|
working_crc = 0; // clear before first "real data"
|
||||||
|
|
||||||
|
_FIELD_TEST(esteppers);
|
||||||
|
|
||||||
const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
|
const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
|
||||||
EEPROM_WRITE(esteppers);
|
EEPROM_WRITE(esteppers);
|
||||||
|
|
||||||
@ -405,6 +421,9 @@ void MarlinSettings::postprocess() {
|
|||||||
EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
|
EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
|
||||||
EEPROM_WRITE(planner.min_segment_time_us);
|
EEPROM_WRITE(planner.min_segment_time_us);
|
||||||
EEPROM_WRITE(planner.max_jerk);
|
EEPROM_WRITE(planner.max_jerk);
|
||||||
|
|
||||||
|
_FIELD_TEST(home_offset);
|
||||||
|
|
||||||
#if !HAS_HOME_OFFSET
|
#if !HAS_HOME_OFFSET
|
||||||
const float home_offset[XYZ] = { 0 };
|
const float home_offset[XYZ] = { 0 };
|
||||||
#endif
|
#endif
|
||||||
@ -454,6 +473,8 @@ void MarlinSettings::postprocess() {
|
|||||||
for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummy);
|
for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummy);
|
||||||
#endif // MESH_BED_LEVELING
|
#endif // MESH_BED_LEVELING
|
||||||
|
|
||||||
|
_FIELD_TEST(zprobe_zoffset);
|
||||||
|
|
||||||
#if !HAS_BED_PROBE
|
#if !HAS_BED_PROBE
|
||||||
const float zprobe_zoffset = 0;
|
const float zprobe_zoffset = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -498,6 +519,8 @@ void MarlinSettings::postprocess() {
|
|||||||
for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
|
for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
|
||||||
#endif // AUTO_BED_LEVELING_BILINEAR
|
#endif // AUTO_BED_LEVELING_BILINEAR
|
||||||
|
|
||||||
|
_FIELD_TEST(planner_leveling_active);
|
||||||
|
|
||||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||||
EEPROM_WRITE(planner.leveling_active);
|
EEPROM_WRITE(planner.leveling_active);
|
||||||
EEPROM_WRITE(ubl.storage_slot);
|
EEPROM_WRITE(ubl.storage_slot);
|
||||||
@ -510,6 +533,7 @@ void MarlinSettings::postprocess() {
|
|||||||
|
|
||||||
// 11 floats for DELTA / [XYZ]_DUAL_ENDSTOPS
|
// 11 floats for DELTA / [XYZ]_DUAL_ENDSTOPS
|
||||||
#if ENABLED(DELTA)
|
#if ENABLED(DELTA)
|
||||||
|
_FIELD_TEST(delta_height);
|
||||||
EEPROM_WRITE(delta_height); // 1 float
|
EEPROM_WRITE(delta_height); // 1 float
|
||||||
EEPROM_WRITE(delta_endstop_adj); // 3 floats
|
EEPROM_WRITE(delta_endstop_adj); // 3 floats
|
||||||
EEPROM_WRITE(delta_radius); // 1 float
|
EEPROM_WRITE(delta_radius); // 1 float
|
||||||
@ -519,6 +543,7 @@ void MarlinSettings::postprocess() {
|
|||||||
EEPROM_WRITE(delta_tower_angle_trim); // 3 floats
|
EEPROM_WRITE(delta_tower_angle_trim); // 3 floats
|
||||||
|
|
||||||
#elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
|
#elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
|
||||||
|
_FIELD_TEST(x_endstop_adj);
|
||||||
// Write dual endstops in X, Y, Z order. Unused = 0.0
|
// Write dual endstops in X, Y, Z order. Unused = 0.0
|
||||||
dummy = 0.0f;
|
dummy = 0.0f;
|
||||||
#if ENABLED(X_DUAL_ENDSTOPS)
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
||||||
@ -546,6 +571,8 @@ void MarlinSettings::postprocess() {
|
|||||||
for (uint8_t q = 11; q--;) EEPROM_WRITE(dummy);
|
for (uint8_t q = 11; q--;) EEPROM_WRITE(dummy);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
_FIELD_TEST(lcd_preheat_hotend_temp);
|
||||||
|
|
||||||
#if DISABLED(ULTIPANEL)
|
#if DISABLED(ULTIPANEL)
|
||||||
constexpr int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
|
constexpr int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
|
||||||
lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
|
lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
|
||||||
@ -595,6 +622,8 @@ void MarlinSettings::postprocess() {
|
|||||||
EEPROM_WRITE(thermalManager.bedKd);
|
EEPROM_WRITE(thermalManager.bedKd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
_FIELD_TEST(lcd_contrast);
|
||||||
|
|
||||||
#if !HAS_LCD_CONTRAST
|
#if !HAS_LCD_CONTRAST
|
||||||
const uint16_t lcd_contrast = 32;
|
const uint16_t lcd_contrast = 32;
|
||||||
#endif
|
#endif
|
||||||
@ -620,6 +649,7 @@ void MarlinSettings::postprocess() {
|
|||||||
//
|
//
|
||||||
// Volumetric & Filament Size
|
// Volumetric & Filament Size
|
||||||
//
|
//
|
||||||
|
_FIELD_TEST(parser_volumetric_enabled);
|
||||||
#if DISABLED(NO_VOLUMETRICS)
|
#if DISABLED(NO_VOLUMETRICS)
|
||||||
|
|
||||||
EEPROM_WRITE(parser.volumetric_enabled);
|
EEPROM_WRITE(parser.volumetric_enabled);
|
||||||
@ -642,6 +672,7 @@ void MarlinSettings::postprocess() {
|
|||||||
//
|
//
|
||||||
// Save TMC2130 or TMC2208 Configuration, and placeholder values
|
// Save TMC2130 or TMC2208 Configuration, and placeholder values
|
||||||
//
|
//
|
||||||
|
_FIELD_TEST(tmc_stepper_current);
|
||||||
uint16_t currents[11] = {
|
uint16_t currents[11] = {
|
||||||
#if HAS_TRINAMIC
|
#if HAS_TRINAMIC
|
||||||
#if X_IS_TRINAMIC
|
#if X_IS_TRINAMIC
|
||||||
@ -730,7 +761,7 @@ void MarlinSettings::postprocess() {
|
|||||||
//
|
//
|
||||||
// Linear Advance
|
// Linear Advance
|
||||||
//
|
//
|
||||||
|
_FIELD_TEST(planner_extruder_advance_k);
|
||||||
#if ENABLED(LIN_ADVANCE)
|
#if ENABLED(LIN_ADVANCE)
|
||||||
EEPROM_WRITE(planner.extruder_advance_k);
|
EEPROM_WRITE(planner.extruder_advance_k);
|
||||||
EEPROM_WRITE(planner.advance_ed_ratio);
|
EEPROM_WRITE(planner.advance_ed_ratio);
|
||||||
@ -750,7 +781,7 @@ void MarlinSettings::postprocess() {
|
|||||||
//
|
//
|
||||||
// CNC Coordinate Systems
|
// CNC Coordinate Systems
|
||||||
//
|
//
|
||||||
|
_FIELD_TEST(coordinate_system);
|
||||||
#if ENABLED(CNC_COORDINATE_SYSTEMS)
|
#if ENABLED(CNC_COORDINATE_SYSTEMS)
|
||||||
EEPROM_WRITE(coordinate_system); // 27 floats
|
EEPROM_WRITE(coordinate_system); // 27 floats
|
||||||
#else
|
#else
|
||||||
@ -761,7 +792,7 @@ void MarlinSettings::postprocess() {
|
|||||||
//
|
//
|
||||||
// Skew correction factors
|
// Skew correction factors
|
||||||
//
|
//
|
||||||
|
_FIELD_TEST(planner_xy_skew_factor);
|
||||||
#if ENABLED(SKEW_CORRECTION)
|
#if ENABLED(SKEW_CORRECTION)
|
||||||
EEPROM_WRITE(planner.xy_skew_factor);
|
EEPROM_WRITE(planner.xy_skew_factor);
|
||||||
EEPROM_WRITE(planner.xz_skew_factor);
|
EEPROM_WRITE(planner.xz_skew_factor);
|
||||||
@ -774,6 +805,7 @@ void MarlinSettings::postprocess() {
|
|||||||
//
|
//
|
||||||
// Advanced Pause filament load & unload lengths
|
// Advanced Pause filament load & unload lengths
|
||||||
//
|
//
|
||||||
|
_FIELD_TEST(filament_change_unload_length);
|
||||||
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
||||||
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
|
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
|
||||||
if (q < COUNT(filament_change_unload_length)) dummy = filament_change_unload_length[q];
|
if (q < COUNT(filament_change_unload_length)) dummy = filament_change_unload_length[q];
|
||||||
|
Loading…
Reference in New Issue
Block a user