My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

configuration_store.cpp 58KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * configuration_store.cpp
  24. *
  25. * Settings and EEPROM storage
  26. *
  27. * IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
  28. * in the functions below, also increment the version number. This makes sure that
  29. * the default values are used whenever there is a change to the data, to prevent
  30. * wrong data being written to the variables.
  31. *
  32. * ALSO: Variables in the Store and Retrieve sections must be in the same order.
  33. * If a feature is disabled, some data must still be written that, when read,
  34. * either sets a Sane Default, or results in No Change to the existing value.
  35. *
  36. */
  37. #define EEPROM_VERSION "V41"
  38. // Change EEPROM version if these are changed:
  39. #define EEPROM_OFFSET 100
  40. /**
  41. * V41 EEPROM Layout:
  42. *
  43. * 100 Version (char x4)
  44. * 104 EEPROM CRC16 (uint16_t)
  45. *
  46. * 106 E_STEPPERS (uint8_t)
  47. * 107 M92 XYZE planner.axis_steps_per_mm (float x4 ... x8)
  48. * 123 M203 XYZE planner.max_feedrate_mm_s (float x4 ... x8)
  49. * 139 M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4 ... x8)
  50. * 155 M204 P planner.acceleration (float)
  51. * 159 M204 R planner.retract_acceleration (float)
  52. * 163 M204 T planner.travel_acceleration (float)
  53. * 167 M205 S planner.min_feedrate_mm_s (float)
  54. * 171 M205 T planner.min_travel_feedrate_mm_s (float)
  55. * 175 M205 B planner.min_segment_time (ulong)
  56. * 179 M205 X planner.max_jerk[X_AXIS] (float)
  57. * 183 M205 Y planner.max_jerk[Y_AXIS] (float)
  58. * 187 M205 Z planner.max_jerk[Z_AXIS] (float)
  59. * 191 M205 E planner.max_jerk[E_AXIS] (float)
  60. * 195 M206 XYZ home_offset (float x3)
  61. * 207 M218 XYZ hotend_offset (float x3 per additional hotend)
  62. *
  63. * Global Leveling:
  64. * 219 z_fade_height (float)
  65. *
  66. * MESH_BED_LEVELING: 43 bytes
  67. * 223 M420 S from mbl.status (bool)
  68. * 224 mbl.z_offset (float)
  69. * 228 GRID_MAX_POINTS_X (uint8_t)
  70. * 229 GRID_MAX_POINTS_Y (uint8_t)
  71. * 230 G29 S3 XYZ z_values[][] (float x9, up to float x81) +288
  72. *
  73. * HAS_BED_PROBE: 4 bytes
  74. * 266 M851 zprobe_zoffset (float)
  75. *
  76. * ABL_PLANAR: 36 bytes
  77. * 270 planner.bed_level_matrix (matrix_3x3 = float x9)
  78. *
  79. * AUTO_BED_LEVELING_BILINEAR: 47 bytes
  80. * 306 GRID_MAX_POINTS_X (uint8_t)
  81. * 307 GRID_MAX_POINTS_Y (uint8_t)
  82. * 308 bilinear_grid_spacing (int x2)
  83. * 312 G29 L F bilinear_start (int x2)
  84. * 316 z_values[][] (float x9, up to float x256) +988
  85. *
  86. * AUTO_BED_LEVELING_UBL: 6 bytes
  87. * 324 G29 A ubl.state.active (bool)
  88. * 325 G29 Z ubl.state.z_offset (float)
  89. * 329 G29 S ubl.state.storage_slot (int8_t)
  90. *
  91. * DELTA: 48 bytes
  92. * 348 M666 XYZ endstop_adj (float x3)
  93. * 360 M665 R delta_radius (float)
  94. * 364 M665 L delta_diagonal_rod (float)
  95. * 368 M665 S delta_segments_per_second (float)
  96. * 372 M665 B delta_calibration_radius (float)
  97. * 376 M665 X delta_tower_angle_trim[A] (float)
  98. * 380 M665 Y delta_tower_angle_trim[B] (float)
  99. * 384 M665 Z delta_tower_angle_trim[C] (float)
  100. *
  101. * Z_DUAL_ENDSTOPS: 48 bytes
  102. * 348 M666 Z z_endstop_adj (float)
  103. * --- dummy data (float x11)
  104. *
  105. * ULTIPANEL: 6 bytes
  106. * 396 M145 S0 H lcd_preheat_hotend_temp (int x2)
  107. * 400 M145 S0 B lcd_preheat_bed_temp (int x2)
  108. * 404 M145 S0 F lcd_preheat_fan_speed (int x2)
  109. *
  110. * PIDTEMP: 66 bytes
  111. * 408 M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
  112. * 424 M301 E1 PIDC Kp[1], Ki[1], Kd[1], Kc[1] (float x4)
  113. * 440 M301 E2 PIDC Kp[2], Ki[2], Kd[2], Kc[2] (float x4)
  114. * 456 M301 E3 PIDC Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
  115. * 472 M301 E4 PIDC Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
  116. * 488 M301 L lpq_len (int)
  117. *
  118. * PIDTEMPBED: 12 bytes
  119. * 490 M304 PID thermalManager.bedKp, .bedKi, .bedKd (float x3)
  120. *
  121. * DOGLCD: 2 bytes
  122. * 502 M250 C lcd_contrast (uint16_t)
  123. *
  124. * FWRETRACT: 33 bytes
  125. * 504 M209 S autoretract_enabled (bool)
  126. * 505 M207 S retract_length (float)
  127. * 509 M207 F retract_feedrate_mm_s (float)
  128. * 513 M207 Z retract_zlift (float)
  129. * 517 M208 S retract_recover_length (float)
  130. * 521 M208 F retract_recover_feedrate_mm_s (float)
  131. * 525 M207 W swap_retract_length (float)
  132. * 529 M208 W swap_retract_recover_length (float)
  133. * 533 M208 R swap_retract_recover_feedrate_mm_s (float)
  134. *
  135. * Volumetric Extrusion: 21 bytes
  136. * 537 M200 D volumetric_enabled (bool)
  137. * 538 M200 T D filament_size (float x5) (T0..3)
  138. *
  139. * HAVE_TMC2130: 20 bytes
  140. * 558 M906 X Stepper X current (uint16_t)
  141. * 560 M906 Y Stepper Y current (uint16_t)
  142. * 562 M906 Z Stepper Z current (uint16_t)
  143. * 564 M906 X2 Stepper X2 current (uint16_t)
  144. * 566 M906 Y2 Stepper Y2 current (uint16_t)
  145. * 568 M906 Z2 Stepper Z2 current (uint16_t)
  146. * 570 M906 E0 Stepper E0 current (uint16_t)
  147. * 572 M906 E1 Stepper E1 current (uint16_t)
  148. * 574 M906 E2 Stepper E2 current (uint16_t)
  149. * 576 M906 E3 Stepper E3 current (uint16_t)
  150. * 580 M906 E4 Stepper E4 current (uint16_t)
  151. *
  152. * LIN_ADVANCE: 8 bytes
  153. * 584 M900 K extruder_advance_k (float)
  154. * 588 M900 WHD advance_ed_ratio (float)
  155. *
  156. * HAS_MOTOR_CURRENT_PWM:
  157. * 592 M907 X Stepper XY current (uint32_t)
  158. * 596 M907 Z Stepper Z current (uint32_t)
  159. * 600 M907 E Stepper E current (uint32_t)
  160. *
  161. * 604 Minimum end-point
  162. * 1925 (604 + 36 + 9 + 288 + 988) Maximum end-point
  163. *
  164. * ========================================================================
  165. * meshes_begin (between max and min end-point, directly above)
  166. * -- MESHES --
  167. * meshes_end
  168. * -- MAT (Mesh Allocation Table) -- 128 bytes (placeholder size)
  169. * mat_end = E2END (0xFFF)
  170. *
  171. */
  172. #include "configuration_store.h"
  173. MarlinSettings settings;
  174. #include "Marlin.h"
  175. #include "language.h"
  176. #include "endstops.h"
  177. #include "planner.h"
  178. #include "temperature.h"
  179. #include "ultralcd.h"
  180. #include "stepper.h"
  181. #if ENABLED(INCH_MODE_SUPPORT) || (ENABLED(ULTIPANEL) && ENABLED(TEMPERATURE_UNITS_SUPPORT))
  182. #include "gcode.h"
  183. #endif
  184. #if ENABLED(MESH_BED_LEVELING)
  185. #include "mesh_bed_leveling.h"
  186. #endif
  187. #if ENABLED(HAVE_TMC2130)
  188. #include "stepper_indirection.h"
  189. #endif
  190. #if ENABLED(AUTO_BED_LEVELING_UBL)
  191. #include "ubl.h"
  192. #endif
  193. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  194. extern void refresh_bed_level();
  195. #endif
  196. /**
  197. * Post-process after Retrieve or Reset
  198. */
  199. void MarlinSettings::postprocess() {
  200. // steps per s2 needs to be updated to agree with units per s2
  201. planner.reset_acceleration_rates();
  202. // Make sure delta kinematics are updated before refreshing the
  203. // planner position so the stepper counts will be set correctly.
  204. #if ENABLED(DELTA)
  205. recalc_delta_settings(delta_radius, delta_diagonal_rod, delta_tower_angle_trim);
  206. #endif
  207. // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
  208. // and init stepper.count[], planner.position[] with current_position
  209. planner.refresh_positioning();
  210. #if ENABLED(PIDTEMP)
  211. thermalManager.updatePID();
  212. #endif
  213. calculate_volumetric_multipliers();
  214. #if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
  215. // Software endstops depend on home_offset
  216. LOOP_XYZ(i) update_software_endstops((AxisEnum)i);
  217. #endif
  218. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  219. set_z_fade_height(planner.z_fade_height);
  220. #endif
  221. #if HAS_BED_PROBE
  222. refresh_zprobe_zoffset();
  223. #endif
  224. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  225. refresh_bed_level();
  226. //set_bed_leveling_enabled(leveling_is_on);
  227. #endif
  228. #if HAS_MOTOR_CURRENT_PWM
  229. stepper.refresh_motor_power();
  230. #endif
  231. }
  232. #if ENABLED(EEPROM_SETTINGS)
  233. #define DUMMY_PID_VALUE 3000.0f
  234. #define EEPROM_START() int eeprom_index = EEPROM_OFFSET
  235. #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
  236. #define EEPROM_WRITE(VAR) write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
  237. #define EEPROM_READ(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
  238. #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
  239. const char version[4] = EEPROM_VERSION;
  240. bool MarlinSettings::eeprom_error;
  241. #if ENABLED(AUTO_BED_LEVELING_UBL)
  242. int MarlinSettings::meshes_begin;
  243. #endif
  244. void MarlinSettings::write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
  245. if (eeprom_error) return;
  246. while (size--) {
  247. uint8_t * const p = (uint8_t * const)pos;
  248. uint8_t v = *value;
  249. // EEPROM has only ~100,000 write cycles,
  250. // so only write bytes that have changed!
  251. if (v != eeprom_read_byte(p)) {
  252. eeprom_write_byte(p, v);
  253. if (eeprom_read_byte(p) != v) {
  254. SERIAL_ECHO_START();
  255. SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
  256. eeprom_error = true;
  257. return;
  258. }
  259. }
  260. crc16(crc, &v, 1);
  261. pos++;
  262. value++;
  263. };
  264. }
  265. void MarlinSettings::read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
  266. if (eeprom_error) return;
  267. do {
  268. uint8_t c = eeprom_read_byte((unsigned char*)pos);
  269. *value = c;
  270. crc16(crc, &c, 1);
  271. pos++;
  272. value++;
  273. } while (--size);
  274. }
  275. /**
  276. * M500 - Store Configuration
  277. */
  278. bool MarlinSettings::save() {
  279. float dummy = 0.0f;
  280. char ver[4] = "000";
  281. uint16_t working_crc = 0;
  282. EEPROM_START();
  283. eeprom_error = false;
  284. EEPROM_WRITE(ver); // invalidate data first
  285. EEPROM_SKIP(working_crc); // Skip the checksum slot
  286. working_crc = 0; // clear before first "real data"
  287. const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
  288. EEPROM_WRITE(esteppers);
  289. EEPROM_WRITE(planner.axis_steps_per_mm);
  290. EEPROM_WRITE(planner.max_feedrate_mm_s);
  291. EEPROM_WRITE(planner.max_acceleration_mm_per_s2);
  292. EEPROM_WRITE(planner.acceleration);
  293. EEPROM_WRITE(planner.retract_acceleration);
  294. EEPROM_WRITE(planner.travel_acceleration);
  295. EEPROM_WRITE(planner.min_feedrate_mm_s);
  296. EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
  297. EEPROM_WRITE(planner.min_segment_time);
  298. EEPROM_WRITE(planner.max_jerk);
  299. #if !HAS_HOME_OFFSET
  300. const float home_offset[XYZ] = { 0 };
  301. #endif
  302. #if ENABLED(DELTA)
  303. dummy = 0.0;
  304. EEPROM_WRITE(dummy);
  305. EEPROM_WRITE(dummy);
  306. dummy = DELTA_HEIGHT + home_offset[Z_AXIS];
  307. EEPROM_WRITE(dummy);
  308. #else
  309. EEPROM_WRITE(home_offset);
  310. #endif
  311. #if HOTENDS > 1
  312. // Skip hotend 0 which must be 0
  313. for (uint8_t e = 1; e < HOTENDS; e++)
  314. LOOP_XYZ(i) EEPROM_WRITE(hotend_offset[i][e]);
  315. #endif
  316. //
  317. // Global Leveling
  318. //
  319. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  320. const float zfh = planner.z_fade_height;
  321. #else
  322. const float zfh = 10.0;
  323. #endif
  324. EEPROM_WRITE(zfh);
  325. //
  326. // Mesh Bed Leveling
  327. //
  328. #if ENABLED(MESH_BED_LEVELING)
  329. // Compile time test that sizeof(mbl.z_values) is as expected
  330. static_assert(
  331. sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
  332. "MBL Z array is the wrong size."
  333. );
  334. const bool leveling_is_on = TEST(mbl.status, MBL_STATUS_HAS_MESH_BIT);
  335. const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
  336. EEPROM_WRITE(leveling_is_on);
  337. EEPROM_WRITE(mbl.z_offset);
  338. EEPROM_WRITE(mesh_num_x);
  339. EEPROM_WRITE(mesh_num_y);
  340. EEPROM_WRITE(mbl.z_values);
  341. #else // For disabled MBL write a default mesh
  342. const bool leveling_is_on = false;
  343. dummy = 0.0f;
  344. const uint8_t mesh_num_x = 3, mesh_num_y = 3;
  345. EEPROM_WRITE(leveling_is_on);
  346. EEPROM_WRITE(dummy); // z_offset
  347. EEPROM_WRITE(mesh_num_x);
  348. EEPROM_WRITE(mesh_num_y);
  349. for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummy);
  350. #endif // MESH_BED_LEVELING
  351. #if !HAS_BED_PROBE
  352. const float zprobe_zoffset = 0;
  353. #endif
  354. EEPROM_WRITE(zprobe_zoffset);
  355. //
  356. // Planar Bed Leveling matrix
  357. //
  358. #if ABL_PLANAR
  359. EEPROM_WRITE(planner.bed_level_matrix);
  360. #else
  361. dummy = 0.0;
  362. for (uint8_t q = 9; q--;) EEPROM_WRITE(dummy);
  363. #endif
  364. //
  365. // Bilinear Auto Bed Leveling
  366. //
  367. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  368. // Compile time test that sizeof(z_values) is as expected
  369. static_assert(
  370. sizeof(z_values) == GRID_MAX_POINTS * sizeof(z_values[0][0]),
  371. "Bilinear Z array is the wrong size."
  372. );
  373. const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y;
  374. EEPROM_WRITE(grid_max_x); // 1 byte
  375. EEPROM_WRITE(grid_max_y); // 1 byte
  376. EEPROM_WRITE(bilinear_grid_spacing); // 2 ints
  377. EEPROM_WRITE(bilinear_start); // 2 ints
  378. EEPROM_WRITE(z_values); // 9-256 floats
  379. #else
  380. // For disabled Bilinear Grid write an empty 3x3 grid
  381. const uint8_t grid_max_x = 3, grid_max_y = 3;
  382. const int bilinear_start[2] = { 0 }, bilinear_grid_spacing[2] = { 0 };
  383. dummy = 0.0f;
  384. EEPROM_WRITE(grid_max_x);
  385. EEPROM_WRITE(grid_max_y);
  386. EEPROM_WRITE(bilinear_grid_spacing);
  387. EEPROM_WRITE(bilinear_start);
  388. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
  389. #endif // AUTO_BED_LEVELING_BILINEAR
  390. #if ENABLED(AUTO_BED_LEVELING_UBL)
  391. EEPROM_WRITE(ubl.state.active);
  392. EEPROM_WRITE(ubl.state.z_offset);
  393. EEPROM_WRITE(ubl.state.storage_slot);
  394. #else
  395. const bool ubl_active = false;
  396. dummy = 0.0f;
  397. const int8_t storage_slot = -1;
  398. EEPROM_WRITE(ubl_active);
  399. EEPROM_WRITE(dummy);
  400. EEPROM_WRITE(storage_slot);
  401. #endif // AUTO_BED_LEVELING_UBL
  402. // 10 floats for DELTA / Z_DUAL_ENDSTOPS
  403. #if ENABLED(DELTA)
  404. EEPROM_WRITE(endstop_adj); // 3 floats
  405. EEPROM_WRITE(delta_radius); // 1 float
  406. EEPROM_WRITE(delta_diagonal_rod); // 1 float
  407. EEPROM_WRITE(delta_segments_per_second); // 1 float
  408. EEPROM_WRITE(delta_calibration_radius); // 1 float
  409. EEPROM_WRITE(delta_tower_angle_trim); // 3 floats
  410. dummy = 0.0f;
  411. for (uint8_t q = 2; q--;) EEPROM_WRITE(dummy);
  412. #elif ENABLED(Z_DUAL_ENDSTOPS)
  413. EEPROM_WRITE(z_endstop_adj); // 1 float
  414. dummy = 0.0f;
  415. for (uint8_t q = 11; q--;) EEPROM_WRITE(dummy);
  416. #else
  417. dummy = 0.0f;
  418. for (uint8_t q = 12; q--;) EEPROM_WRITE(dummy);
  419. #endif
  420. #if DISABLED(ULTIPANEL)
  421. constexpr int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
  422. lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
  423. lcd_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED };
  424. #endif
  425. EEPROM_WRITE(lcd_preheat_hotend_temp);
  426. EEPROM_WRITE(lcd_preheat_bed_temp);
  427. EEPROM_WRITE(lcd_preheat_fan_speed);
  428. for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
  429. #if ENABLED(PIDTEMP)
  430. if (e < HOTENDS) {
  431. EEPROM_WRITE(PID_PARAM(Kp, e));
  432. EEPROM_WRITE(PID_PARAM(Ki, e));
  433. EEPROM_WRITE(PID_PARAM(Kd, e));
  434. #if ENABLED(PID_EXTRUSION_SCALING)
  435. EEPROM_WRITE(PID_PARAM(Kc, e));
  436. #else
  437. dummy = 1.0f; // 1.0 = default kc
  438. EEPROM_WRITE(dummy);
  439. #endif
  440. }
  441. else
  442. #endif // !PIDTEMP
  443. {
  444. dummy = DUMMY_PID_VALUE; // When read, will not change the existing value
  445. EEPROM_WRITE(dummy); // Kp
  446. dummy = 0.0f;
  447. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy); // Ki, Kd, Kc
  448. }
  449. } // Hotends Loop
  450. #if DISABLED(PID_EXTRUSION_SCALING)
  451. int lpq_len = 20;
  452. #endif
  453. EEPROM_WRITE(lpq_len);
  454. #if DISABLED(PIDTEMPBED)
  455. dummy = DUMMY_PID_VALUE;
  456. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
  457. #else
  458. EEPROM_WRITE(thermalManager.bedKp);
  459. EEPROM_WRITE(thermalManager.bedKi);
  460. EEPROM_WRITE(thermalManager.bedKd);
  461. #endif
  462. #if !HAS_LCD_CONTRAST
  463. const uint16_t lcd_contrast = 32;
  464. #endif
  465. EEPROM_WRITE(lcd_contrast);
  466. #if DISABLED(FWRETRACT)
  467. const bool autoretract_enabled = false;
  468. const float retract_length = 3,
  469. retract_feedrate_mm_s = 45,
  470. retract_zlift = 0,
  471. retract_recover_length = 0,
  472. retract_recover_feedrate_mm_s = 0,
  473. swap_retract_length = 13,
  474. swap_retract_recover_length = 0,
  475. swap_retract_recover_feedrate_mm_s = 8;
  476. #endif
  477. EEPROM_WRITE(autoretract_enabled);
  478. EEPROM_WRITE(retract_length);
  479. EEPROM_WRITE(retract_feedrate_mm_s);
  480. EEPROM_WRITE(retract_zlift);
  481. EEPROM_WRITE(retract_recover_length);
  482. EEPROM_WRITE(retract_recover_feedrate_mm_s);
  483. EEPROM_WRITE(swap_retract_length);
  484. EEPROM_WRITE(swap_retract_recover_length);
  485. EEPROM_WRITE(swap_retract_recover_feedrate_mm_s);
  486. EEPROM_WRITE(volumetric_enabled);
  487. // Save filament sizes
  488. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  489. if (q < COUNT(filament_size)) dummy = filament_size[q];
  490. EEPROM_WRITE(dummy);
  491. }
  492. // Save TMC2130 Configuration, and placeholder values
  493. uint16_t val;
  494. #if ENABLED(HAVE_TMC2130)
  495. #if ENABLED(X_IS_TMC2130)
  496. val = stepperX.getCurrent();
  497. #else
  498. val = 0;
  499. #endif
  500. EEPROM_WRITE(val);
  501. #if ENABLED(Y_IS_TMC2130)
  502. val = stepperY.getCurrent();
  503. #else
  504. val = 0;
  505. #endif
  506. EEPROM_WRITE(val);
  507. #if ENABLED(Z_IS_TMC2130)
  508. val = stepperZ.getCurrent();
  509. #else
  510. val = 0;
  511. #endif
  512. EEPROM_WRITE(val);
  513. #if ENABLED(X2_IS_TMC2130)
  514. val = stepperX2.getCurrent();
  515. #else
  516. val = 0;
  517. #endif
  518. EEPROM_WRITE(val);
  519. #if ENABLED(Y2_IS_TMC2130)
  520. val = stepperY2.getCurrent();
  521. #else
  522. val = 0;
  523. #endif
  524. EEPROM_WRITE(val);
  525. #if ENABLED(Z2_IS_TMC2130)
  526. val = stepperZ2.getCurrent();
  527. #else
  528. val = 0;
  529. #endif
  530. EEPROM_WRITE(val);
  531. #if ENABLED(E0_IS_TMC2130)
  532. val = stepperE0.getCurrent();
  533. #else
  534. val = 0;
  535. #endif
  536. EEPROM_WRITE(val);
  537. #if ENABLED(E1_IS_TMC2130)
  538. val = stepperE1.getCurrent();
  539. #else
  540. val = 0;
  541. #endif
  542. EEPROM_WRITE(val);
  543. #if ENABLED(E2_IS_TMC2130)
  544. val = stepperE2.getCurrent();
  545. #else
  546. val = 0;
  547. #endif
  548. EEPROM_WRITE(val);
  549. #if ENABLED(E3_IS_TMC2130)
  550. val = stepperE3.getCurrent();
  551. #else
  552. val = 0;
  553. #endif
  554. EEPROM_WRITE(val);
  555. #if ENABLED(E4_IS_TMC2130)
  556. val = stepperE4.getCurrent();
  557. #else
  558. val = 0;
  559. #endif
  560. EEPROM_WRITE(val);
  561. #else
  562. val = 0;
  563. for (uint8_t q = 11; q--;) EEPROM_WRITE(val);
  564. #endif
  565. //
  566. // Linear Advance
  567. //
  568. #if ENABLED(LIN_ADVANCE)
  569. EEPROM_WRITE(planner.extruder_advance_k);
  570. EEPROM_WRITE(planner.advance_ed_ratio);
  571. #else
  572. dummy = 0.0f;
  573. EEPROM_WRITE(dummy);
  574. EEPROM_WRITE(dummy);
  575. #endif
  576. #if HAS_MOTOR_CURRENT_PWM
  577. for (uint8_t q = 3; q--;) EEPROM_WRITE(stepper.motor_current_setting[q]);
  578. #else
  579. const uint32_t dummyui32 = 0;
  580. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummyui32);
  581. #endif
  582. if (!eeprom_error) {
  583. const int eeprom_size = eeprom_index;
  584. const uint16_t final_crc = working_crc;
  585. // Write the EEPROM header
  586. eeprom_index = EEPROM_OFFSET;
  587. EEPROM_WRITE(version);
  588. EEPROM_WRITE(final_crc);
  589. // Report storage size
  590. #if ENABLED(EEPROM_CHITCHAT)
  591. SERIAL_ECHO_START();
  592. SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET));
  593. SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)final_crc);
  594. SERIAL_ECHOLNPGM(")");
  595. #endif
  596. }
  597. #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
  598. if (ubl.state.storage_slot >= 0)
  599. store_mesh(ubl.state.storage_slot);
  600. #endif
  601. return !eeprom_error;
  602. }
  603. /**
  604. * M501 - Retrieve Configuration
  605. */
  606. bool MarlinSettings::load() {
  607. uint16_t working_crc = 0;
  608. EEPROM_START();
  609. char stored_ver[4];
  610. EEPROM_READ(stored_ver);
  611. uint16_t stored_crc;
  612. EEPROM_READ(stored_crc);
  613. // Version has to match or defaults are used
  614. if (strncmp(version, stored_ver, 3) != 0) {
  615. if (stored_ver[0] != 'V') {
  616. stored_ver[0] = '?';
  617. stored_ver[1] = '\0';
  618. }
  619. #if ENABLED(EEPROM_CHITCHAT)
  620. SERIAL_ECHO_START();
  621. SERIAL_ECHOPGM("EEPROM version mismatch ");
  622. SERIAL_ECHOPAIR("(EEPROM=", stored_ver);
  623. SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")");
  624. #endif
  625. reset();
  626. }
  627. else {
  628. float dummy = 0;
  629. bool dummyb;
  630. working_crc = 0; //clear before reading first "real data"
  631. // Number of esteppers may change
  632. uint8_t esteppers;
  633. EEPROM_READ(esteppers);
  634. // Get only the number of E stepper parameters previously stored
  635. // Any steppers added later are set to their defaults
  636. const float def1[] = DEFAULT_AXIS_STEPS_PER_UNIT, def2[] = DEFAULT_MAX_FEEDRATE;
  637. const uint32_t def3[] = DEFAULT_MAX_ACCELERATION;
  638. float tmp1[XYZ + esteppers], tmp2[XYZ + esteppers];
  639. uint32_t tmp3[XYZ + esteppers];
  640. EEPROM_READ(tmp1);
  641. EEPROM_READ(tmp2);
  642. EEPROM_READ(tmp3);
  643. LOOP_XYZE_N(i) {
  644. planner.axis_steps_per_mm[i] = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
  645. planner.max_feedrate_mm_s[i] = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
  646. planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
  647. }
  648. EEPROM_READ(planner.acceleration);
  649. EEPROM_READ(planner.retract_acceleration);
  650. EEPROM_READ(planner.travel_acceleration);
  651. EEPROM_READ(planner.min_feedrate_mm_s);
  652. EEPROM_READ(planner.min_travel_feedrate_mm_s);
  653. EEPROM_READ(planner.min_segment_time);
  654. EEPROM_READ(planner.max_jerk);
  655. #if !HAS_HOME_OFFSET
  656. float home_offset[XYZ];
  657. #endif
  658. EEPROM_READ(home_offset);
  659. #if ENABLED(DELTA)
  660. home_offset[X_AXIS] = 0.0;
  661. home_offset[Y_AXIS] = 0.0;
  662. home_offset[Z_AXIS] -= DELTA_HEIGHT;
  663. #endif
  664. #if HOTENDS > 1
  665. // Skip hotend 0 which must be 0
  666. for (uint8_t e = 1; e < HOTENDS; e++)
  667. LOOP_XYZ(i) EEPROM_READ(hotend_offset[i][e]);
  668. #endif
  669. //
  670. // Global Leveling
  671. //
  672. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  673. EEPROM_READ(planner.z_fade_height);
  674. #else
  675. EEPROM_READ(dummy);
  676. #endif
  677. //
  678. // Mesh (Manual) Bed Leveling
  679. //
  680. bool leveling_is_on;
  681. uint8_t mesh_num_x, mesh_num_y;
  682. EEPROM_READ(leveling_is_on);
  683. EEPROM_READ(dummy);
  684. EEPROM_READ(mesh_num_x);
  685. EEPROM_READ(mesh_num_y);
  686. #if ENABLED(MESH_BED_LEVELING)
  687. mbl.status = leveling_is_on ? _BV(MBL_STATUS_HAS_MESH_BIT) : 0;
  688. mbl.z_offset = dummy;
  689. if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
  690. // EEPROM data fits the current mesh
  691. EEPROM_READ(mbl.z_values);
  692. }
  693. else {
  694. // EEPROM data is stale
  695. mbl.reset();
  696. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
  697. }
  698. #else
  699. // MBL is disabled - skip the stored data
  700. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
  701. #endif // MESH_BED_LEVELING
  702. #if !HAS_BED_PROBE
  703. float zprobe_zoffset;
  704. #endif
  705. EEPROM_READ(zprobe_zoffset);
  706. //
  707. // Planar Bed Leveling matrix
  708. //
  709. #if ABL_PLANAR
  710. EEPROM_READ(planner.bed_level_matrix);
  711. #else
  712. for (uint8_t q = 9; q--;) EEPROM_READ(dummy);
  713. #endif
  714. //
  715. // Bilinear Auto Bed Leveling
  716. //
  717. uint8_t grid_max_x, grid_max_y;
  718. EEPROM_READ(grid_max_x); // 1 byte
  719. EEPROM_READ(grid_max_y); // 1 byte
  720. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  721. if (grid_max_x == GRID_MAX_POINTS_X && grid_max_y == GRID_MAX_POINTS_Y) {
  722. set_bed_leveling_enabled(false);
  723. EEPROM_READ(bilinear_grid_spacing); // 2 ints
  724. EEPROM_READ(bilinear_start); // 2 ints
  725. EEPROM_READ(z_values); // 9 to 256 floats
  726. }
  727. else // EEPROM data is stale
  728. #endif // AUTO_BED_LEVELING_BILINEAR
  729. {
  730. // Skip past disabled (or stale) Bilinear Grid data
  731. int bgs[2], bs[2];
  732. EEPROM_READ(bgs);
  733. EEPROM_READ(bs);
  734. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummy);
  735. }
  736. #if ENABLED(AUTO_BED_LEVELING_UBL)
  737. EEPROM_READ(ubl.state.active);
  738. EEPROM_READ(ubl.state.z_offset);
  739. EEPROM_READ(ubl.state.storage_slot);
  740. #else
  741. uint8_t dummyui8;
  742. EEPROM_READ(dummyb);
  743. EEPROM_READ(dummy);
  744. EEPROM_READ(dummyui8);
  745. #endif // AUTO_BED_LEVELING_UBL
  746. #if ENABLED(DELTA)
  747. EEPROM_READ(endstop_adj); // 3 floats
  748. EEPROM_READ(delta_radius); // 1 float
  749. EEPROM_READ(delta_diagonal_rod); // 1 float
  750. EEPROM_READ(delta_segments_per_second); // 1 float
  751. EEPROM_READ(delta_calibration_radius); // 1 float
  752. EEPROM_READ(delta_tower_angle_trim); // 3 floats
  753. dummy = 0.0f;
  754. for (uint8_t q=2; q--;) EEPROM_READ(dummy);
  755. #elif ENABLED(Z_DUAL_ENDSTOPS)
  756. EEPROM_READ(z_endstop_adj);
  757. dummy = 0.0f;
  758. for (uint8_t q=11; q--;) EEPROM_READ(dummy);
  759. #else
  760. dummy = 0.0f;
  761. for (uint8_t q=12; q--;) EEPROM_READ(dummy);
  762. #endif
  763. #if DISABLED(ULTIPANEL)
  764. int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  765. #endif
  766. EEPROM_READ(lcd_preheat_hotend_temp);
  767. EEPROM_READ(lcd_preheat_bed_temp);
  768. EEPROM_READ(lcd_preheat_fan_speed);
  769. //EEPROM_ASSERT(
  770. // WITHIN(lcd_preheat_fan_speed, 0, 255),
  771. // "lcd_preheat_fan_speed out of range"
  772. //);
  773. #if ENABLED(PIDTEMP)
  774. for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
  775. EEPROM_READ(dummy); // Kp
  776. if (e < HOTENDS && dummy != DUMMY_PID_VALUE) {
  777. // do not need to scale PID values as the values in EEPROM are already scaled
  778. PID_PARAM(Kp, e) = dummy;
  779. EEPROM_READ(PID_PARAM(Ki, e));
  780. EEPROM_READ(PID_PARAM(Kd, e));
  781. #if ENABLED(PID_EXTRUSION_SCALING)
  782. EEPROM_READ(PID_PARAM(Kc, e));
  783. #else
  784. EEPROM_READ(dummy);
  785. #endif
  786. }
  787. else {
  788. for (uint8_t q=3; q--;) EEPROM_READ(dummy); // Ki, Kd, Kc
  789. }
  790. }
  791. #else // !PIDTEMP
  792. // 4 x 4 = 16 slots for PID parameters
  793. for (uint8_t q = MAX_EXTRUDERS * 4; q--;) EEPROM_READ(dummy); // Kp, Ki, Kd, Kc
  794. #endif // !PIDTEMP
  795. #if DISABLED(PID_EXTRUSION_SCALING)
  796. int lpq_len;
  797. #endif
  798. EEPROM_READ(lpq_len);
  799. #if ENABLED(PIDTEMPBED)
  800. EEPROM_READ(dummy); // bedKp
  801. if (dummy != DUMMY_PID_VALUE) {
  802. thermalManager.bedKp = dummy;
  803. EEPROM_READ(thermalManager.bedKi);
  804. EEPROM_READ(thermalManager.bedKd);
  805. }
  806. #else
  807. for (uint8_t q=3; q--;) EEPROM_READ(dummy); // bedKp, bedKi, bedKd
  808. #endif
  809. #if !HAS_LCD_CONTRAST
  810. uint16_t lcd_contrast;
  811. #endif
  812. EEPROM_READ(lcd_contrast);
  813. #if ENABLED(FWRETRACT)
  814. EEPROM_READ(autoretract_enabled);
  815. EEPROM_READ(retract_length);
  816. EEPROM_READ(retract_feedrate_mm_s);
  817. EEPROM_READ(retract_zlift);
  818. EEPROM_READ(retract_recover_length);
  819. EEPROM_READ(retract_recover_feedrate_mm_s);
  820. EEPROM_READ(swap_retract_length);
  821. EEPROM_READ(swap_retract_recover_length);
  822. EEPROM_READ(swap_retract_recover_feedrate_mm_s);
  823. #else
  824. EEPROM_READ(dummyb);
  825. for (uint8_t q=8; q--;) EEPROM_READ(dummy);
  826. #endif
  827. EEPROM_READ(volumetric_enabled);
  828. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  829. EEPROM_READ(dummy);
  830. if (q < COUNT(filament_size)) filament_size[q] = dummy;
  831. }
  832. uint16_t val;
  833. #if ENABLED(HAVE_TMC2130)
  834. EEPROM_READ(val);
  835. #if ENABLED(X_IS_TMC2130)
  836. stepperX.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  837. #endif
  838. EEPROM_READ(val);
  839. #if ENABLED(Y_IS_TMC2130)
  840. stepperY.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  841. #endif
  842. EEPROM_READ(val);
  843. #if ENABLED(Z_IS_TMC2130)
  844. stepperZ.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  845. #endif
  846. EEPROM_READ(val);
  847. #if ENABLED(X2_IS_TMC2130)
  848. stepperX2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  849. #endif
  850. EEPROM_READ(val);
  851. #if ENABLED(Y2_IS_TMC2130)
  852. stepperY2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  853. #endif
  854. EEPROM_READ(val);
  855. #if ENABLED(Z2_IS_TMC2130)
  856. stepperZ2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  857. #endif
  858. EEPROM_READ(val);
  859. #if ENABLED(E0_IS_TMC2130)
  860. stepperE0.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  861. #endif
  862. EEPROM_READ(val);
  863. #if ENABLED(E1_IS_TMC2130)
  864. stepperE1.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  865. #endif
  866. EEPROM_READ(val);
  867. #if ENABLED(E2_IS_TMC2130)
  868. stepperE2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  869. #endif
  870. EEPROM_READ(val);
  871. #if ENABLED(E3_IS_TMC2130)
  872. stepperE3.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  873. #endif
  874. EEPROM_READ(val);
  875. #if ENABLED(E4_IS_TMC2130)
  876. stepperE4.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
  877. #endif
  878. #else
  879. for (uint8_t q = 0; q < 11; q++) EEPROM_READ(val);
  880. #endif
  881. //
  882. // Linear Advance
  883. //
  884. #if ENABLED(LIN_ADVANCE)
  885. EEPROM_READ(planner.extruder_advance_k);
  886. EEPROM_READ(planner.advance_ed_ratio);
  887. #else
  888. EEPROM_READ(dummy);
  889. EEPROM_READ(dummy);
  890. #endif
  891. #if HAS_MOTOR_CURRENT_PWM
  892. for (uint8_t q = 3; q--;) EEPROM_READ(stepper.motor_current_setting[q]);
  893. #else
  894. uint32_t dummyui32;
  895. for (uint8_t q = 3; q--;) EEPROM_READ(dummyui32);
  896. #endif
  897. if (working_crc == stored_crc) {
  898. postprocess();
  899. #if ENABLED(EEPROM_CHITCHAT)
  900. SERIAL_ECHO_START();
  901. SERIAL_ECHO(version);
  902. SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET));
  903. SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)working_crc);
  904. SERIAL_ECHOLNPGM(")");
  905. #endif
  906. }
  907. else {
  908. #if ENABLED(EEPROM_CHITCHAT)
  909. SERIAL_ERROR_START();
  910. SERIAL_ERRORPGM("EEPROM CRC mismatch - (stored) ");
  911. SERIAL_ERROR(stored_crc);
  912. SERIAL_ERRORPGM(" != ");
  913. SERIAL_ERROR(working_crc);
  914. SERIAL_ERRORLNPGM(" (calculated)!");
  915. #endif
  916. reset();
  917. }
  918. #if ENABLED(AUTO_BED_LEVELING_UBL)
  919. meshes_begin = (eeprom_index + 32) & 0xFFF8; // Pad the end of configuration data so it
  920. // can float up or down a little bit without
  921. // disrupting the mesh data
  922. ubl.report_state();
  923. if (!ubl.sanity_check()) {
  924. SERIAL_EOL();
  925. #if ENABLED(EEPROM_CHITCHAT)
  926. ubl.echo_name();
  927. SERIAL_ECHOLNPGM(" initialized.\n");
  928. #endif
  929. }
  930. else {
  931. #if ENABLED(EEPROM_CHITCHAT)
  932. SERIAL_PROTOCOLPGM("?Can't enable ");
  933. ubl.echo_name();
  934. SERIAL_PROTOCOLLNPGM(".");
  935. #endif
  936. ubl.reset();
  937. }
  938. if (ubl.state.storage_slot >= 0) {
  939. load_mesh(ubl.state.storage_slot);
  940. #if ENABLED(EEPROM_CHITCHAT)
  941. SERIAL_ECHOPAIR("Mesh ", ubl.state.storage_slot);
  942. SERIAL_ECHOLNPGM(" loaded from storage.");
  943. #endif
  944. }
  945. else {
  946. ubl.reset();
  947. #if ENABLED(EEPROM_CHITCHAT)
  948. SERIAL_ECHOLNPGM("UBL System reset()");
  949. #endif
  950. }
  951. #endif
  952. }
  953. #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
  954. report();
  955. #endif
  956. return !eeprom_error;
  957. }
  958. #if ENABLED(AUTO_BED_LEVELING_UBL)
  959. #if ENABLED(EEPROM_CHITCHAT)
  960. void ubl_invalid_slot(const int s) {
  961. SERIAL_PROTOCOLLNPGM("?Invalid slot.");
  962. SERIAL_PROTOCOL(s);
  963. SERIAL_PROTOCOLLNPGM(" mesh slots available.");
  964. }
  965. #endif
  966. int MarlinSettings::calc_num_meshes() {
  967. //obviously this will get more sophisticated once we've added an actual MAT
  968. if (meshes_begin <= 0) return 0;
  969. return (meshes_end - meshes_begin) / sizeof(ubl.z_values);
  970. }
  971. void MarlinSettings::store_mesh(int8_t slot) {
  972. #if ENABLED(AUTO_BED_LEVELING_UBL)
  973. const int a = calc_num_meshes();
  974. if (!WITHIN(slot, 0, a - 1)) {
  975. #if ENABLED(EEPROM_CHITCHAT)
  976. ubl_invalid_slot(a);
  977. SERIAL_PROTOCOLPAIR("E2END=", E2END);
  978. SERIAL_PROTOCOLPAIR(" meshes_end=", meshes_end);
  979. SERIAL_PROTOCOLLNPAIR(" slot=", slot);
  980. SERIAL_EOL();
  981. #endif
  982. return;
  983. }
  984. uint16_t crc = 0;
  985. int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values);
  986. write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc);
  987. // Write crc to MAT along with other data, or just tack on to the beginning or end
  988. #if ENABLED(EEPROM_CHITCHAT)
  989. SERIAL_PROTOCOLLNPAIR("Mesh saved in slot ", slot);
  990. #endif
  991. #else
  992. // Other mesh types
  993. #endif
  994. }
  995. void MarlinSettings::load_mesh(int8_t slot, void *into /* = 0 */) {
  996. #if ENABLED(AUTO_BED_LEVELING_UBL)
  997. const int16_t a = settings.calc_num_meshes();
  998. if (!WITHIN(slot, 0, a - 1)) {
  999. #if ENABLED(EEPROM_CHITCHAT)
  1000. ubl_invalid_slot(a);
  1001. #endif
  1002. return;
  1003. }
  1004. uint16_t crc = 0;
  1005. int pos = meshes_end - (slot + 1) * sizeof(ubl.z_values);
  1006. uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
  1007. read_data(pos, dest, sizeof(ubl.z_values), &crc);
  1008. // Compare crc with crc from MAT, or read from end
  1009. #if ENABLED(EEPROM_CHITCHAT)
  1010. SERIAL_PROTOCOLLNPAIR("Mesh loaded from slot ", slot);
  1011. #endif
  1012. #else
  1013. // Other mesh types
  1014. #endif
  1015. }
  1016. //void MarlinSettings::delete_mesh() { return; }
  1017. //void MarlinSettings::defrag_meshes() { return; }
  1018. #endif // AUTO_BED_LEVELING_UBL
  1019. #else // !EEPROM_SETTINGS
  1020. bool MarlinSettings::save() {
  1021. SERIAL_ERROR_START();
  1022. SERIAL_ERRORLNPGM("EEPROM disabled");
  1023. return false;
  1024. }
  1025. #endif // !EEPROM_SETTINGS
  1026. /**
  1027. * M502 - Reset Configuration
  1028. */
  1029. void MarlinSettings::reset() {
  1030. static const float tmp1[] PROGMEM = DEFAULT_AXIS_STEPS_PER_UNIT, tmp2[] PROGMEM = DEFAULT_MAX_FEEDRATE;
  1031. static const uint32_t tmp3[] PROGMEM = DEFAULT_MAX_ACCELERATION;
  1032. LOOP_XYZE_N(i) {
  1033. planner.axis_steps_per_mm[i] = pgm_read_float(&tmp1[i < COUNT(tmp1) ? i : COUNT(tmp1) - 1]);
  1034. planner.max_feedrate_mm_s[i] = pgm_read_float(&tmp2[i < COUNT(tmp2) ? i : COUNT(tmp2) - 1]);
  1035. planner.max_acceleration_mm_per_s2[i] = pgm_read_dword_near(&tmp3[i < COUNT(tmp3) ? i : COUNT(tmp3) - 1]);
  1036. }
  1037. planner.acceleration = DEFAULT_ACCELERATION;
  1038. planner.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
  1039. planner.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
  1040. planner.min_feedrate_mm_s = DEFAULT_MINIMUMFEEDRATE;
  1041. planner.min_segment_time = DEFAULT_MINSEGMENTTIME;
  1042. planner.min_travel_feedrate_mm_s = DEFAULT_MINTRAVELFEEDRATE;
  1043. planner.max_jerk[X_AXIS] = DEFAULT_XJERK;
  1044. planner.max_jerk[Y_AXIS] = DEFAULT_YJERK;
  1045. planner.max_jerk[Z_AXIS] = DEFAULT_ZJERK;
  1046. planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
  1047. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1048. planner.z_fade_height = 0.0;
  1049. #endif
  1050. #if HAS_HOME_OFFSET
  1051. ZERO(home_offset);
  1052. #endif
  1053. #if HOTENDS > 1
  1054. constexpr float tmp4[XYZ][HOTENDS] = {
  1055. HOTEND_OFFSET_X,
  1056. HOTEND_OFFSET_Y
  1057. #ifdef HOTEND_OFFSET_Z
  1058. , HOTEND_OFFSET_Z
  1059. #else
  1060. , { 0 }
  1061. #endif
  1062. };
  1063. static_assert(
  1064. tmp4[X_AXIS][0] == 0 && tmp4[Y_AXIS][0] == 0 && tmp4[Z_AXIS][0] == 0,
  1065. "Offsets for the first hotend must be 0.0."
  1066. );
  1067. LOOP_XYZ(i) HOTEND_LOOP() hotend_offset[i][e] = tmp4[i][e];
  1068. #endif
  1069. // Applies to all MBL and ABL
  1070. #if HAS_LEVELING
  1071. reset_bed_level();
  1072. #endif
  1073. #if HAS_BED_PROBE
  1074. zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER;
  1075. #endif
  1076. #if ENABLED(DELTA)
  1077. const float adj[ABC] = DELTA_ENDSTOP_ADJ,
  1078. dta[ABC] = DELTA_TOWER_ANGLE_TRIM;
  1079. COPY(endstop_adj, adj);
  1080. delta_radius = DELTA_RADIUS;
  1081. delta_diagonal_rod = DELTA_DIAGONAL_ROD;
  1082. delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
  1083. delta_calibration_radius = DELTA_CALIBRATION_RADIUS;
  1084. COPY(delta_tower_angle_trim, dta);
  1085. home_offset[Z_AXIS] = 0;
  1086. #elif ENABLED(Z_DUAL_ENDSTOPS)
  1087. z_endstop_adj =
  1088. #ifdef Z_DUAL_ENDSTOPS_ADJUSTMENT
  1089. Z_DUAL_ENDSTOPS_ADJUSTMENT
  1090. #else
  1091. 0
  1092. #endif
  1093. ;
  1094. #endif
  1095. #if ENABLED(ULTIPANEL)
  1096. lcd_preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
  1097. lcd_preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
  1098. lcd_preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
  1099. lcd_preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
  1100. lcd_preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
  1101. lcd_preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
  1102. #endif
  1103. #if HAS_LCD_CONTRAST
  1104. lcd_contrast = DEFAULT_LCD_CONTRAST;
  1105. #endif
  1106. #if ENABLED(PIDTEMP)
  1107. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  1108. HOTEND_LOOP()
  1109. #endif
  1110. {
  1111. PID_PARAM(Kp, e) = DEFAULT_Kp;
  1112. PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
  1113. PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
  1114. #if ENABLED(PID_EXTRUSION_SCALING)
  1115. PID_PARAM(Kc, e) = DEFAULT_Kc;
  1116. #endif
  1117. }
  1118. #if ENABLED(PID_EXTRUSION_SCALING)
  1119. lpq_len = 20; // default last-position-queue size
  1120. #endif
  1121. #endif // PIDTEMP
  1122. #if ENABLED(PIDTEMPBED)
  1123. thermalManager.bedKp = DEFAULT_bedKp;
  1124. thermalManager.bedKi = scalePID_i(DEFAULT_bedKi);
  1125. thermalManager.bedKd = scalePID_d(DEFAULT_bedKd);
  1126. #endif
  1127. #if ENABLED(FWRETRACT)
  1128. autoretract_enabled = false;
  1129. retract_length = RETRACT_LENGTH;
  1130. retract_feedrate_mm_s = RETRACT_FEEDRATE;
  1131. retract_zlift = RETRACT_ZLIFT;
  1132. retract_recover_length = RETRACT_RECOVER_LENGTH;
  1133. retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE;
  1134. swap_retract_length = RETRACT_LENGTH_SWAP;
  1135. swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP;
  1136. swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
  1137. #endif // FWRETRACT
  1138. volumetric_enabled =
  1139. #if ENABLED(VOLUMETRIC_DEFAULT_ON)
  1140. true
  1141. #else
  1142. false
  1143. #endif
  1144. ;
  1145. for (uint8_t q = 0; q < COUNT(filament_size); q++)
  1146. filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
  1147. endstops.enable_globally(
  1148. #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
  1149. true
  1150. #else
  1151. false
  1152. #endif
  1153. );
  1154. #if ENABLED(HAVE_TMC2130)
  1155. #if ENABLED(X_IS_TMC2130)
  1156. stepperX.setCurrent(X_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1157. #endif
  1158. #if ENABLED(Y_IS_TMC2130)
  1159. stepperY.setCurrent(Y_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1160. #endif
  1161. #if ENABLED(Z_IS_TMC2130)
  1162. stepperZ.setCurrent(Z_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1163. #endif
  1164. #if ENABLED(X2_IS_TMC2130)
  1165. stepperX2.setCurrent(X2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1166. #endif
  1167. #if ENABLED(Y2_IS_TMC2130)
  1168. stepperY2.setCurrent(Y2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1169. #endif
  1170. #if ENABLED(Z2_IS_TMC2130)
  1171. stepperZ2.setCurrent(Z2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1172. #endif
  1173. #if ENABLED(E0_IS_TMC2130)
  1174. stepperE0.setCurrent(E0_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1175. #endif
  1176. #if ENABLED(E1_IS_TMC2130)
  1177. stepperE1.setCurrent(E1_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1178. #endif
  1179. #if ENABLED(E2_IS_TMC2130)
  1180. stepperE2.setCurrent(E2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1181. #endif
  1182. #if ENABLED(E3_IS_TMC2130)
  1183. stepperE3.setCurrent(E3_CURRENT, R_SENSE, HOLD_MULTIPLIER);
  1184. #endif
  1185. #endif
  1186. #if ENABLED(LIN_ADVANCE)
  1187. planner.extruder_advance_k = LIN_ADVANCE_K;
  1188. planner.advance_ed_ratio = LIN_ADVANCE_E_D_RATIO;
  1189. #endif
  1190. #if HAS_MOTOR_CURRENT_PWM
  1191. uint32_t tmp_motor_current_setting[3] = PWM_MOTOR_CURRENT;
  1192. for (uint8_t q = 3; q--;)
  1193. stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
  1194. #endif
  1195. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1196. ubl.reset();
  1197. #endif
  1198. postprocess();
  1199. #if ENABLED(EEPROM_CHITCHAT)
  1200. SERIAL_ECHO_START();
  1201. SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
  1202. #endif
  1203. }
  1204. #if DISABLED(DISABLE_M503)
  1205. #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START(); }while(0)
  1206. /**
  1207. * M503 - Report current settings in RAM
  1208. *
  1209. * Unless specifically disabled, M503 is available even without EEPROM
  1210. */
  1211. void MarlinSettings::report(bool forReplay) {
  1212. /**
  1213. * Announce current units, in case inches are being displayed
  1214. */
  1215. CONFIG_ECHO_START;
  1216. #if ENABLED(INCH_MODE_SUPPORT)
  1217. #define LINEAR_UNIT(N) ((N) / parser.linear_unit_factor)
  1218. #define VOLUMETRIC_UNIT(N) ((N) / (volumetric_enabled ? parser.volumetric_unit_factor : parser.linear_unit_factor))
  1219. SERIAL_ECHOPGM(" G2");
  1220. SERIAL_CHAR(parser.linear_unit_factor == 1.0 ? '1' : '0');
  1221. SERIAL_ECHOPGM(" ; Units in ");
  1222. serialprintPGM(parser.linear_unit_factor == 1.0 ? PSTR("mm\n") : PSTR("inches\n"));
  1223. #else
  1224. #define LINEAR_UNIT(N) N
  1225. #define VOLUMETRIC_UNIT(N) N
  1226. SERIAL_ECHOLNPGM(" G21 ; Units in mm");
  1227. #endif
  1228. #if ENABLED(ULTIPANEL)
  1229. // Temperature units - for Ultipanel temperature options
  1230. CONFIG_ECHO_START;
  1231. #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
  1232. #define TEMP_UNIT(N) parser.to_temp_units(N)
  1233. SERIAL_ECHOPGM(" M149 ");
  1234. SERIAL_CHAR(parser.temp_units_code());
  1235. SERIAL_ECHOPGM(" ; Units in ");
  1236. serialprintPGM(parser.temp_units_name());
  1237. #else
  1238. #define TEMP_UNIT(N) N
  1239. SERIAL_ECHOLNPGM(" M149 C ; Units in Celsius");
  1240. #endif
  1241. #endif
  1242. SERIAL_EOL();
  1243. /**
  1244. * Volumetric extrusion M200
  1245. */
  1246. if (!forReplay) {
  1247. CONFIG_ECHO_START;
  1248. SERIAL_ECHOPGM("Filament settings:");
  1249. if (volumetric_enabled)
  1250. SERIAL_EOL();
  1251. else
  1252. SERIAL_ECHOLNPGM(" Disabled");
  1253. }
  1254. CONFIG_ECHO_START;
  1255. SERIAL_ECHOPAIR(" M200 D", filament_size[0]);
  1256. SERIAL_EOL();
  1257. #if EXTRUDERS > 1
  1258. CONFIG_ECHO_START;
  1259. SERIAL_ECHOPAIR(" M200 T1 D", filament_size[1]);
  1260. SERIAL_EOL();
  1261. #if EXTRUDERS > 2
  1262. CONFIG_ECHO_START;
  1263. SERIAL_ECHOPAIR(" M200 T2 D", filament_size[2]);
  1264. SERIAL_EOL();
  1265. #if EXTRUDERS > 3
  1266. CONFIG_ECHO_START;
  1267. SERIAL_ECHOPAIR(" M200 T3 D", filament_size[3]);
  1268. SERIAL_EOL();
  1269. #if EXTRUDERS > 4
  1270. CONFIG_ECHO_START;
  1271. SERIAL_ECHOPAIR(" M200 T4 D", filament_size[4]);
  1272. SERIAL_EOL();
  1273. #endif // EXTRUDERS > 4
  1274. #endif // EXTRUDERS > 3
  1275. #endif // EXTRUDERS > 2
  1276. #endif // EXTRUDERS > 1
  1277. if (!volumetric_enabled) {
  1278. CONFIG_ECHO_START;
  1279. SERIAL_ECHOLNPGM(" M200 D0");
  1280. }
  1281. if (!forReplay) {
  1282. CONFIG_ECHO_START;
  1283. SERIAL_ECHOLNPGM("Steps per unit:");
  1284. }
  1285. CONFIG_ECHO_START;
  1286. SERIAL_ECHOPAIR(" M92 X", LINEAR_UNIT(planner.axis_steps_per_mm[X_AXIS]));
  1287. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.axis_steps_per_mm[Y_AXIS]));
  1288. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.axis_steps_per_mm[Z_AXIS]));
  1289. #if DISABLED(DISTINCT_E_FACTORS)
  1290. SERIAL_ECHOPAIR(" E", VOLUMETRIC_UNIT(planner.axis_steps_per_mm[E_AXIS]));
  1291. #endif
  1292. SERIAL_EOL();
  1293. #if ENABLED(DISTINCT_E_FACTORS)
  1294. CONFIG_ECHO_START;
  1295. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1296. SERIAL_ECHOPAIR(" M92 T", (int)i);
  1297. SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.axis_steps_per_mm[E_AXIS + i]));
  1298. }
  1299. #endif
  1300. if (!forReplay) {
  1301. CONFIG_ECHO_START;
  1302. SERIAL_ECHOLNPGM("Maximum feedrates (units/s):");
  1303. }
  1304. CONFIG_ECHO_START;
  1305. SERIAL_ECHOPAIR(" M203 X", LINEAR_UNIT(planner.max_feedrate_mm_s[X_AXIS]));
  1306. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.max_feedrate_mm_s[Y_AXIS]));
  1307. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.max_feedrate_mm_s[Z_AXIS]));
  1308. #if DISABLED(DISTINCT_E_FACTORS)
  1309. SERIAL_ECHOPAIR(" E", VOLUMETRIC_UNIT(planner.max_feedrate_mm_s[E_AXIS]));
  1310. #endif
  1311. SERIAL_EOL();
  1312. #if ENABLED(DISTINCT_E_FACTORS)
  1313. CONFIG_ECHO_START;
  1314. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1315. SERIAL_ECHOPAIR(" M203 T", (int)i);
  1316. SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.max_feedrate_mm_s[E_AXIS + i]));
  1317. }
  1318. #endif
  1319. if (!forReplay) {
  1320. CONFIG_ECHO_START;
  1321. SERIAL_ECHOLNPGM("Maximum Acceleration (units/s2):");
  1322. }
  1323. CONFIG_ECHO_START;
  1324. SERIAL_ECHOPAIR(" M201 X", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[X_AXIS]));
  1325. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[Y_AXIS]));
  1326. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[Z_AXIS]));
  1327. #if DISABLED(DISTINCT_E_FACTORS)
  1328. SERIAL_ECHOPAIR(" E", VOLUMETRIC_UNIT(planner.max_acceleration_mm_per_s2[E_AXIS]));
  1329. #endif
  1330. SERIAL_EOL();
  1331. #if ENABLED(DISTINCT_E_FACTORS)
  1332. CONFIG_ECHO_START;
  1333. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1334. SERIAL_ECHOPAIR(" M201 T", (int)i);
  1335. SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.max_acceleration_mm_per_s2[E_AXIS + i]));
  1336. }
  1337. #endif
  1338. if (!forReplay) {
  1339. CONFIG_ECHO_START;
  1340. SERIAL_ECHOLNPGM("Acceleration (units/s2): P<print_accel> R<retract_accel> T<travel_accel>");
  1341. }
  1342. CONFIG_ECHO_START;
  1343. SERIAL_ECHOPAIR(" M204 P", LINEAR_UNIT(planner.acceleration));
  1344. SERIAL_ECHOPAIR(" R", LINEAR_UNIT(planner.retract_acceleration));
  1345. SERIAL_ECHOLNPAIR(" T", LINEAR_UNIT(planner.travel_acceleration));
  1346. if (!forReplay) {
  1347. CONFIG_ECHO_START;
  1348. SERIAL_ECHOLNPGM("Advanced: S<min_feedrate> T<min_travel_feedrate> B<min_segment_time_ms> X<max_xy_jerk> Z<max_z_jerk> E<max_e_jerk>");
  1349. }
  1350. CONFIG_ECHO_START;
  1351. SERIAL_ECHOPAIR(" M205 S", LINEAR_UNIT(planner.min_feedrate_mm_s));
  1352. SERIAL_ECHOPAIR(" T", LINEAR_UNIT(planner.min_travel_feedrate_mm_s));
  1353. SERIAL_ECHOPAIR(" B", planner.min_segment_time);
  1354. SERIAL_ECHOPAIR(" X", LINEAR_UNIT(planner.max_jerk[X_AXIS]));
  1355. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.max_jerk[Y_AXIS]));
  1356. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.max_jerk[Z_AXIS]));
  1357. SERIAL_ECHOLNPAIR(" E", LINEAR_UNIT(planner.max_jerk[E_AXIS]));
  1358. #if HAS_M206_COMMAND
  1359. if (!forReplay) {
  1360. CONFIG_ECHO_START;
  1361. SERIAL_ECHOLNPGM("Home offset:");
  1362. }
  1363. CONFIG_ECHO_START;
  1364. SERIAL_ECHOPAIR(" M206 X", LINEAR_UNIT(home_offset[X_AXIS]));
  1365. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(home_offset[Y_AXIS]));
  1366. SERIAL_ECHOLNPAIR(" Z", LINEAR_UNIT(home_offset[Z_AXIS]));
  1367. #endif
  1368. #if HOTENDS > 1
  1369. if (!forReplay) {
  1370. CONFIG_ECHO_START;
  1371. SERIAL_ECHOLNPGM("Hotend offsets:");
  1372. }
  1373. CONFIG_ECHO_START;
  1374. for (uint8_t e = 1; e < HOTENDS; e++) {
  1375. SERIAL_ECHOPAIR(" M218 T", (int)e);
  1376. SERIAL_ECHOPAIR(" X", LINEAR_UNIT(hotend_offset[X_AXIS][e]));
  1377. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(hotend_offset[Y_AXIS][e]));
  1378. #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(SWITCHING_NOZZLE) ||ENABLED(PARKING_EXTRUDER)
  1379. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(hotend_offset[Z_AXIS][e]));
  1380. #endif
  1381. SERIAL_EOL();
  1382. }
  1383. #endif
  1384. #if ENABLED(MESH_BED_LEVELING)
  1385. if (!forReplay) {
  1386. CONFIG_ECHO_START;
  1387. SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
  1388. }
  1389. CONFIG_ECHO_START;
  1390. SERIAL_ECHOPAIR(" M420 S", leveling_is_valid() ? 1 : 0);
  1391. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1392. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
  1393. #endif
  1394. SERIAL_EOL();
  1395. for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
  1396. for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
  1397. CONFIG_ECHO_START;
  1398. SERIAL_ECHOPAIR(" G29 S3 X", (int)px + 1);
  1399. SERIAL_ECHOPAIR(" Y", (int)py + 1);
  1400. SERIAL_ECHOPGM(" Z");
  1401. SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
  1402. SERIAL_EOL();
  1403. }
  1404. }
  1405. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1406. if (!forReplay) {
  1407. CONFIG_ECHO_START;
  1408. ubl.echo_name();
  1409. SERIAL_ECHOLNPGM(":");
  1410. }
  1411. CONFIG_ECHO_START;
  1412. SERIAL_ECHOPAIR(" M420 S", leveling_is_active() ? 1 : 0);
  1413. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1414. SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
  1415. #endif
  1416. SERIAL_EOL();
  1417. if (!forReplay) {
  1418. SERIAL_EOL();
  1419. ubl.report_state();
  1420. SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.state.storage_slot);
  1421. SERIAL_ECHOPGM("z_offset: ");
  1422. SERIAL_ECHO_F(ubl.state.z_offset, 6);
  1423. SERIAL_EOL();
  1424. SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
  1425. SERIAL_ECHOLNPGM(" meshes.\n");
  1426. }
  1427. #elif HAS_ABL
  1428. if (!forReplay) {
  1429. CONFIG_ECHO_START;
  1430. SERIAL_ECHOLNPGM("Auto Bed Leveling:");
  1431. }
  1432. CONFIG_ECHO_START;
  1433. SERIAL_ECHOPAIR(" M420 S", leveling_is_active() ? 1 : 0);
  1434. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1435. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
  1436. #endif
  1437. SERIAL_EOL();
  1438. #endif
  1439. #if ENABLED(DELTA)
  1440. if (!forReplay) {
  1441. CONFIG_ECHO_START;
  1442. SERIAL_ECHOLNPGM("Endstop adjustment:");
  1443. }
  1444. CONFIG_ECHO_START;
  1445. SERIAL_ECHOPAIR(" M666 X", LINEAR_UNIT(endstop_adj[X_AXIS]));
  1446. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(endstop_adj[Y_AXIS]));
  1447. SERIAL_ECHOLNPAIR(" Z", LINEAR_UNIT(endstop_adj[Z_AXIS]));
  1448. if (!forReplay) {
  1449. CONFIG_ECHO_START;
  1450. SERIAL_ECHOLNPGM("Delta settings: L<diagonal_rod> R<radius> H<height> S<segments_per_s> B<calibration radius> XYZ<tower angle corrections>");
  1451. }
  1452. CONFIG_ECHO_START;
  1453. SERIAL_ECHOPAIR(" M665 L", LINEAR_UNIT(delta_diagonal_rod));
  1454. SERIAL_ECHOPAIR(" R", LINEAR_UNIT(delta_radius));
  1455. SERIAL_ECHOPAIR(" H", LINEAR_UNIT(DELTA_HEIGHT + home_offset[Z_AXIS]));
  1456. SERIAL_ECHOPAIR(" S", delta_segments_per_second);
  1457. SERIAL_ECHOPAIR(" B", LINEAR_UNIT(delta_calibration_radius));
  1458. SERIAL_ECHOPAIR(" X", LINEAR_UNIT(delta_tower_angle_trim[A_AXIS]));
  1459. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(delta_tower_angle_trim[B_AXIS]));
  1460. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(delta_tower_angle_trim[C_AXIS]));
  1461. SERIAL_EOL();
  1462. #elif ENABLED(Z_DUAL_ENDSTOPS)
  1463. if (!forReplay) {
  1464. CONFIG_ECHO_START;
  1465. SERIAL_ECHOLNPGM("Z2 Endstop adjustment:");
  1466. }
  1467. CONFIG_ECHO_START;
  1468. SERIAL_ECHOLNPAIR(" M666 Z", LINEAR_UNIT(z_endstop_adj));
  1469. #endif // DELTA
  1470. #if ENABLED(ULTIPANEL)
  1471. if (!forReplay) {
  1472. CONFIG_ECHO_START;
  1473. SERIAL_ECHOLNPGM("Material heatup parameters:");
  1474. }
  1475. CONFIG_ECHO_START;
  1476. for (uint8_t i = 0; i < COUNT(lcd_preheat_hotend_temp); i++) {
  1477. SERIAL_ECHOPAIR(" M145 S", (int)i);
  1478. SERIAL_ECHOPAIR(" H", TEMP_UNIT(lcd_preheat_hotend_temp[i]));
  1479. SERIAL_ECHOPAIR(" B", TEMP_UNIT(lcd_preheat_bed_temp[i]));
  1480. SERIAL_ECHOLNPAIR(" F", lcd_preheat_fan_speed[i]);
  1481. }
  1482. #endif // ULTIPANEL
  1483. #if HAS_PID_HEATING
  1484. if (!forReplay) {
  1485. CONFIG_ECHO_START;
  1486. SERIAL_ECHOLNPGM("PID settings:");
  1487. }
  1488. #if ENABLED(PIDTEMP)
  1489. #if HOTENDS > 1
  1490. if (forReplay) {
  1491. HOTEND_LOOP() {
  1492. CONFIG_ECHO_START;
  1493. SERIAL_ECHOPAIR(" M301 E", e);
  1494. SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, e));
  1495. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, e)));
  1496. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, e)));
  1497. #if ENABLED(PID_EXTRUSION_SCALING)
  1498. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, e));
  1499. if (e == 0) SERIAL_ECHOPAIR(" L", lpq_len);
  1500. #endif
  1501. SERIAL_EOL();
  1502. }
  1503. }
  1504. else
  1505. #endif // HOTENDS > 1
  1506. // !forReplay || HOTENDS == 1
  1507. {
  1508. CONFIG_ECHO_START;
  1509. SERIAL_ECHOPAIR(" M301 P", PID_PARAM(Kp, 0)); // for compatibility with hosts, only echo values for E0
  1510. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, 0)));
  1511. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
  1512. #if ENABLED(PID_EXTRUSION_SCALING)
  1513. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, 0));
  1514. SERIAL_ECHOPAIR(" L", lpq_len);
  1515. #endif
  1516. SERIAL_EOL();
  1517. }
  1518. #endif // PIDTEMP
  1519. #if ENABLED(PIDTEMPBED)
  1520. CONFIG_ECHO_START;
  1521. SERIAL_ECHOPAIR(" M304 P", thermalManager.bedKp);
  1522. SERIAL_ECHOPAIR(" I", unscalePID_i(thermalManager.bedKi));
  1523. SERIAL_ECHOPAIR(" D", unscalePID_d(thermalManager.bedKd));
  1524. SERIAL_EOL();
  1525. #endif
  1526. #endif // PIDTEMP || PIDTEMPBED
  1527. #if HAS_LCD_CONTRAST
  1528. if (!forReplay) {
  1529. CONFIG_ECHO_START;
  1530. SERIAL_ECHOLNPGM("LCD Contrast:");
  1531. }
  1532. CONFIG_ECHO_START;
  1533. SERIAL_ECHOLNPAIR(" M250 C", lcd_contrast);
  1534. #endif
  1535. #if ENABLED(FWRETRACT)
  1536. if (!forReplay) {
  1537. CONFIG_ECHO_START;
  1538. SERIAL_ECHOLNPGM("Retract: S<length> F<units/m> Z<lift>");
  1539. }
  1540. CONFIG_ECHO_START;
  1541. SERIAL_ECHOPAIR(" M207 S", LINEAR_UNIT(retract_length));
  1542. SERIAL_ECHOPAIR(" W", LINEAR_UNIT(swap_retract_length));
  1543. SERIAL_ECHOPAIR(" F", MMS_TO_MMM(LINEAR_UNIT(retract_feedrate_mm_s)));
  1544. SERIAL_ECHOLNPAIR(" Z", LINEAR_UNIT(retract_zlift));
  1545. if (!forReplay) {
  1546. CONFIG_ECHO_START;
  1547. SERIAL_ECHOLNPGM("Recover: S<length> F<units/m>");
  1548. }
  1549. CONFIG_ECHO_START;
  1550. SERIAL_ECHOPAIR(" M208 S", LINEAR_UNIT(retract_recover_length));
  1551. SERIAL_ECHOPAIR(" W", LINEAR_UNIT(swap_retract_recover_length));
  1552. SERIAL_ECHOLNPAIR(" F", MMS_TO_MMM(LINEAR_UNIT(retract_recover_feedrate_mm_s)));
  1553. if (!forReplay) {
  1554. CONFIG_ECHO_START;
  1555. SERIAL_ECHOLNPGM("Auto-Retract: S=0 to disable, 1 to interpret E-only moves as retract/recover");
  1556. }
  1557. CONFIG_ECHO_START;
  1558. SERIAL_ECHOLNPAIR(" M209 S", autoretract_enabled ? 1 : 0);
  1559. #endif // FWRETRACT
  1560. /**
  1561. * Auto Bed Leveling
  1562. */
  1563. #if HAS_BED_PROBE
  1564. if (!forReplay) {
  1565. CONFIG_ECHO_START;
  1566. SERIAL_ECHOLNPGM("Z-Probe Offset (mm):");
  1567. }
  1568. CONFIG_ECHO_START;
  1569. SERIAL_ECHOLNPAIR(" M851 Z", LINEAR_UNIT(zprobe_zoffset));
  1570. #endif
  1571. /**
  1572. * TMC2130 stepper driver current
  1573. */
  1574. #if ENABLED(HAVE_TMC2130)
  1575. if (!forReplay) {
  1576. CONFIG_ECHO_START;
  1577. SERIAL_ECHOLNPGM("Stepper driver current:");
  1578. }
  1579. CONFIG_ECHO_START;
  1580. SERIAL_ECHO(" M906");
  1581. #if ENABLED(X_IS_TMC2130)
  1582. SERIAL_ECHOPAIR(" X", stepperX.getCurrent());
  1583. #endif
  1584. #if ENABLED(Y_IS_TMC2130)
  1585. SERIAL_ECHOPAIR(" Y", stepperY.getCurrent());
  1586. #endif
  1587. #if ENABLED(Z_IS_TMC2130)
  1588. SERIAL_ECHOPAIR(" Z", stepperZ.getCurrent());
  1589. #endif
  1590. #if ENABLED(X2_IS_TMC2130)
  1591. SERIAL_ECHOPAIR(" X2", stepperX2.getCurrent());
  1592. #endif
  1593. #if ENABLED(Y2_IS_TMC2130)
  1594. SERIAL_ECHOPAIR(" Y2", stepperY2.getCurrent());
  1595. #endif
  1596. #if ENABLED(Z2_IS_TMC2130)
  1597. SERIAL_ECHOPAIR(" Z2", stepperZ2.getCurrent());
  1598. #endif
  1599. #if ENABLED(E0_IS_TMC2130)
  1600. SERIAL_ECHOPAIR(" E0", stepperE0.getCurrent());
  1601. #endif
  1602. #if ENABLED(E1_IS_TMC2130)
  1603. SERIAL_ECHOPAIR(" E1", stepperE1.getCurrent());
  1604. #endif
  1605. #if ENABLED(E2_IS_TMC2130)
  1606. SERIAL_ECHOPAIR(" E2", stepperE2.getCurrent());
  1607. #endif
  1608. #if ENABLED(E3_IS_TMC2130)
  1609. SERIAL_ECHOPAIR(" E3", stepperE3.getCurrent());
  1610. #endif
  1611. SERIAL_EOL();
  1612. #endif
  1613. /**
  1614. * Linear Advance
  1615. */
  1616. #if ENABLED(LIN_ADVANCE)
  1617. if (!forReplay) {
  1618. CONFIG_ECHO_START;
  1619. SERIAL_ECHOLNPGM("Linear Advance:");
  1620. }
  1621. CONFIG_ECHO_START;
  1622. SERIAL_ECHOPAIR(" M900 K", planner.extruder_advance_k);
  1623. SERIAL_ECHOLNPAIR(" R", planner.advance_ed_ratio);
  1624. #endif
  1625. #if HAS_MOTOR_CURRENT_PWM
  1626. CONFIG_ECHO_START;
  1627. if (!forReplay) {
  1628. SERIAL_ECHOLNPGM("Stepper motor currents:");
  1629. CONFIG_ECHO_START;
  1630. }
  1631. SERIAL_ECHOPAIR(" M907 X", stepper.motor_current_setting[0]);
  1632. SERIAL_ECHOPAIR(" Z", stepper.motor_current_setting[1]);
  1633. SERIAL_ECHOPAIR(" E", stepper.motor_current_setting[2]);
  1634. SERIAL_EOL();
  1635. #endif
  1636. }
  1637. #endif // !DISABLE_M503