Browse Source

Merge pull request #5448 from thinkyhead/rc_eeprom_bump

EEPROM: Prolong life. Better support for `DISTINCT_E_FACTORS`.
Scott Lahteine 8 years ago
parent
commit
8239c45b30
1 changed files with 113 additions and 83 deletions
  1. 113
    83
      Marlin/configuration_store.cpp

+ 113
- 83
Marlin/configuration_store.cpp View File

36
  *
36
  *
37
  */
37
  */
38
 
38
 
39
-#define EEPROM_VERSION "V27"
39
+#define EEPROM_VERSION "V28"
40
 
40
 
41
 // Change EEPROM version if these are changed:
41
 // Change EEPROM version if these are changed:
42
 #define EEPROM_OFFSET 100
42
 #define EEPROM_OFFSET 100
43
 
43
 
44
 /**
44
 /**
45
- * V27 EEPROM Layout:
45
+ * V28 EEPROM Layout:
46
  *
46
  *
47
  *  100  Version (char x4)
47
  *  100  Version (char x4)
48
  *  104  EEPROM Checksum (uint16_t)
48
  *  104  EEPROM Checksum (uint16_t)
49
  *
49
  *
50
- *  106  M92 XYZE  planner.axis_steps_per_mm (float x4 ... x7)
51
- *  122  M203 XYZE planner.max_feedrate_mm_s (float x4 ... x7)
52
- *  138  M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4 ... x7)
53
- *  154  M204 P    planner.acceleration (float)
54
- *  158  M204 R    planner.retract_acceleration (float)
55
- *  162  M204 T    planner.travel_acceleration (float)
56
- *  166  M205 S    planner.min_feedrate_mm_s (float)
57
- *  170  M205 T    planner.min_travel_feedrate_mm_s (float)
58
- *  174  M205 B    planner.min_segment_time (ulong)
59
- *  178  M205 X    planner.max_jerk[X_AXIS] (float)
60
- *  182  M205 Y    planner.max_jerk[Y_AXIS] (float)
61
- *  186  M205 Z    planner.max_jerk[Z_AXIS] (float)
62
- *  190  M205 E    planner.max_jerk[E_AXIS] (float)
63
- *  194  M206 XYZ  home_offset (float x3)
64
- *  206  M218 XYZ  hotend_offset (float x3 per additional hotend)
50
+ *  106  E_STEPPERS (uint8_t)
51
+ *  107  M92 XYZE  planner.axis_steps_per_mm (float x4 ... x7)
52
+ *  123  M203 XYZE planner.max_feedrate_mm_s (float x4 ... x7)
53
+ *  139  M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4 ... x7)
54
+ *  155  M204 P    planner.acceleration (float)
55
+ *  159  M204 R    planner.retract_acceleration (float)
56
+ *  163  M204 T    planner.travel_acceleration (float)
57
+ *  167  M205 S    planner.min_feedrate_mm_s (float)
58
+ *  171  M205 T    planner.min_travel_feedrate_mm_s (float)
59
+ *  175  M205 B    planner.min_segment_time (ulong)
60
+ *  179  M205 X    planner.max_jerk[X_AXIS] (float)
61
+ *  183  M205 Y    planner.max_jerk[Y_AXIS] (float)
62
+ *  187  M205 Z    planner.max_jerk[Z_AXIS] (float)
63
+ *  191  M205 E    planner.max_jerk[E_AXIS] (float)
64
+ *  195  M206 XYZ  home_offset (float x3)
65
+ *  207  M218 XYZ  hotend_offset (float x3 per additional hotend)
65
  *
66
  *
66
  * Mesh bed leveling:
67
  * Mesh bed leveling:
67
- *  218  M420 S    status (uint8)
68
- *  219            z_offset (float)
69
- *  223            mesh_num_x (uint8 as set in firmware)
70
- *  224            mesh_num_y (uint8 as set in firmware)
71
- *  225 G29 S3 XYZ z_values[][] (float x9, by default, up to float x 81)
68
+ *  219  M420 S    status (uint8)
69
+ *  220            z_offset (float)
70
+ *  224            mesh_num_x (uint8 as set in firmware)
71
+ *  225            mesh_num_y (uint8 as set in firmware)
72
+ *  226 G29 S3 XYZ z_values[][] (float x9, by default, up to float x 81)
72
  *
73
  *
73
  * AUTO BED LEVELING
74
  * AUTO BED LEVELING
74
- *  261  M851      zprobe_zoffset (float)
75
+ *  262  M851      zprobe_zoffset (float)
75
  *
76
  *
76
  * DELTA:
77
  * DELTA:
77
- *  265  M666 XYZ  endstop_adj (float x3)
78
- *  277  M665 R    delta_radius (float)
79
- *  281  M665 L    delta_diagonal_rod (float)
80
- *  285  M665 S    delta_segments_per_second (float)
81
- *  289  M665 A    delta_diagonal_rod_trim_tower_1 (float)
82
- *  293  M665 B    delta_diagonal_rod_trim_tower_2 (float)
83
- *  297  M665 C    delta_diagonal_rod_trim_tower_3 (float)
78
+ *  266  M666 XYZ  endstop_adj (float x3)
79
+ *  278  M665 R    delta_radius (float)
80
+ *  282  M665 L    delta_diagonal_rod (float)
81
+ *  286  M665 S    delta_segments_per_second (float)
82
+ *  290  M665 A    delta_diagonal_rod_trim_tower_1 (float)
83
+ *  294  M665 B    delta_diagonal_rod_trim_tower_2 (float)
84
+ *  298  M665 C    delta_diagonal_rod_trim_tower_3 (float)
84
  *
85
  *
85
  * Z_DUAL_ENDSTOPS:
86
  * Z_DUAL_ENDSTOPS:
86
- *  301  M666 Z    z_endstop_adj (float)
87
+ *  302  M666 Z    z_endstop_adj (float)
87
  *
88
  *
88
  * ULTIPANEL:
89
  * ULTIPANEL:
89
- *  305  M145 S0 H lcd_preheat_hotend_temp (int x2)
90
- *  309  M145 S0 B lcd_preheat_bed_temp (int x2)
91
- *  313  M145 S0 F lcd_preheat_fan_speed (int x2)
90
+ *  306  M145 S0 H lcd_preheat_hotend_temp (int x2)
91
+ *  310  M145 S0 B lcd_preheat_bed_temp (int x2)
92
+ *  314  M145 S0 F lcd_preheat_fan_speed (int x2)
92
  *
93
  *
93
  * PIDTEMP:
94
  * PIDTEMP:
94
- *  317  M301 E0 PIDC  Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
95
- *  333  M301 E1 PIDC  Kp[1], Ki[1], Kd[1], Kc[1] (float x4)
96
- *  349  M301 E2 PIDC  Kp[2], Ki[2], Kd[2], Kc[2] (float x4)
97
- *  365  M301 E3 PIDC  Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
98
- *  381  M301 L        lpq_len (int)
95
+ *  318  M301 E0 PIDC  Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
96
+ *  334  M301 E1 PIDC  Kp[1], Ki[1], Kd[1], Kc[1] (float x4)
97
+ *  350  M301 E2 PIDC  Kp[2], Ki[2], Kd[2], Kc[2] (float x4)
98
+ *  366  M301 E3 PIDC  Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
99
+ *  382  M301 L        lpq_len (int)
99
  *
100
  *
100
  * PIDTEMPBED:
101
  * PIDTEMPBED:
101
- *  383  M304 PID  thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
102
+ *  384  M304 PID  thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
102
  *
103
  *
103
  * DOGLCD:
104
  * DOGLCD:
104
- *  395  M250 C    lcd_contrast (int)
105
+ *  396  M250 C    lcd_contrast (int)
105
  *
106
  *
106
  * FWRETRACT:
107
  * FWRETRACT:
107
- *  397  M209 S    autoretract_enabled (bool)
108
- *  398  M207 S    retract_length (float)
109
- *  402  M207 W    retract_length_swap (float)
110
- *  406  M207 F    retract_feedrate_mm_s (float)
111
- *  410  M207 Z    retract_zlift (float)
112
- *  414  M208 S    retract_recover_length (float)
113
- *  418  M208 W    retract_recover_length_swap (float)
114
- *  422  M208 F    retract_recover_feedrate_mm_s (float)
108
+ *  398  M209 S    autoretract_enabled (bool)
109
+ *  399  M207 S    retract_length (float)
110
+ *  403  M207 W    retract_length_swap (float)
111
+ *  407  M207 F    retract_feedrate_mm_s (float)
112
+ *  411  M207 Z    retract_zlift (float)
113
+ *  415  M208 S    retract_recover_length (float)
114
+ *  419  M208 W    retract_recover_length_swap (float)
115
+ *  423  M208 F    retract_recover_feedrate_mm_s (float)
115
  *
116
  *
116
  * Volumetric Extrusion:
117
  * Volumetric Extrusion:
117
- *  426  M200 D    volumetric_enabled (bool)
118
- *  427  M200 T D  filament_size (float x4) (T0..3)
118
+ *  427  M200 D    volumetric_enabled (bool)
119
+ *  428  M200 T D  filament_size (float x4) (T0..3)
119
  *
120
  *
120
- *  443  This Slot is Available!
121
+ *  444  This Slot is Available!
121
  *
122
  *
122
  */
