浏览代码

Add FIELD_TEST to validate storage

Scott Lahteine 7 年前
父节点
当前提交
950be70a33
共有 1 个文件被更改,包括 36 次插入4 次删除
  1. 36
    4
      Marlin/src/module/configuration_store.cpp

+ 36
- 4
Marlin/src/module/configuration_store.cpp 查看文件

40
 #define EEPROM_VERSION "V48"
40
 #define EEPROM_VERSION "V48"
41
 #define EEPROM_OFFSET 100
41
 #define EEPROM_OFFSET 100
42
 
42
 
43
+// Check the integrity of data offsets.
44
+// Can be disabled for production build.
45
+//#define DEBUG_EEPROM_READWRITE
46
+
43
 #include "configuration_store.h"
47
 #include "configuration_store.h"
44
 #include "endstops.h"
48
 #include "endstops.h"
45
 #include "planner.h"
49
 #include "planner.h"
323
   #define EEPROM_WRITE(VAR) HAL::PersistentStore::write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
327
   #define EEPROM_WRITE(VAR) HAL::PersistentStore::write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
324
   #define EEPROM_READ(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, !validating)
328
   #define EEPROM_READ(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, !validating)
325
   #define EEPROM_READ_ALWAYS(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
329
   #define EEPROM_READ_ALWAYS(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
326
-  #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
330
+  #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_error = true; }while(0)
331
+
332
+  #if ENABLED(DEBUG_EEPROM_READWRITE)
333
+    #define _FIELD_TEST(FIELD)                                          \
334
+      EEPROM_ASSERT(                                                    \
335
+        eeprom_error || eeprom_index == offsetof(SettingsData, FIELD),  \
336
+        "Field " STRINGIFY(FIELD) " mismatch."                          \
337
+      )
338
+  #else
339
+    #define _FIELD_TEST(FIELD) NOOP
340
+  #endif
327
 
341
 
328
   const char version[4] = EEPROM_VERSION;
342
   const char version[4] = EEPROM_VERSION;
329
 
343
 
363
 
377
 
364
     working_crc = 0; // clear before first "real data"
378
     working_crc = 0; // clear before first "real data"
365
 
379
 
380
+    _FIELD_TEST(esteppers);
381
+
366
     const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
382
     const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
367
     EEPROM_WRITE(esteppers);
383
     EEPROM_WRITE(esteppers);
368
 
384
 
377
     EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
393
     EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
378
     EEPROM_WRITE(planner.min_segment_time_us);
394
     EEPROM_WRITE(planner.min_segment_time_us);
379
     EEPROM_WRITE(planner.max_jerk);
395
     EEPROM_WRITE(planner.max_jerk);
396
+
397
+    _FIELD_TEST(home_offset);
398
+
380
     #if !HAS_HOME_OFFSET
399
     #if !HAS_HOME_OFFSET
381
       const float home_offset[XYZ] = { 0 };
400
       const float home_offset[XYZ] = { 0 };
382
     #endif
401
     #endif
426
       for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummy);
445
       for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummy);
427
     #endif // MESH_BED_LEVELING
446
     #endif // MESH_BED_LEVELING
428
 
447
 
448
+    _FIELD_TEST(zprobe_zoffset);
449
+
429
     #if !HAS_BED_PROBE
450
     #if !HAS_BED_PROBE
430
       const float zprobe_zoffset = 0;
451
       const float zprobe_zoffset = 0;
431
     #endif
452
     #endif
470
       for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
491
       for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
471
     #endif // AUTO_BED_LEVELING_BILINEAR
492
     #endif // AUTO_BED_LEVELING_BILINEAR
472
 
493
 
494
+    _FIELD_TEST(planner_leveling_active);
495
+
473
     #if ENABLED(AUTO_BED_LEVELING_UBL)
496
     #if ENABLED(AUTO_BED_LEVELING_UBL)
474
       EEPROM_WRITE(planner.leveling_active);
497
       EEPROM_WRITE(planner.leveling_active);
475
       EEPROM_WRITE(ubl.storage_slot);
498
       EEPROM_WRITE(ubl.storage_slot);
482
 
505
 
483
     // 11 floats for DELTA / [XYZ]_DUAL_ENDSTOPS
506
     // 11 floats for DELTA / [XYZ]_DUAL_ENDSTOPS
484
     #if ENABLED(DELTA)
507
     #if ENABLED(DELTA)
508
+      _FIELD_TEST(delta_height);
485
       EEPROM_WRITE(delta_height);              // 1 float
509
       EEPROM_WRITE(delta_height);              // 1 float
486
       EEPROM_WRITE(delta_endstop_adj);         // 3 floats
510
       EEPROM_WRITE(delta_endstop_adj);         // 3 floats
487
       EEPROM_WRITE(delta_radius);              // 1 float
511
       EEPROM_WRITE(delta_radius);              // 1 float
491
       EEPROM_WRITE(delta_tower_angle_trim);    // 3 floats
