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

configuration_store.cpp 58KB

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