123
  */
123
 #include "Marlin.h"
124
 #include "Marlin.h"
132
   #include "mesh_bed_leveling.h"
133
   #include "mesh_bed_leveling.h"
133
 #endif
134
 #endif
134
 
135
 
135
-uint16_t eeprom_checksum;
136
-const char version[4] = EEPROM_VERSION;
137
-
138
-void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
139
-  uint8_t c;
140
-  while (size--) {
141
-    eeprom_write_byte((unsigned char*)pos, *value);
142
-    c = eeprom_read_byte((unsigned char*)pos);
143
-    if (c != *value) {
144
-      SERIAL_ECHO_START;
145
-      SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
146
-    }
147
-    eeprom_checksum += c;
148
-    pos++;
149
-    value++;
150
-  };
151
-}
152
-void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
153
-  do {
154
-    uint8_t c = eeprom_read_byte((unsigned char*)pos);
155
-    *value = c;
156
-    eeprom_checksum += c;
157
-    pos++;
158
-    value++;
159
-  } while (--size);
160
-}
161
-
162
 /**
136
 /**
163
  * Post-process after Retrieve or Reset
137
  * Post-process after Retrieve or Reset
164
  */
138
  */
188
 
162
 
189
 #if ENABLED(EEPROM_SETTINGS)
