Browse Source

Add MarlinSettings::validate()

Scott Lahteine 6 years ago
parent
commit
51e0f2bee3

+ 2
- 2
Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp View File

@@ -38,10 +38,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
38 38
   return false;
39 39
 }
40 40
 
41
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
41
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
42 42
   do {
43 43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
44
-    *value = c;
44
+    if (writing) *value = c;
45 45
     crc16(crc, &c, 1);
46 46
     pos++;
47 47
     value++;

+ 2
- 2
Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp View File

@@ -43,10 +43,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
43 43
   return false;
44 44
 }
45 45
 
46
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
46
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
47 47
   do {
48 48
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
49
-    *value = c;
49
+    if (writing) *value = c;
50 50
     crc16(crc, &c, 1);
51 51
     pos++;
52 52
     value++;

+ 10
- 3
Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp View File

@@ -128,7 +128,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
128 128
   return (bytes_written != size);  // return true for any error
129 129
 }
130 130
 
131
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
131
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
132 132
   UINT bytes_read = 0;
133 133
   FRESULT s;
134 134
   s = f_lseek(&eeprom_file, pos);
@@ -140,7 +140,15 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
140 140
    SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
141 141
    return true;
142 142
   }
143
-  s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
143
+  if (writing) {
144
+    s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
145
+    crc16(crc, value, size);
146
+  }
147
+  else {
148
+    uint8_t temp[size];
149
+    s = f_read(&eeprom_file, (void *)temp, size, &bytes_read);
150
+    crc16(crc, temp, size);
151
+  }
144 152
   if (s) {
145 153
    SERIAL_PROTOCOLPAIR(" read_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
146 154
    SERIAL_PROTOCOLPAIR(",", (int)value);           // right now to see errors that are happening in the
@@ -151,7 +159,6 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
151 159
    SERIAL_PROTOCOLLNPAIR("\n bytes_read=",  bytes_read);
152 160
    return true;
153 161
   }
154
-  crc16(crc, value, size);
155 162
   pos = pos + size;
156 163
   return bytes_read != size;  // return true for any error
157 164
 }

+ 4
- 4
Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp View File

@@ -93,13 +93,13 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
93 93
   return true;
94 94
 }
95 95
 
96
-void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
96
+void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
97 97
   for (uint16_t i = 0; i < size; i++) {
98 98
     byte* accessPoint = (byte*)(pageBase + pos + i);
99
-    value[i] = *accessPoint;
99
+    uint8_t c = *accessPoint;
100
+    if (writing) value[i] = c;
101
+    crc16(crc, &c, 1);
100 102
   }
101
-
102
-  crc16(crc, value, size);
103 103
   pos += ((size + 1) & ~1);
104 104
 }
105 105
 

+ 4
- 4
Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp View File

@@ -62,7 +62,6 @@ bool access_start() {
62 62
   return true;
63 63
 }
64 64
 
65
-
66 65
 bool access_finish(){
67 66
   if (!card.cardOK) return false;
68 67
   int16_t bytes_written = 0;
@@ -81,11 +80,12 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
81 80
   return false;
82 81
 }
83 82
 
