My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

configuration_store.cpp 58KB

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