515
       EEPROM_WRITE(delta_tower_angle_trim);    // 3 floats
492
 
516
 
493
     #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
517
     #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
518
+      _FIELD_TEST(x_endstop_adj);
494
       // Write dual endstops in X, Y, Z order. Unused = 0.0
519
       // Write dual endstops in X, Y, Z order. Unused = 0.0
495
       dummy = 0.0f;
520
       dummy = 0.0f;
496
       #if ENABLED(X_DUAL_ENDSTOPS)
521
       #if ENABLED(X_DUAL_ENDSTOPS)
518
       for (uint8_t q = 11; q--;) EEPROM_WRITE(dummy);
543
       for (uint8_t q = 11; q--;) EEPROM_WRITE(dummy);
519
     #endif
544
     #endif
520
 
545
 
546
+    _FIELD_TEST(lcd_preheat_hotend_temp);
547
+
521
     #if DISABLED(ULTIPANEL)
548
     #if DISABLED(ULTIPANEL)
522
       constexpr int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
549
       constexpr int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
523
                     lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
550
                     lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
567
       EEPROM_WRITE(thermalManager.bedKd);
594
       EEPROM_WRITE(thermalManager.bedKd);
568
     #endif
595
     #endif
569
 
596
 
597
+    _FIELD_TEST(lcd_contrast);
598
+
570
     #if !HAS_LCD_CONTRAST
599
     #if !HAS_LCD_CONTRAST
571
       const uint16_t lcd_contrast = 32;
600
       const uint16_t lcd_contrast = 32;
572
     #endif
601
     #endif
592
     //
621
     //
593
     // Volumetric & Filament Size
622
     // Volumetric & Filament Size
594
     //
623
     //
624
+    _FIELD_TEST(parser_volumetric_enabled);
595
     #if DISABLED(NO_VOLUMETRICS)
625
     #if DISABLED(NO_VOLUMETRICS)
596
 
626
 
597
       EEPROM_WRITE(parser.volumetric_enabled);
627
       EEPROM_WRITE(parser.volumetric_enabled);
614
     //
644
     //
615
     // Save TMC2130 or TMC2208 Configuration, and placeholder values
645
     // Save TMC2130 or TMC2208 Configuration, and placeholder values
616
     //
646
     //
647
+    _FIELD_TEST(tmc_stepper_current);
617
     uint16_t currents[11] = {
648
     uint16_t currents[11] = {
618
       #if HAS_TRINAMIC
649
       #if HAS_TRINAMIC
619
         #if X_IS_TRINAMIC
650
         #if X_IS_TRINAMIC
702
     //
733
     //
703
     // Linear Advance
734
     // Linear Advance
704
     //
735
     //
705
-
736
+    _FIELD_TEST(planner_extruder_advance_k);
706
     #if ENABLED(LIN_ADVANCE)
737
     #if ENABLED(LIN_ADVANCE)
707
       EEPROM_WRITE(planner.extruder_advance_k);
738
       EEPROM_WRITE(planner.extruder_advance_k);
708
       EEPROM_WRITE(planner.advance_ed_ratio);
739
       EEPROM_WRITE(planner.advance_ed_ratio);
722
     //
753
     //
723
     // CNC Coordinate Systems
754
     // CNC Coordinate Systems
724
     //
755
     //
725
-
756
+    _FIELD_TEST(coordinate_system);
726
     #if ENABLED(CNC_COORDINATE_SYSTEMS)
757
     #if ENABLED(CNC_COORDINATE_SYSTEMS)
727
       EEPROM_WRITE(coordinate_system); // 27 floats
758
       EEPROM_WRITE(coordinate_system); // 27 floats
728
     #else
759
     #else
733
     //
764
     //
734
     // Skew correction factors
765
     // Skew correction factors
735
     //
766
     //
736
-
767
+    _FIELD_TEST(planner_xy_skew_factor);
737
     #if ENABLED(SKEW_CORRECTION)
768
     #if ENABLED(SKEW_CORRECTION)
738
       EEPROM_WRITE(planner.xy_skew_factor);
769
       EEPROM_WRITE(planner.xy_skew_factor);
739
       EEPROM_WRITE(planner.xz_skew_factor);
770
       EEPROM_WRITE(planner.xz_skew_factor);
746
     //
777
     //
747
     // Advanced Pause filament load & unload lengths
778
     // Advanced Pause filament load & unload lengths
748
     //
779
     //
780
+    _FIELD_TEST(filament_change_unload_length);
749
     #if ENABLED(ADVANCED_PAUSE_FEATURE)
781
     #if ENABLED(ADVANCED_PAUSE_FEATURE)
750
       for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
782
       for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
751
         if (q < COUNT(filament_change_unload_length)) dummy = filament_change_unload_length[q];
783
         if (q < COUNT(filament_change_unload_length)) dummy = filament_change_unload_length[q];

正在加载...
取消
保存