My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

configuration_store.cpp 61KB

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