163
 #if ENABLED(EEPROM_SETTINGS)
190
 
164
 
165
+  uint16_t eeprom_checksum;
166
+  const char version[4] = EEPROM_VERSION;
167
+
168
+  bool eeprom_write_error;
169
+
170
+  void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
171
+    if (eeprom_write_error) return;
172
+    while (size--) {
173
+      uint8_t * const p = (uint8_t * const)pos;
174
+      const uint8_t v = *value;
175
+      // EEPROM has only ~100,000 write cycles,
176
+      // so only write bytes that have changed!
177
+      if (v != eeprom_read_byte(p)) {
178
+        eeprom_write_byte(p, v);
179
+        if (eeprom_read_byte(p) != v) {
180
+          SERIAL_ECHO_START;
181
+          SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
182
+          eeprom_write_error = true;
183
+          return;
184
+        }
185
+      }
186
+      eeprom_checksum += v;
187
+      pos++;
188
+      value++;
189
+    };
190
+  }
191
+  void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
192
+    do {
193
+      uint8_t c = eeprom_read_byte((unsigned char*)pos);
194
+      *value = c;
195
+      eeprom_checksum += c;
196
+      pos++;
197
+      value++;
198
+    } while (--size);
199
+  }
200
+
191
   #define DUMMY_PID_VALUE 3000.0f
