My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

configuration_store.cpp 56KB

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