Browse Source

Add MarlinSettings::validate()

Scott Lahteine 7 years ago
parent
commit
51e0f2bee3

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

38
   return false;
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
   do {
42
   do {
43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
44
-    *value = c;
44
+    if (writing) *value = c;
45
     crc16(crc, &c, 1);
45
     crc16(crc, &c, 1);
46
     pos++;
46
     pos++;
47
     value++;
47
     value++;

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

43
   return false;
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
   do {
47
   do {
48
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
48
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
49
-    *value = c;
49
+    if (writing) *value = c;
50
     crc16(crc, &c, 1);
50
     crc16(crc, &c, 1);
51
     pos++;
51
     pos++;
52
     value++;
52
     value++;

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

128
   return (bytes_written != size);  // return true for any error
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
   UINT bytes_read = 0;
132
   UINT bytes_read = 0;
133
   FRESULT s;
133
   FRESULT s;
134
   s = f_lseek(&eeprom_file, pos);
134
   s = f_lseek(&eeprom_file, pos);
140
    SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
140
    SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
141
    return true;
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
   if (s) {
152
   if (s) {
145
    SERIAL_PROTOCOLPAIR(" read_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
153
    SERIAL_PROTOCOLPAIR(" read_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
146
    SERIAL_PROTOCOLPAIR(",", (int)value);           // right now to see errors that are happening in the
154
    SERIAL_PROTOCOLPAIR(",", (int)value);           // right now to see errors that are happening in the
151
    SERIAL_PROTOCOLLNPAIR("\n bytes_read=",  bytes_read);
159
    SERIAL_PROTOCOLLNPAIR("\n bytes_read=",  bytes_read);
152
    return true;
160
    return true;
153
   }
161
   }
154
-  crc16(crc, value, size);
155
   pos = pos + size;
162
   pos = pos + size;
156
   return bytes_read != size;  // return true for any error
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
   return true;
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
   for (uint16_t i = 0; i < size; i++) {
97
   for (uint16_t i = 0; i < size; i++) {
98
     byte* accessPoint = (byte*)(pageBase + pos + i);
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
   pos += ((size + 1) & ~1);
103
   pos += ((size + 1) & ~1);
104
 }
104
 }
105
 
105
 

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

62
   return true;
62
   return true;
63
 }
63
 }
64
 
64
 
65
-
66
 bool access_finish(){
65
 bool access_finish(){
67
   if (!card.cardOK) return false;
66
   if (!card.cardOK) return false;
68
   int16_t bytes_written = 0;
67
   int16_t bytes_written = 0;
81
   return false;
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
   for (int i = 0; i < size; i++) {
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
   pos += size;
89
   pos += size;
90
   return false;
90
   return false;
91
 }
91
 }

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

38
   return false;
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
   do {
42
   do {
43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
44
-    *value = c;
44
+    if (writing) *value = c;
45
     crc16(crc, &c, 1);
45
     crc16(crc, &c, 1);
46
     pos++;
46
     pos++;
47
     value++;
47
     value++;

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

10
 bool access_start();
10
 bool access_start();
11
 bool access_finish();
11
 bool access_finish();
12
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
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
 } // PersistentStore
15
 } // PersistentStore
16
 } // HAL
16
 } // HAL

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

55
   }
55
   }
56
 
56
 
57
 #endif // !DISABLE_M503
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
       #if DISABLED(DISABLE_M503)
610
       #if DISABLED(DISABLE_M503)
611
         case 503: M503(); break;  // M503: print settings currently in memory
611
         case 503: M503(); break;  // M503: print settings currently in memory
612
       #endif
612
       #endif
613
+      #if ENABLED(EEPROM_SETTINGS)
614
+        case 504: M504(); break;  // M504: Validate EEPROM contents
615
+      #endif
613
 
616
 
614
       #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
617
       #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
615
         case 540: M540(); break;  // M540: Set abort on endstop hit for SD printing
618
         case 540: M540(); break;  // M540: Set abort on endstop hit for SD printing

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

681
   #if DISABLED(DISABLE_M503)
681
   #if DISABLED(DISABLE_M503)
682
     static void M503();
682
     static void M503();
683
   #endif
683
   #endif
684
+  #if ENABLED(EEPROM_SETTINGS)
685
+    static void M504();
686
+  #endif
684
 
687
 
685
   #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
688
   #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
686
     static void M540();
689
     static void M540();

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

289
   #define EEPROM_FINISH() HAL::PersistentStore::access_finish()
289
   #define EEPROM_FINISH() HAL::PersistentStore::access_finish()
290
   #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
290
   #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
291
   #define EEPROM_WRITE(VAR) HAL::PersistentStore::write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
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
   #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
294
   #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
294
 
295
 
295
   const char version[4] = EEPROM_VERSION;
296
   const char version[4] = EEPROM_VERSION;
296
 
297
 
297
-  bool MarlinSettings::eeprom_error;
298
+  bool MarlinSettings::eeprom_error, MarlinSettings::validating;
298
 
299
 
299
   #if ENABLED(AUTO_BED_LEVELING_UBL)
300
   #if ENABLED(AUTO_BED_LEVELING_UBL)
300
     int16_t MarlinSettings::meshes_begin;
301
     int16_t MarlinSettings::meshes_begin;
718
       for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_WRITE(dummy);
719
       for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_WRITE(dummy);
719
     #endif
720
     #endif
720
 
721
 
722
+    //
723
+    // Validate CRC
724
+    //
721
     if (!eeprom_error) {
725
     if (!eeprom_error) {
722
       #if ENABLED(EEPROM_CHITCHAT)
726
       #if ENABLED(EEPROM_CHITCHAT)
723
         const int eeprom_size = eeprom_index;
727
         const int eeprom_size = eeprom_index;
741
     }
745
     }
742
     EEPROM_FINISH();
746
     EEPROM_FINISH();
743
 
747
 
748
+    //
749
+    // UBL Mesh
750
+    //
744
     #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
751
     #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
745
       if (ubl.storage_slot >= 0)
752
       if (ubl.storage_slot >= 0)
746
         store_mesh(ubl.storage_slot);
753
         store_mesh(ubl.storage_slot);
752
   /**
759
   /**
753
    * M501 - Retrieve Configuration
760
    * M501 - Retrieve Configuration
754
    */
761
    */
755
-  bool MarlinSettings::load() {
762
+  bool MarlinSettings::_load() {
756
     uint16_t working_crc = 0;
763
     uint16_t working_crc = 0;
757
 
764
 
758
     EEPROM_START();
765
     EEPROM_START();
759
 
766
 
760
     char stored_ver[4];
767
     char stored_ver[4];
761
-    EEPROM_READ(stored_ver);
768
+    EEPROM_READ_ALWAYS(stored_ver);
762
 
769
 
763
     uint16_t stored_crc;
770
     uint16_t stored_crc;
764
-    EEPROM_READ(stored_crc);
771
+    EEPROM_READ_ALWAYS(stored_crc);
765
 
772
 
766
     // Version has to match or defaults are used
773
     // Version has to match or defaults are used
767
     if (strncmp(version, stored_ver, 3) != 0) {
774
     if (strncmp(version, stored_ver, 3) != 0) {
775
         SERIAL_ECHOPAIR("(EEPROM=", stored_ver);
782
         SERIAL_ECHOPAIR("(EEPROM=", stored_ver);
776
         SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")");
783
         SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")");
777
       #endif
784
       #endif
778
-      reset();
785
+      if (!validating) reset();
786
+      eeprom_error = true;
779
     }
787
     }
780
     else {
788
     else {
781
       float dummy = 0;
789
       float dummy = 0;
787
 
795
 
788
       // Number of esteppers may change
796
       // Number of esteppers may change
789
       uint8_t esteppers;
797
       uint8_t esteppers;
790
-      EEPROM_READ(esteppers);
798
+      EEPROM_READ_ALWAYS(esteppers);
791
 
799
 
792
       //
800
       //
793
       // Planner Motion
801
       // Planner Motion
802
       EEPROM_READ(tmp1);
810
       EEPROM_READ(tmp1);
803
       EEPROM_READ(tmp2);
811
       EEPROM_READ(tmp2);
804
       EEPROM_READ(tmp3);
812
       EEPROM_READ(tmp3);
805
-      LOOP_XYZE_N(i) {
813
+      if (!validating) LOOP_XYZE_N(i) {
806
         planner.axis_steps_per_mm[i]          = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
814
         planner.axis_steps_per_mm[i]          = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
807
         planner.max_feedrate_mm_s[i]          = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
815
         planner.max_feedrate_mm_s[i]          = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
808
         planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
816
         planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
851
 
859
 
852
       bool leveling_is_on;
860
       bool leveling_is_on;
853
       uint8_t mesh_num_x, mesh_num_y;
861
       uint8_t mesh_num_x, mesh_num_y;
854
-      EEPROM_READ(leveling_is_on);
862
+      EEPROM_READ_ALWAYS(leveling_is_on);
855
       EEPROM_READ(dummy);
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
       #if ENABLED(MESH_BED_LEVELING)
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
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
872
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
863
           // EEPROM data fits the current mesh
873
           // EEPROM data fits the current mesh
864
           EEPROM_READ(mbl.z_values);
874
           EEPROM_READ(mbl.z_values);
865
         }
875
         }
866
         else {
876
         else {
867
           // EEPROM data is stale
877
           // EEPROM data is stale
868
-          mbl.reset();
878
+          if (!validating) mbl.reset();
869
           for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
879
           for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
870
         }
880
         }
871
       #else
881
       #else
893
       //
903
       //
894
 
904
 
895
       uint8_t grid_max_x, grid_max_y;
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
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
908
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
899
         if (grid_max_x == GRID_MAX_POINTS_X && grid_max_y == GRID_MAX_POINTS_Y) {
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
           EEPROM_READ(bilinear_grid_spacing);        // 2 ints
911
           EEPROM_READ(bilinear_grid_spacing);        // 2 ints
902
           EEPROM_READ(bilinear_start);               // 2 ints
912
           EEPROM_READ(bilinear_start);               // 2 ints
903
           EEPROM_READ(z_values);                     // 9 to 256 floats
913
           EEPROM_READ(z_values);                     // 9 to 256 floats
989
           EEPROM_READ(dummy); // Kp
999
           EEPROM_READ(dummy); // Kp
990
           if (e < HOTENDS && dummy != DUMMY_PID_VALUE) {
1000
           if (e < HOTENDS && dummy != DUMMY_PID_VALUE) {
991
             // do not need to scale PID values as the values in EEPROM are already scaled
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
             EEPROM_READ(PID_PARAM(Ki, e));
1003
             EEPROM_READ(PID_PARAM(Ki, e));
994
             EEPROM_READ(PID_PARAM(Kd, e));
1004
             EEPROM_READ(PID_PARAM(Kd, e));
995
             #if ENABLED(PID_EXTRUSION_SCALING)
1005
             #if ENABLED(PID_EXTRUSION_SCALING)
1023
       #if ENABLED(PIDTEMPBED)
1033
       #if ENABLED(PIDTEMPBED)
1024
         EEPROM_READ(dummy); // bedKp
1034
         EEPROM_READ(dummy); // bedKp
1025
         if (dummy != DUMMY_PID_VALUE) {
1035
         if (dummy != DUMMY_PID_VALUE) {
1026
-          thermalManager.bedKp = dummy;
1036
+          if (!validating) thermalManager.bedKp = dummy;
1027
           EEPROM_READ(thermalManager.bedKi);
1037
           EEPROM_READ(thermalManager.bedKi);
1028
           EEPROM_READ(thermalManager.bedKd);
1038
           EEPROM_READ(thermalManager.bedKd);
1029
         }
1039
         }
1068
 
1078
 
1069
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1079
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1070
           EEPROM_READ(dummy);
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
       #else
1085
       #else
1081
       //
1092
       //
1082
       // TMC2130 Stepper Current
1093
       // TMC2130 Stepper Current
1083
       //
1094
       //
1084
-
1085
-      uint16_t val;
1086
       #if HAS_TRINAMIC
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
         EEPROM_READ(val);
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
       #else
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
       #endif
1137
       #endif
1134
 
1138
 
1135
       /*
1139
       /*
1140
       int16_t thrs;
1144
       int16_t thrs;
1141
       #if ENABLED(SENSORLESS_HOMING)
1145
       #if ENABLED(SENSORLESS_HOMING)
1142
         EEPROM_READ(thrs);
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
         EEPROM_READ(thrs);
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
       #else
1164
       #else
1157
         for (uint8_t q = 0; q < 2; q++) EEPROM_READ(thrs);
1165
         for (uint8_t q = 0; q < 2; q++) EEPROM_READ(thrs);
1158
       #endif
1166
       #endif
1185
       //
1193
       //
1186
 
1194
 
1187
       #if ENABLED(CNC_COORDINATE_SYSTEMS)
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
         EEPROM_READ(gcode.coordinate_system);                  // 27 floats
1197
         EEPROM_READ(gcode.coordinate_system);                  // 27 floats
1190
       #else
1198
       #else
1191
         for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
1199
         for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
1215
       #if ENABLED(ADVANCED_PAUSE_FEATURE)
1223
       #if ENABLED(ADVANCED_PAUSE_FEATURE)
1216
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1224
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1217
           EEPROM_READ(dummy);
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
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1228
         for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1221
           EEPROM_READ(dummy);
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
       #else
1232
       #else
1225
         for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_READ(dummy);
1233
         for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_READ(dummy);
1226
       #endif
1234
       #endif
1227
 
1235
 
1228
       if (working_crc == stored_crc) {
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
       else {
1248
       else {
1239
         #if ENABLED(EEPROM_CHITCHAT)
1249
         #if ENABLED(EEPROM_CHITCHAT)
1253
                                                       // disrupting the mesh data
1263
                                                       // disrupting the mesh data
1254
         ubl.report_state();
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
       #endif
1298
       #endif
1286
     }
1299
     }
1287
 
1300
 
1288
     #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
1301
     #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
1289
-      report();
1302
+      if (!validating) report();
1290
     #endif
1303
     #endif
1291
     EEPROM_FINISH();
1304
     EEPROM_FINISH();
1292
 
1305
 
1293
     return !eeprom_error;
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
   #if ENABLED(AUTO_BED_LEVELING_UBL)
1322
   #if ENABLED(AUTO_BED_LEVELING_UBL)
1297
 
1323
 
1298
     #if ENABLED(EEPROM_CHITCHAT)
1324
     #if ENABLED(EEPROM_CHITCHAT)

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

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

Loading…
Cancel
Save