201
   #define DUMMY_PID_VALUE 3000.0f
192
   #define EEPROM_START() int eeprom_index = EEPROM_OFFSET
202
   #define EEPROM_START() int eeprom_index = EEPROM_OFFSET
193
   #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
203
   #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
203
 
213
 
204
     EEPROM_START();
214
     EEPROM_START();
205
 
215
 
216
+    eeprom_write_error = false;
217
+
206
     EEPROM_WRITE(ver);     // invalidate data first
218
     EEPROM_WRITE(ver);     // invalidate data first
207
     EEPROM_SKIP(eeprom_checksum); // Skip the checksum slot
219
     EEPROM_SKIP(eeprom_checksum); // Skip the checksum slot
208
 
220
 
209
     eeprom_checksum = 0; // clear before first "real data"
221
     eeprom_checksum = 0; // clear before first "real data"
210
 
222
 
223
+    const uint8_t esteppers = E_STEPPERS;
224
+    EEPROM_WRITE(esteppers);
211
     EEPROM_WRITE(planner.axis_steps_per_mm);
225
     EEPROM_WRITE(planner.axis_steps_per_mm);
212
     EEPROM_WRITE(planner.max_feedrate_mm_s);
226
     EEPROM_WRITE(planner.max_feedrate_mm_s);
213
     EEPROM_WRITE(planner.max_acceleration_mm_per_s2);
227
     EEPROM_WRITE(planner.max_acceleration_mm_per_s2);
228
+
214
     EEPROM_WRITE(planner.acceleration);
229
     EEPROM_WRITE(planner.acceleration);
215
     EEPROM_WRITE(planner.retract_acceleration);
230
     EEPROM_WRITE(planner.retract_acceleration);
216
     EEPROM_WRITE(planner.travel_acceleration);
231
     EEPROM_WRITE(planner.travel_acceleration);
387
     //  SERIAL_CHAR(']');
402
     //  SERIAL_CHAR(']');
388
     //  SERIAL_EOL;
403
     //  SERIAL_EOL;
389
 
404
 
405
+    // Version has to match or defaults are used
390
     if (strncmp(version, stored_ver, 3) != 0) {
406
     if (strncmp(version, stored_ver, 3) != 0) {
391
       Config_ResetDefault();
407
       Config_ResetDefault();
392
     }
408
     }
395
 
411
 
396
       eeprom_checksum = 0; // clear before reading first "real data"
412
       eeprom_checksum = 0; // clear before reading first "real data"
397
 
413
 
398
-      // version number match
399
-      EEPROM_READ(planner.axis_steps_per_mm);
400
-      EEPROM_READ(planner.max_feedrate_mm_s);
401
-      EEPROM_READ(planner.max_acceleration_mm_per_s2);
414
+      // Number of esteppers may change
415
+      uint8_t esteppers;
416
+      EEPROM_READ(esteppers);
417
+
418
+      // Get only the number of E stepper parameters previously stored
419
+      // Any steppers added later are set to their defaults
420
+      const float def1[] = DEFAULT_AXIS_STEPS_PER_UNIT, def2[] = DEFAULT_MAX_FEEDRATE;
421
+      const long def3[] = DEFAULT_MAX_ACCELERATION;
422
+      float tmp1[XYZ + esteppers], tmp2[XYZ + esteppers];
423
+      long tmp3[XYZ + esteppers];
424
+      EEPROM_READ(tmp1);
425
+      EEPROM_READ(tmp2);
426
+      EEPROM_READ(tmp3);
427
+      LOOP_XYZE_N(i) {
428
+        planner.axis_steps_per_mm[i]          = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
429
+        planner.max_feedrate_mm_s[i]          = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
430
+        planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
431
+      }
402
 
432
 
403
       EEPROM_READ(planner.acceleration);
433
       EEPROM_READ(planner.acceleration);
404
       EEPROM_READ(planner.retract_acceleration);
434
       EEPROM_READ(planner.retract_acceleration);

Loading…
Cancel
Save