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

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