84
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
83
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
85 84
   for (int i = 0; i < size; i++) {
86
-    value[i] = HAL_STM32F1_eeprom_content [pos + i];
85
+    uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
86
+    if (writing) value[i] = c`;
87
+    crc16(crc, &c, 1);
87 88
   }
88
-  crc16(crc, value, size);
89 89
   pos += size;
90 90
   return false;
91 91
 }

+ 2
- 2
Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp View File

@@ -38,10 +38,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
38 38
   return false;
39 39
 }
40 40
 
41
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
41
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
42 42
   do {
43 43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
44
-    *value = c;
44
+    if (writing) *value = c;
45 45
     crc16(crc, &c, 1);
46 46
     pos++;
47 47
     value++;

+ 1
- 1
Marlin/src/HAL/persistent_store_api.h View File

@@ -10,7 +10,7 @@ namespace PersistentStore {
10 10
 bool access_start();
11 11
 bool access_finish();
12 12
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
13
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc);
13
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing=true);
14 14
 
15 15
 } // PersistentStore
16 16
 } // HAL

Marlin/src/gcode/eeprom/M500-M503.cpp → Marlin/src/gcode/eeprom/M500-M504.cpp View File

@@ -55,3 +55,15 @@ void GcodeSuite::M502() {
55 55
   }
56 56
 
57 57
 #endif // !DISABLE_M503
58
+
59
+#if ENABLED(EEPROM_SETTINGS)
60
+  /**
61
+   * M504: Validate EEPROM Contents
62
+   */
63
+  void GcodeSuite::M504() {
64
+    if (settings.validate()) {
65
+      SERIAL_ECHO_START();
66
+      SERIAL_ECHOLNPGM("EEPROM OK");
67
+    }
68
+  }
69
+#endif

+ 3
- 0
Marlin/src/gcode/gcode.cpp View File

@@ -610,6 +610,9 @@ void GcodeSuite::process_parsed_command() {
610 610
       #if DISABLED(DISABLE_M503)
611 611
         case 503: M503(); break;  // M503: print settings currently in memory
612 612
       #endif
613
+      #if ENABLED(EEPROM_SETTINGS)
614
+        case 504: M504(); break;  // M504: Validate EEPROM contents
615
+      #endif
613 616
 
614 617
       #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
615 618
         case 540: M540(); break;  // M540: Set abort on endstop hit for SD printing

+ 3
- 0
Marlin/src/gcode/gcode.h View File

@@ -681,6 +681,9 @@ private:
681 681
   #if DISABLED(DISABLE_M503)
682 682
     static void M503();
683 683
   #endif
684
+  #if ENABLED(EEPROM_SETTINGS)
685
+    static void M504();
686
+  #endif
684 687
 
685 688
   #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
686 689
     static void M540();

+ 143
- 117
Marlin/src/module/configuration_store.cpp View File

@@ -289,12 +289,13 @@ void MarlinSettings::postprocess() {
289 289
   #define EEPROM_FINISH() HAL::PersistentStore::access_finish()
290 290
   #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
291 291
   #define EEPROM_WRITE(VAR) HAL::PersistentStore::write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
292
-  #define EEPROM_READ(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
292
+  #define EEPROM_READ(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, !validating)
293
+  #define EEPROM_READ_ALWAYS(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
293 294
   #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
294 295
 
295 296
   const char version[4] = EEPROM_VERSION;
296 297
 
297
-  bool MarlinSettings::eeprom_error;
298
+  bool MarlinSettings::eeprom_error, MarlinSettings::validating;
298 299
 
299 300
   #if ENABLED(AUTO_BED_LEVELING_UBL)
300 301
     int16_t MarlinSettings::meshes_begin;
@@ -718,6 +719,9 @@ void MarlinSettings::postprocess() {
718 719
       for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_WRITE(dummy);
719 720
     #endif
720 721
 
722
+    //
723
+    // Validate CRC
724
+    //
721 725
     if (!eeprom_error) {
722 726
       #if ENABLED(EEPROM_CHITCHAT)
723 727
         const int eeprom_size = eeprom_index;
@@ -741,6 +745,9 @@ void MarlinSettings::postprocess() {
741 745
     }
742 746
     EEPROM_FINISH();
743 747
 
748
+    //
749
+    // UBL Mesh
750
+    //
744 751
     #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
745 752
       if (ubl.storage_slot >= 0)
746 753
         store_mesh(ubl.storage_slot);
@@ -752,16 +759,16 @@ void MarlinSettings::postprocess() {
752 759
   /**
753 760
    * M501 - Retrieve Configuration
754 761
    */
755
-  bool MarlinSettings::load() {
762
+  bool MarlinSettings::_load() {
756 763
     uint16_t working_crc = 0;
757 764
 
758 765
     EEPROM_START();
759 766
 
760 767
     char stored_ver[4];
761
-    EEPROM_READ(stored_ver);
768
+    EEPROM_READ_ALWAYS(stored_ver);
762 769
 
763 770
     uint16_t stored_crc;
764
-    EEPROM_READ(stored_crc);
771
+    EEPROM_READ_ALWAYS(stored_crc);
765 772
 
766 773
     // Version has to match or defaults are used
767 774
     if (strncmp(version, stored_ver, 3) != 0) {
@@ -775,7 +782,8 @@ void MarlinSettings::postprocess() {
775 782
         SERIAL_ECHOPAIR("(EEPROM=", stored_ver);
776 783
         SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")");
777 784
       #endif
778
-      reset();
785
+      if (!validating) reset();
786
+      eeprom_error = true;
779 787
     }
780 788
     else {
781 789
       float dummy = 0;
@@ -787,7 +795,7 @@ void MarlinSettings::postprocess() {
787 795
 
788 796
       // Number of esteppers may change
789 797
       uint8_t esteppers;
790
-      EEPROM_READ(esteppers);
798
+      EEPROM_READ_ALWAYS(esteppers);
791 799
 
792 800
       //
793 801
       // Planner Motion
@@ -802,7 +810,7 @@ void MarlinSettings::postprocess() {
802 810
       EEPROM_READ(tmp1);
803 811
       EEPROM_READ(tmp2);
804 812
       EEPROM_READ(tmp3);
805
-      LOOP_XYZE_N(i) {
813
+      if (!validating) LOOP_XYZE_N(i) {
806 814
         planner.axis_steps_per_mm[i]          = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
807 815
         planner.max_feedrate_mm_s[i]          = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
808 816
         planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
@@ -851,21 +859,23 @@ void MarlinSettings::postprocess() {
851 859
 
852 860
       bool leveling_is_on;
853 861
       uint8_t mesh_num_x, mesh_num_y;
854
-      EEPROM_READ(leveling_is_on);
862
+      EEPROM_READ_ALWAYS(leveling_is_on);
855 863
       EEPROM_READ(dummy);
856
-      EEPROM_READ(mesh_num_x);
857
-      EEPROM_READ(mesh_num_y);
864
+      EEPROM_READ_ALWAYS(mesh_num_x);
865
+      EEPROM_READ_ALWAYS(mesh_num_y);
858 866
 
859 867
       #if ENABLED(MESH_BED_LEVELING)
860
-        mbl.has_mesh = leveling_is_on;
861
-        mbl.z_offset = dummy;
868
+        if (!validating) {
869
+          mbl.has_mesh = leveling_is_on;
870
+          mbl.z_offset = dummy;
871
+        }
862 872
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
863 873
           // EEPROM data fits the current mesh
864 874
           EEPROM_READ(mbl.z_values);
865 875
         }
866 876
         else {
867 877
           // EEPROM data is stale
868
-          mbl.reset();
878
+          if (!validating) mbl.reset();
869 879
           for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
870 880
         }
871 881
       #else
@@ -893,11 +903,11 @@ void MarlinSettings::postprocess() {
893 903
       //
894 904
 
895 905
       uint8_t grid_max_x, grid_max_y;
896
-      EEPROM_READ(grid_max_x);                       // 1 byte
897
-      EEPROM_READ(grid_max_y);                       // 1 byte
906
+      EEPROM_READ_ALWAYS(grid_max_x);                       // 1 byte
907
+      EEPROM_READ_ALWAYS(grid_max_y);                       // 1 byte
898 908
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
899 909
         if (grid_max_x == GRID_MAX_POINTS_X && grid_max_y == GRID_MAX_POINTS_Y) {
900
-          set_bed_leveling_enabled(false);
910
+          if (!validating) set_bed_leveling_enabled(false);
901 911
           EEPROM_READ(bilinear_grid_spacing);        // 2 ints
902 912
           EEPROM_READ(bilinear_start);               // 2 ints
903 913
           EEPROM_READ(z_values);                     // 9 to 256 floats
@@ -989,7 +999,7 @@ void MarlinSettings::postprocess() {
989 999
           EEPROM_READ(dummy); // Kp
990 1000
           if (e < HOTENDS && dummy != DUMMY_PID_VALUE) {
991 1001
             // do not need to scale PID values as the values in EEPROM are already scaled
992
-            PID_PARAM(Kp, e) = dummy;
1002
+            if (!validating) PID_PARAM(Kp, e) = dummy;
993 1003
             EEPROM_READ(PID_PARAM(Ki, e));
994 1004
             EEPROM_READ(PID_PARAM(Kd, e));
995 1005
             #if ENABLED(PID_EXTRUSION_SCALING)
@@ -1023,7 +1033,7 @@ void MarlinSettings::postprocess() {
1023 1033
       #if ENABLED(PIDTEMPBED)
1024 1034
         EEPROM_READ(dummy); // bedKp
1025 1035
         if (dummy != DUMMY_PID_VALUE) {
1026
-          thermalManager.bedKp = dummy;
1036
+          if (!validating) thermalManager.bedKp = dummy;
1027 1037
           EEPROM_READ(thermalManager.bedKi);
1028 1038
           EEPROM_READ(thermalManager.bedKd);
1029 1039
         }
@@ -1068,7 +1078,8 @@ void MarlinSettings::postprocess() {
1068 1078
 
1069 1079
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1070 1080
           EEPROM_READ(dummy);
1071
-          if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy;
1081
+          if (!validating && q < COUNT(planner.filament_size))
1082
+            planner.filament_size[q] = dummy;
1072 1083
         }
1073 1084
 
1074 1085
       #else
@@ -1081,55 +1092,48 @@ void MarlinSettings::postprocess() {
1081 1092
       //
1082 1093
       // TMC2130 Stepper Current
1083 1094
       //
1084
-
1085
-      uint16_t val;
1086 1095
       #if HAS_TRINAMIC
1096
+        #define SET_CURR(N,Q) stepper##Q.setCurrent(val[N], R_SENSE, HOLD_MULTIPLIER)
1097
+        uint16_t val[11];
1087 1098
         EEPROM_READ(val);
1088
-        #if X_IS_TRINAMIC
1089
-          stepperX.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1090
-        #endif
1091
-        EEPROM_READ(val);
1092
-        #if Y_IS_TRINAMIC
1093
-          stepperY.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1094
-        #endif
1095
-        EEPROM_READ(val);
1096
-        #if Z_IS_TRINAMIC
1097
-          stepperZ.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1098
-        #endif
1099
-        EEPROM_READ(val);
1100
-        #if X2_IS_TRINAMIC
1101
-          stepperX2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1102
-        #endif
1103
-        EEPROM_READ(val);
1104
-        #if Y2_IS_TRINAMIC
1105
-          stepperY2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1106
-        #endif
1107
-        EEPROM_READ(val);
1108
-        #if Z2_IS_TRINAMIC
1109
-          stepperZ2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1110
-        #endif
1111
-        EEPROM_READ(val);
1112
-        #if E0_IS_TRINAMIC
1113
-          stepperE0.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1114
-        #endif
1115
-        EEPROM_READ(val);
1116
-        #if E1_IS_TRINAMIC
1117
-          stepperE1.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1118
-        #endif
1119
-        EEPROM_READ(val);
1120
-        #if E2_IS_TRINAMIC
1121
-          stepperE2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1122
-        #endif
1123
-        EEPROM_READ(val);
1124
-        #if E3_IS_TRINAMIC
1125
-          stepperE3.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1126
-        #endif
1127
-        EEPROM_READ(val);
1128
-        #if E4_IS_TRINAMIC
1129
-          stepperE4.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1130
-        #endif
1099
+        if (!validating) {
1100
+          #if X_IS_TRINAMIC
1101
+            SET_CURR(0, X);
1102
+          #endif
1103
+          #if Y_IS_TRINAMIC
1104
+            SET_CURR(1, Y);
1105
+          #endif
1106
+          #if Z_IS_TRINAMIC
1107
+            SET_CURR(2, Z);
1108
+          #endif
1109
+          #if X2_IS_TRINAMIC
1110
+            SET_CURR(3, X2);
1111
+          #endif
1112
+          #if Y2_IS_TRINAMIC
1113
+            SET_CURR(4, Y2);
1114
+          #endif
1115
+          #if Z2_IS_TRINAMIC
1116
+            SET_CURR(5, Z2);
1117
+          #endif
1118
+          #if E0_IS_TRINAMIC
1119
+            SET_CURR(6, E0);
1120
+          #endif
1121
+          #if E1_IS_TRINAMIC
1122
+            SET_CURR(7, E1);
1123
+          #endif
1124
+          #if E2_IS_TRINAMIC
1125
+            SET_CURR(8, E2);
1126
+          #endif
1127
+          #if E3_IS_TRINAMIC
1128
+            SET_CURR(9, E3);
1129
+          #endif
1130
+          #if E4_IS_TRINAMIC
1131
+            SET_CURR(10, E4);
1132
+          #endif
1133
+        }
1131 1134
       #else
1132
-        for (uint8_t q = 11; q--;) EEPROM_READ(val);
1135
+        uint16_t val;
1136
+        for (uint8_t q=11; q--;) EEPROM_READ(val);
1133 1137
       #endif
1134 1138
 
1135 1139
       /*
@@ -1140,19 +1144,23 @@ void MarlinSettings::postprocess() {
1140 1144
       int16_t thrs;
1141 1145
       #if ENABLED(SENSORLESS_HOMING)
1142 1146
         EEPROM_READ(thrs);
1143
-        #if ENABLED(X_IS_TMC2130)
1144
-          stepperX.sgt(thrs);
1145
-        #endif
1146
-        #if ENABLED(X2_IS_TMC2130)
1147
-          stepperX2.sgt(thrs);
1148
-        #endif
1147
+        if (!validating) {
1148
+          #if ENABLED(X_IS_TMC2130)
1149
+            stepperX.sgt(thrs);
1150
+          #endif
1151
+          #if ENABLED(X2_IS_TMC2130)
1152
+            stepperX2.sgt(thrs);
1153
+          #endif
1154
+        }
1149 1155
         EEPROM_READ(thrs);
1150
-        #if ENABLED(Y_IS_TMC2130)
1151
-          stepperY.sgt(thrs);
1152
-        #endif
1153
-        #if ENABLED(Y2_IS_TMC2130)
1154
-          stepperY2.sgt(thrs);
1155
-        #endif
1156
+        if (!validating) {
1157
+          #if ENABLED(Y_IS_TMC2130)
1158
+            stepperY.sgt(thrs);
1159
+          #endif
1160
+          #if ENABLED(Y2_IS_TMC2130)
1161
+            stepperY2.sgt(thrs);
1162
+          #endif
1163
+        }
1156 1164
       #else
1157 1165
         for (uint8_t q = 0; q < 2; q++) EEPROM_READ(thrs);
1158 1166
       #endif
@@ -1185,7 +1193,7 @@ void MarlinSettings::postprocess() {
1185 1193
       //
1186 1194
 
1187 1195
       #if ENABLED(CNC_COORDINATE_SYSTEMS)
1188
-        (void)gcode.select_coordinate_system(-1); // Go back to machine space
1196
+        if (!validating) (void)gcode.select_coordinate_system(-1); // Go back to machine space
1189 1197
         EEPROM_READ(gcode.coordinate_system);                  // 27 floats
1190 1198
       #else
1191 1199
         for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
@@ -1215,25 +1223,27 @@ void MarlinSettings::postprocess() {
1215 1223
       #if ENABLED(ADVANCED_PAUSE_FEATURE)
1216 1224
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1217 1225
           EEPROM_READ(dummy);
1218
-          if (q < COUNT(filament_change_unload_length)) filament_change_unload_length[q] = dummy;
1226
+          if (!validating && q < COUNT(filament_change_unload_length)) filament_change_unload_length[q] = dummy;
1219 1227
         }
1220 1228
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1221 1229
           EEPROM_READ(dummy);
1222
-          if (q < COUNT(filament_change_load_length)) filament_change_load_length[q] = dummy;
1230
+          if (!validating && q < COUNT(filament_change_load_length)) filament_change_load_length[q] = dummy;
1223 1231
         }
1224 1232
       #else
1225 1233
         for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_READ(dummy);
1226 1234
       #endif
1227 1235
 
1228 1236
       if (working_crc == stored_crc) {
1229
-        postprocess();
1230
-        #if ENABLED(EEPROM_CHITCHAT)
1231
-          SERIAL_ECHO_START();
1232
-          SERIAL_ECHO(version);
1233
-          SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET));
1234
-          SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)working_crc);
1235
-          SERIAL_ECHOLNPGM(")");
1236
-        #endif
1237
+        if (!validating) {
1238
+          postprocess();
1239
+          #if ENABLED(EEPROM_CHITCHAT)
1240
+            SERIAL_ECHO_START();
1241
+            SERIAL_ECHO(version);
1242
+            SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET));
1243
+            SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)working_crc);
1244
+            SERIAL_ECHOLNPGM(")");
1245
+          #endif
1246
+        }
1237 1247
       }
1238 1248
       else {
1239 1249
         #if ENABLED(EEPROM_CHITCHAT)
@@ -1253,46 +1263,62 @@ void MarlinSettings::postprocess() {
1253 1263
                                                       // disrupting the mesh data
1254 1264
         ubl.report_state();
1255 1265
 
1256
-        if (!ubl.sanity_check()) {
1257
-          SERIAL_EOL();
1258
-          #if ENABLED(EEPROM_CHITCHAT)
1259
-            ubl.echo_name();
1260
-            SERIAL_ECHOLNPGM(" initialized.\n");
1261
-          #endif
1262
-        }
1263
-        else {
1264
-          #if ENABLED(EEPROM_CHITCHAT)
1265
-            SERIAL_PROTOCOLPGM("?Can't enable ");
1266
-            ubl.echo_name();
1267
-            SERIAL_PROTOCOLLNPGM(".");
1268
-          #endif
1269
-          ubl.reset();
1270
-        }
1266
+        if (!validating) {
1267
+          if (!ubl.sanity_check()) {
1268
+            SERIAL_EOL();
1269
+            #if ENABLED(EEPROM_CHITCHAT)
1270
+              ubl.echo_name();
1271
+              SERIAL_ECHOLNPGM(" initialized.\n");
1272
+            #endif
1273
+          }
1274
+          else {
1275
+            eeprom_error = true;
1276
+            #if ENABLED(EEPROM_CHITCHAT)
1277
+              SERIAL_PROTOCOLPGM("?Can't enable ");
1278
+              ubl.echo_name();
1279
+              SERIAL_PROTOCOLLNPGM(".");
1280
+            #endif
1281
+            ubl.reset();
1282
+          }
1271 1283
 
1272
-        if (ubl.storage_slot >= 0) {
1273
-          load_mesh(ubl.storage_slot);
1274
-          #if ENABLED(EEPROM_CHITCHAT)
1275
-            SERIAL_ECHOPAIR("Mesh ", ubl.storage_slot);
1276
-            SERIAL_ECHOLNPGM(" loaded from storage.");
1277
-          #endif
1278
-        }
1279
-        else {
1280
-          ubl.reset();
1281
-          #if ENABLED(EEPROM_CHITCHAT)
1282
-            SERIAL_ECHOLNPGM("UBL System reset()");
1283
-          #endif
1284
+          if (ubl.storage_slot >= 0) {
1285
+            load_mesh(ubl.storage_slot);
1286
+            #if ENABLED(EEPROM_CHITCHAT)
1287
+              SERIAL_ECHOPAIR("Mesh ", ubl.storage_slot);
1288
+              SERIAL_ECHOLNPGM(" loaded from storage.");
1289
+            #endif
1290
+          }
1291
+          else {
1292
+            ubl.reset();
1293
+            #if ENABLED(EEPROM_CHITCHAT)
1294
+              SERIAL_ECHOLNPGM("UBL System reset()");
1295
+            #endif
1296
+          }
1284 1297
         }
1285 1298
       #endif
1286 1299
     }
1287 1300
 
1288 1301
     #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
1289
-      report();
1302
+      if (!validating) report();
1290 1303
     #endif
1291 1304
     EEPROM_FINISH();
1292 1305
 
1293 1306
     return !eeprom_error;
1294 1307
   }
1295 1308
 
1309
+  bool MarlinSettings::validate() {
1310
+    validating = true;
1311
+    const bool success = _load();
1312
+    validating = false;
1313
+    return success;
1314
+  }
1315
+
1316
+  bool MarlinSettings::load() {
1317
+    if (validate()) return _load();
1318
+    reset();
1319
+    return true;
1320
+  }
1321
+
1296 1322
   #if ENABLED(AUTO_BED_LEVELING_UBL)
1297 1323
 
1298 1324
     #if ENABLED(EEPROM_CHITCHAT)

+ 6
- 3
Marlin/src/module/configuration_store.h View File

@@ -30,7 +30,7 @@ class MarlinSettings {
30 30
     MarlinSettings() { }
31 31
 
32 32
     static void reset();
33
-    static bool save();
33
+    static bool save();   // Return 'true' if data was saved
34 34
 
35 35
     FORCE_INLINE static bool init_eeprom() {
36 36
       bool success = true;
@@ -48,7 +48,8 @@ class MarlinSettings {
48 48
     }
49 49
 
50 50
     #if ENABLED(EEPROM_SETTINGS)
51
-      static bool load();
51
+      static bool load();     // Return 'true' if data was loaded ok
52
+      static bool validate(); // Return 'true' if EEPROM data is ok
52 53
 
53 54
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
54 55
                                          // That can store is enabled
@@ -77,7 +78,8 @@ class MarlinSettings {
77 78
     static void postprocess();
78 79
 
79 80
     #if ENABLED(EEPROM_SETTINGS)
80
-      static bool eeprom_error;
81
+
82
+      static bool eeprom_error, validating;
81 83
 
82 84
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
83 85
                                          // That can store is enabled
@@ -87,6 +89,7 @@ class MarlinSettings {
87 89
 
88 90
       #endif
89 91
 
92
+      static bool _load();
90 93
     #endif
91 94
 };
92 95
 

Loading…
Cancel
Save