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 61KB

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