configuration_store.cpp 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825
  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. // Change EEPROM version if the structure changes
  38. #define EEPROM_VERSION "V56"
  39. #define EEPROM_OFFSET 100
  40. // Check the integrity of data offsets.
  41. // Can be disabled for production build.
  42. //#define DEBUG_EEPROM_READWRITE
  43. #include "configuration_store.h"
  44. #include "Marlin.h"
  45. #include "language.h"
  46. #include "endstops.h"
  47. #include "planner.h"
  48. #include "temperature.h"
  49. #include "ultralcd.h"
  50. #include "stepper.h"
  51. #include "parser.h"
  52. #include "vector_3.h"
  53. #if ENABLED(MESH_BED_LEVELING)
  54. #include "mesh_bed_leveling.h"
  55. #endif
  56. #if HAS_TRINAMIC
  57. #include "stepper_indirection.h"
  58. #include "tmc_util.h"
  59. #define TMC_GET_PWMTHRS(A,Q) _tmc_thrs(stepper##Q.microsteps(), stepper##Q.TPWMTHRS(), planner.axis_steps_per_mm[_AXIS(A)])
  60. #endif
  61. #if ENABLED(AUTO_BED_LEVELING_UBL)
  62. #include "ubl.h"
  63. #endif
  64. #if ENABLED(FWRETRACT)
  65. #include "fwretract.h"
  66. #endif
  67. #if ENABLED(PID_EXTRUSION_SCALING)
  68. #define LPQ_LEN thermalManager.lpq_len
  69. #endif
  70. #if ENABLED(BLTOUCH)
  71. extern bool bltouch_last_written_mode;
  72. #endif
  73. #pragma pack(push, 1) // No padding between variables
  74. typedef struct PID { float Kp, Ki, Kd; } PID;
  75. typedef struct PIDC { float Kp, Ki, Kd, Kc; } PIDC;
  76. /**
  77. * Current EEPROM Layout
  78. *
  79. * Keep this data structure up to date so
  80. * EEPROM size is known at compile time!
  81. */
  82. typedef struct SettingsDataStruct {
  83. char version[4]; // Vnn\0
  84. uint16_t crc; // Data Checksum
  85. //
  86. // DISTINCT_E_FACTORS
  87. //
  88. uint8_t esteppers; // NUM_AXIS_N - MOV_AXIS
  89. uint32_t planner_max_acceleration_mm_per_s2[NUM_AXIS_N], // M201 XYZE/ABCDE planner.max_acceleration_mm_per_s2[NUM_AXIS_N]
  90. planner_min_segment_time_us; // M205 Q planner.min_segment_time_us
  91. float planner_axis_steps_per_mm[NUM_AXIS_N], // M92 XYZE/ABCDE planner.axis_steps_per_mm[NUM_AXIS_N]
  92. planner_max_feedrate_mm_s[NUM_AXIS_N], // M203 XYZE/ABCDE planner.max_feedrate_mm_s[NUM_AXIS_N]
  93. planner_acceleration, // M204 P planner.acceleration
  94. planner_retract_acceleration, // M204 R planner.retract_acceleration
  95. planner_travel_acceleration, // M204 T planner.travel_acceleration
  96. planner_min_feedrate_mm_s, // M205 S planner.min_feedrate_mm_s
  97. planner_min_travel_feedrate_mm_s, // M205 T planner.min_travel_feedrate_mm_s
  98. planner_max_jerk[NUM_AXIS], // M205 XYZE/ABCDE planner.max_jerk[NUM_AXIS]
  99. planner_junction_deviation_mm; // M205 J planner.junction_deviation_mm
  100. float home_offset[XYZ]; // M206 XYZ
  101. #if HOTENDS > 1
  102. float hotend_offset[XYZ][HOTENDS - 1]; // M218 XYZ
  103. #endif
  104. //
  105. // ENABLE_LEVELING_FADE_HEIGHT
  106. //
  107. float planner_z_fade_height; // M420 Zn planner.z_fade_height
  108. //
  109. // MESH_BED_LEVELING
  110. //
  111. float mbl_z_offset; // mbl.z_offset
  112. uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
  113. #if ENABLED(MESH_BED_LEVELING)
  114. float mbl_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; // mbl.z_values
  115. #else
  116. float mbl_z_values[3][3];
  117. #endif
  118. //
  119. // HAS_BED_PROBE
  120. //
  121. float zprobe_zoffset; // M851 Z
  122. //
  123. // ABL_PLANAR
  124. //
  125. matrix_3x3 planner_bed_level_matrix; // planner.bed_level_matrix
  126. //
  127. // AUTO_BED_LEVELING_BILINEAR
  128. //
  129. uint8_t grid_max_x, grid_max_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
  130. int bilinear_grid_spacing[2],
  131. bilinear_start[2]; // G29 L F
  132. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  133. float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; // G29
  134. #else
  135. float z_values[3][3];
  136. #endif
  137. //
  138. // AUTO_BED_LEVELING_UBL
  139. //
  140. bool planner_leveling_active; // M420 S planner.leveling_active
  141. int8_t ubl_storage_slot; // ubl.storage_slot
  142. //
  143. // BLTOUCH
  144. //
  145. bool bltouch_last_written_mode;
  146. //
  147. // DELTA / [XYZ]_DUAL_ENDSTOPS
  148. //
  149. #if ENABLED(DELTA)
  150. float delta_height, // M666 H
  151. delta_endstop_adj[ABC], // M666 XYZ
  152. delta_radius, // M665 R
  153. delta_diagonal_rod, // M665 L
  154. delta_segments_per_second, // M665 S
  155. delta_calibration_radius, // M665 B
  156. delta_tower_angle_trim[ABC]; // M665 XYZ
  157. #elif ENABLED(HANGPRINTER)
  158. float anchor_A_y, // M665 W
  159. anchor_A_z, // M665 E
  160. anchor_B_x, // M665 R
  161. anchor_B_y, // M665 T
  162. anchor_B_z, // M665 Y
  163. anchor_C_x, // M665 U
  164. anchor_C_y, // M665 I
  165. anchor_C_z, // M665 O
  166. anchor_D_z, // M665 P
  167. delta_segments_per_second, // M665 S
  168. hangprinter_calibration_radius_placeholder;
  169. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  170. float x_endstop_adj, // M666 X
  171. y_endstop_adj, // M666 Y
  172. z_endstop_adj; // M666 Z
  173. #endif
  174. //
  175. // ULTIPANEL
  176. //
  177. int16_t lcd_preheat_hotend_temp[2], // M145 S0 H
  178. lcd_preheat_bed_temp[2], // M145 S0 B
  179. lcd_preheat_fan_speed[2]; // M145 S0 F
  180. //
  181. // PIDTEMP
  182. //
  183. PIDC hotendPID[MAX_EXTRUDERS]; // M301 En PIDC / M303 En U
  184. int16_t lpq_len; // M301 L
  185. //
  186. // PIDTEMPBED
  187. //
  188. PID bedPID; // M304 PID / M303 E-1 U
  189. //
  190. // HAS_LCD_CONTRAST
  191. //
  192. int16_t lcd_contrast; // M250 C
  193. //
  194. // FWRETRACT
  195. //
  196. bool autoretract_enabled; // M209 S
  197. float retract_length, // M207 S
  198. retract_feedrate_mm_s, // M207 F
  199. retract_zlift, // M207 Z
  200. retract_recover_length, // M208 S
  201. retract_recover_feedrate_mm_s, // M208 F
  202. swap_retract_length, // M207 W
  203. swap_retract_recover_length, // M208 W
  204. swap_retract_recover_feedrate_mm_s; // M208 R
  205. //
  206. // !NO_VOLUMETRIC
  207. //
  208. bool parser_volumetric_enabled; // M200 D parser.volumetric_enabled
  209. float planner_filament_size[MAX_EXTRUDERS]; // M200 T D planner.filament_size[]
  210. //
  211. // HAS_TRINAMIC
  212. //
  213. #define TMC_AXES (MAX_EXTRUDERS + 6)
  214. uint16_t tmc_stepper_current[TMC_AXES]; // M906 X Y Z X2 Y2 Z2 E0 E1 E2 E3 E4
  215. uint32_t tmc_hybrid_threshold[TMC_AXES]; // M913 X Y Z X2 Y2 Z2 E0 E1 E2 E3 E4
  216. int16_t tmc_sgt[XYZ]; // M914 X Y Z
  217. //
  218. // LIN_ADVANCE
  219. //
  220. float planner_extruder_advance_K; // M900 K planner.extruder_advance_K
  221. //
  222. // HAS_MOTOR_CURRENT_PWM
  223. //
  224. uint32_t motor_current_setting[XYZ]; // M907 X Z E
  225. //
  226. // CNC_COORDINATE_SYSTEMS
  227. //
  228. float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ]; // G54-G59.3
  229. //
  230. // SKEW_CORRECTION
  231. //
  232. float planner_xy_skew_factor, // M852 I planner.xy_skew_factor
  233. planner_xz_skew_factor, // M852 J planner.xz_skew_factor
  234. planner_yz_skew_factor; // M852 K planner.yz_skew_factor
  235. //
  236. // ADVANCED_PAUSE_FEATURE
  237. //
  238. float filament_change_unload_length[MAX_EXTRUDERS], // M603 T U
  239. filament_change_load_length[MAX_EXTRUDERS]; // M603 T L
  240. } SettingsData;
  241. #pragma pack(pop)
  242. MarlinSettings settings;
  243. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  244. extern void refresh_bed_level();
  245. #endif
  246. uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); }
  247. /**
  248. * Post-process after Retrieve or Reset
  249. */
  250. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  251. float new_z_fade_height;
  252. #endif
  253. void MarlinSettings::postprocess() {
  254. const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
  255. // steps per s2 needs to be updated to agree with units per s2
  256. planner.reset_acceleration_rates();
  257. // Make sure delta kinematics are updated before refreshing the
  258. // planner position so the stepper counts will be set correctly.
  259. #if ENABLED(DELTA)
  260. recalc_delta_settings();
  261. #elif ENABLED(HANGPRINTER)
  262. recalc_hangprinter_settings();
  263. #endif
  264. #if ENABLED(PIDTEMP)
  265. thermalManager.update_pid();
  266. #endif
  267. #if DISABLED(NO_VOLUMETRICS)
  268. planner.calculate_volumetric_multipliers();
  269. #else
  270. for (uint8_t i = COUNT(planner.e_factor); i--;)
  271. planner.refresh_e_factor(i);
  272. #endif
  273. #if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
  274. // Software endstops depend on home_offset
  275. LOOP_XYZ(i) update_software_endstops((AxisEnum)i);
  276. #endif
  277. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  278. set_z_fade_height(new_z_fade_height, false); // false = no report
  279. #endif
  280. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  281. refresh_bed_level();
  282. #endif
  283. #if HAS_MOTOR_CURRENT_PWM
  284. stepper.refresh_motor_power();
  285. #endif
  286. #if ENABLED(FWRETRACT)
  287. fwretract.refresh_autoretract();
  288. #endif
  289. #if ENABLED(JUNCTION_DEVIATION) && ENABLED(LIN_ADVANCE)
  290. planner.recalculate_max_e_jerk();
  291. #endif
  292. // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
  293. // and init stepper.count[], planner.position[] with current_position
  294. planner.refresh_positioning();
  295. // Various factors can change the current position
  296. if (memcmp(oldpos, current_position, sizeof(oldpos)))
  297. report_current_position();
  298. }
  299. #if ENABLED(EEPROM_SETTINGS)
  300. #define EEPROM_START() int eeprom_index = EEPROM_OFFSET
  301. #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
  302. #define EEPROM_WRITE(VAR) write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
  303. #define EEPROM_READ(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
  304. #define EEPROM_READ_ALWAYS(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, true)
  305. #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_error = true; }while(0)
  306. #if ENABLED(DEBUG_EEPROM_READWRITE)
  307. #define _FIELD_TEST(FIELD) \
  308. EEPROM_ASSERT( \
  309. eeprom_error || eeprom_index == offsetof(SettingsData, FIELD) + EEPROM_OFFSET, \
  310. "Field " STRINGIFY(FIELD) " mismatch." \
  311. )
  312. #else
  313. #define _FIELD_TEST(FIELD) NOOP
  314. #endif
  315. const char version[4] = EEPROM_VERSION;
  316. bool MarlinSettings::eeprom_error, MarlinSettings::validating;
  317. void MarlinSettings::write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
  318. if (eeprom_error) { pos += size; return; }
  319. while (size--) {
  320. uint8_t * const p = (uint8_t * const)pos;
  321. uint8_t v = *value;
  322. // EEPROM has only ~100,000 write cycles,
  323. // so only write bytes that have changed!
  324. if (v != eeprom_read_byte(p)) {
  325. eeprom_write_byte(p, v);
  326. if (eeprom_read_byte(p) != v) {
  327. SERIAL_ECHO_START();
  328. SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
  329. eeprom_error = true;
  330. return;
  331. }
  332. }
  333. crc16(crc, &v, 1);
  334. pos++;
  335. value++;
  336. };
  337. }
  338. void MarlinSettings::read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool force/*=false*/) {
  339. if (eeprom_error) { pos += size; return; }
  340. do {
  341. uint8_t c = eeprom_read_byte((unsigned char*)pos);
  342. if (!validating || force) *value = c;
  343. crc16(crc, &c, 1);
  344. pos++;
  345. value++;
  346. } while (--size);
  347. }
  348. bool MarlinSettings::size_error(const uint16_t size) {
  349. if (size != datasize()) {
  350. SERIAL_ERROR_START();
  351. SERIAL_ERRORLNPGM("EEPROM datasize error.");
  352. return true;
  353. }
  354. return false;
  355. }
  356. /**
  357. * M500 - Store Configuration
  358. */
  359. bool MarlinSettings::save() {
  360. float dummy = 0;
  361. char ver[4] = "ERR";
  362. uint16_t working_crc = 0;
  363. EEPROM_START();
  364. eeprom_error = false;
  365. EEPROM_WRITE(ver); // invalidate data first
  366. EEPROM_SKIP(working_crc); // Skip the checksum slot
  367. working_crc = 0; // clear before first "real data"
  368. _FIELD_TEST(esteppers);
  369. const uint8_t esteppers = NUM_AXIS_N - MOV_AXIS;
  370. EEPROM_WRITE(esteppers);
  371. EEPROM_WRITE(planner.max_acceleration_mm_per_s2);
  372. EEPROM_WRITE(planner.min_segment_time_us);
  373. EEPROM_WRITE(planner.axis_steps_per_mm);
  374. EEPROM_WRITE(planner.max_feedrate_mm_s);
  375. EEPROM_WRITE(planner.acceleration);
  376. EEPROM_WRITE(planner.retract_acceleration);
  377. EEPROM_WRITE(planner.travel_acceleration);
  378. EEPROM_WRITE(planner.min_feedrate_mm_s);
  379. EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
  380. #if ENABLED(JUNCTION_DEVIATION)
  381. const float planner_max_jerk[] = {
  382. #if ENABLED(HANGPRINTER)
  383. float(DEFAULT_AJERK), float(DEFAULT_BJERK), float(DEFAULT_CJERK), float(DEFAULT_DJERK), float(DEFAULT_EJERK)
  384. #else
  385. float(DEFAULT_XJERK), float(DEFAULT_YJERK), float(DEFAULT_ZJERK), float(DEFAULT_EJERK)
  386. #endif
  387. };
  388. EEPROM_WRITE(planner_max_jerk);
  389. EEPROM_WRITE(planner.junction_deviation_mm);
  390. #else
  391. EEPROM_WRITE(planner.max_jerk);
  392. dummy = 0.02f;
  393. EEPROM_WRITE(dummy);
  394. #endif
  395. _FIELD_TEST(home_offset);
  396. #if !HAS_HOME_OFFSET
  397. const float home_offset[XYZ] = { 0 };
  398. #endif
  399. EEPROM_WRITE(home_offset);
  400. #if HOTENDS > 1
  401. // Skip hotend 0 which must be 0
  402. for (uint8_t e = 1; e < HOTENDS; e++)
  403. LOOP_XYZ(i) EEPROM_WRITE(hotend_offset[i][e]);
  404. #endif
  405. //
  406. // Global Leveling
  407. //
  408. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  409. const float zfh = planner.z_fade_height;
  410. #else
  411. const float zfh = 10.0;
  412. #endif
  413. EEPROM_WRITE(zfh);
  414. //
  415. // Mesh Bed Leveling
  416. //
  417. #if ENABLED(MESH_BED_LEVELING)
  418. // Compile time test that sizeof(mbl.z_values) is as expected
  419. static_assert(
  420. sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
  421. "MBL Z array is the wrong size."
  422. );
  423. const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
  424. EEPROM_WRITE(mbl.z_offset);
  425. EEPROM_WRITE(mesh_num_x);
  426. EEPROM_WRITE(mesh_num_y);
  427. EEPROM_WRITE(mbl.z_values);
  428. #else // For disabled MBL write a default mesh
  429. dummy = 0;
  430. const uint8_t mesh_num_x = 3, mesh_num_y = 3;
  431. EEPROM_WRITE(dummy); // z_offset
  432. EEPROM_WRITE(mesh_num_x);
  433. EEPROM_WRITE(mesh_num_y);
  434. for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummy);
  435. #endif // MESH_BED_LEVELING
  436. _FIELD_TEST(zprobe_zoffset);
  437. #if !HAS_BED_PROBE
  438. const float zprobe_zoffset = 0;
  439. #endif
  440. EEPROM_WRITE(zprobe_zoffset);
  441. //
  442. // Planar Bed Leveling matrix
  443. //
  444. #if ABL_PLANAR
  445. EEPROM_WRITE(planner.bed_level_matrix);
  446. #else
  447. dummy = 0;
  448. for (uint8_t q = 9; q--;) EEPROM_WRITE(dummy);
  449. #endif
  450. //
  451. // Bilinear Auto Bed Leveling
  452. //
  453. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  454. // Compile time test that sizeof(z_values) is as expected
  455. static_assert(
  456. sizeof(z_values) == GRID_MAX_POINTS * sizeof(z_values[0][0]),
  457. "Bilinear Z array is the wrong size."
  458. );
  459. const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y;
  460. EEPROM_WRITE(grid_max_x); // 1 byte
  461. EEPROM_WRITE(grid_max_y); // 1 byte
  462. EEPROM_WRITE(bilinear_grid_spacing); // 2 ints
  463. EEPROM_WRITE(bilinear_start); // 2 ints
  464. EEPROM_WRITE(z_values); // 9-256 floats
  465. #else
  466. // For disabled Bilinear Grid write an empty 3x3 grid
  467. const uint8_t grid_max_x = 3, grid_max_y = 3;
  468. const int bilinear_start[2] = { 0 }, bilinear_grid_spacing[2] = { 0 };
  469. dummy = 0;
  470. EEPROM_WRITE(grid_max_x);
  471. EEPROM_WRITE(grid_max_y);
  472. EEPROM_WRITE(bilinear_grid_spacing);
  473. EEPROM_WRITE(bilinear_start);
  474. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
  475. #endif // AUTO_BED_LEVELING_BILINEAR
  476. _FIELD_TEST(planner_leveling_active);
  477. #if ENABLED(AUTO_BED_LEVELING_UBL)
  478. EEPROM_WRITE(planner.leveling_active);
  479. EEPROM_WRITE(ubl.storage_slot);
  480. #else
  481. const bool ubl_active = false;
  482. const int8_t storage_slot = -1;
  483. EEPROM_WRITE(ubl_active);
  484. EEPROM_WRITE(storage_slot);
  485. #endif // AUTO_BED_LEVELING_UBL
  486. //
  487. // BLTOUCH
  488. //
  489. {
  490. _FIELD_TEST(bltouch_last_written_mode);
  491. #if ENABLED(BLTOUCH)
  492. const bool &eeprom_bltouch_last_written_mode = bltouch_last_written_mode;
  493. #else
  494. constexpr bool eeprom_bltouch_last_written_mode = false;
  495. #endif
  496. EEPROM_WRITE(eeprom_bltouch_last_written_mode);
  497. }
  498. // 11 floats for DELTA / [XYZ]_DUAL_ENDSTOPS
  499. #if ENABLED(DELTA)
  500. _FIELD_TEST(delta_height);
  501. EEPROM_WRITE(delta_height); // 1 float
  502. EEPROM_WRITE(delta_endstop_adj); // 3 floats
  503. EEPROM_WRITE(delta_radius); // 1 float
  504. EEPROM_WRITE(delta_diagonal_rod); // 1 float
  505. EEPROM_WRITE(delta_segments_per_second); // 1 float
  506. EEPROM_WRITE(delta_calibration_radius); // 1 float
  507. EEPROM_WRITE(delta_tower_angle_trim); // 3 floats
  508. #elif ENABLED(HANGPRINTER)
  509. dummy = 0.0f;
  510. _FIELD_TEST(anchor_A_y);
  511. EEPROM_WRITE(anchor_A_y); // 1 float
  512. EEPROM_WRITE(anchor_A_z); // 1 float
  513. EEPROM_WRITE(anchor_B_x); // 1 float
  514. EEPROM_WRITE(anchor_B_y); // 1 float
  515. EEPROM_WRITE(anchor_B_z); // 1 float
  516. EEPROM_WRITE(anchor_C_x); // 1 float
  517. EEPROM_WRITE(anchor_C_y); // 1 float
  518. EEPROM_WRITE(anchor_C_z); // 1 float
  519. EEPROM_WRITE(anchor_D_z); // 1 float
  520. EEPROM_WRITE(delta_segments_per_second); // 1 float
  521. EEPROM_WRITE(dummy); // 1 float
  522. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  523. _FIELD_TEST(x_endstop_adj);
  524. // Write dual endstops in X, Y, Z order. Unused = 0.0
  525. dummy = 0;
  526. #if ENABLED(X_DUAL_ENDSTOPS)
  527. EEPROM_WRITE(endstops.x_endstop_adj); // 1 float
  528. #else
  529. EEPROM_WRITE(dummy);
  530. #endif
  531. #if ENABLED(Y_DUAL_ENDSTOPS)
  532. EEPROM_WRITE(endstops.y_endstop_adj); // 1 float
  533. #else
  534. EEPROM_WRITE(dummy);
  535. #endif
  536. #if ENABLED(Z_DUAL_ENDSTOPS)
  537. EEPROM_WRITE(endstops.z_endstop_adj); // 1 float
  538. #else
  539. EEPROM_WRITE(dummy);
  540. #endif
  541. #endif
  542. _FIELD_TEST(lcd_preheat_hotend_temp);
  543. #if DISABLED(ULTIPANEL)
  544. constexpr int16_t lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
  545. lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
  546. lcd_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED };
  547. #endif
  548. EEPROM_WRITE(lcd_preheat_hotend_temp);
  549. EEPROM_WRITE(lcd_preheat_bed_temp);
  550. EEPROM_WRITE(lcd_preheat_fan_speed);
  551. for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
  552. #if ENABLED(PIDTEMP)
  553. if (e < HOTENDS) {
  554. EEPROM_WRITE(PID_PARAM(Kp, e));
  555. EEPROM_WRITE(PID_PARAM(Ki, e));
  556. EEPROM_WRITE(PID_PARAM(Kd, e));
  557. #if ENABLED(PID_EXTRUSION_SCALING)
  558. EEPROM_WRITE(PID_PARAM(Kc, e));
  559. #else
  560. dummy = 1.0f; // 1.0 = default kc
  561. EEPROM_WRITE(dummy);
  562. #endif
  563. }
  564. else
  565. #endif // !PIDTEMP
  566. {
  567. dummy = NAN; // When read, will not change the existing value
  568. EEPROM_WRITE(dummy); // Kp
  569. dummy = 0;
  570. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy); // Ki, Kd, Kc
  571. }
  572. } // Hotends Loop
  573. _FIELD_TEST(lpq_len);
  574. #if DISABLED(PID_EXTRUSION_SCALING)
  575. const int16_t LPQ_LEN = 20;
  576. #endif
  577. EEPROM_WRITE(LPQ_LEN);
  578. #if DISABLED(PIDTEMPBED)
  579. dummy = NAN;
  580. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
  581. #else
  582. EEPROM_WRITE(thermalManager.bedKp);
  583. EEPROM_WRITE(thermalManager.bedKi);
  584. EEPROM_WRITE(thermalManager.bedKd);
  585. #endif
  586. _FIELD_TEST(lcd_contrast);
  587. #if !HAS_LCD_CONTRAST
  588. const int16_t lcd_contrast = 32;
  589. #endif
  590. EEPROM_WRITE(lcd_contrast);
  591. #if DISABLED(FWRETRACT)
  592. const bool autoretract_enabled = false;
  593. const float autoretract_defaults[] = { 3, 45, 0, 0, 0, 13, 0, 8 };
  594. EEPROM_WRITE(autoretract_enabled);
  595. EEPROM_WRITE(autoretract_defaults);
  596. #else
  597. EEPROM_WRITE(fwretract.autoretract_enabled);
  598. EEPROM_WRITE(fwretract.retract_length);
  599. EEPROM_WRITE(fwretract.retract_feedrate_mm_s);
  600. EEPROM_WRITE(fwretract.retract_zlift);
  601. EEPROM_WRITE(fwretract.retract_recover_length);
  602. EEPROM_WRITE(fwretract.retract_recover_feedrate_mm_s);
  603. EEPROM_WRITE(fwretract.swap_retract_length);
  604. EEPROM_WRITE(fwretract.swap_retract_recover_length);
  605. EEPROM_WRITE(fwretract.swap_retract_recover_feedrate_mm_s);
  606. #endif
  607. //
  608. // Volumetric & Filament Size
  609. //
  610. _FIELD_TEST(parser_volumetric_enabled);
  611. #if DISABLED(NO_VOLUMETRICS)
  612. EEPROM_WRITE(parser.volumetric_enabled);
  613. // Save filament sizes
  614. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  615. if (q < COUNT(planner.filament_size)) dummy = planner.filament_size[q];
  616. EEPROM_WRITE(dummy);
  617. }
  618. #else
  619. const bool volumetric_enabled = false;
  620. dummy = DEFAULT_NOMINAL_FILAMENT_DIA;
  621. EEPROM_WRITE(volumetric_enabled);
  622. for (uint8_t q = MAX_EXTRUDERS; q--;) EEPROM_WRITE(dummy);
  623. #endif
  624. //
  625. // Save TMC2130 or TMC2208 Configuration, and placeholder values
  626. //
  627. _FIELD_TEST(tmc_stepper_current);
  628. uint16_t tmc_stepper_current[TMC_AXES] = {
  629. #if HAS_TRINAMIC
  630. #if AXIS_IS_TMC(X)
  631. stepperX.getCurrent(),
  632. #else
  633. 0,
  634. #endif
  635. #if AXIS_IS_TMC(Y)
  636. stepperY.getCurrent(),
  637. #else
  638. 0,
  639. #endif
  640. #if AXIS_IS_TMC(Z)
  641. stepperZ.getCurrent(),
  642. #else
  643. 0,
  644. #endif
  645. #if AXIS_IS_TMC(X2)
  646. stepperX2.getCurrent(),
  647. #else
  648. 0,
  649. #endif
  650. #if AXIS_IS_TMC(Y2)
  651. stepperY2.getCurrent(),
  652. #else
  653. 0,
  654. #endif
  655. #if AXIS_IS_TMC(Z2)
  656. stepperZ2.getCurrent(),
  657. #else
  658. 0,
  659. #endif
  660. #if AXIS_IS_TMC(E0)
  661. stepperE0.getCurrent(),
  662. #else
  663. 0,
  664. #endif
  665. #if AXIS_IS_TMC(E1)
  666. stepperE1.getCurrent(),
  667. #else
  668. 0,
  669. #endif
  670. #if AXIS_IS_TMC(E2)
  671. stepperE2.getCurrent(),
  672. #else
  673. 0,
  674. #endif
  675. #if AXIS_IS_TMC(E3)
  676. stepperE3.getCurrent(),
  677. #else
  678. 0,
  679. #endif
  680. #if AXIS_IS_TMC(E4)
  681. stepperE4.getCurrent()
  682. #else
  683. 0
  684. #endif
  685. #else
  686. 0
  687. #endif
  688. };
  689. EEPROM_WRITE(tmc_stepper_current);
  690. //
  691. // Save TMC2130 or TMC2208 Hybrid Threshold, and placeholder values
  692. //
  693. _FIELD_TEST(tmc_hybrid_threshold);
  694. uint32_t tmc_hybrid_threshold[TMC_AXES] = {
  695. #if ENABLED(HYBRID_THRESHOLD)
  696. #if AXIS_HAS_STEALTHCHOP(X)
  697. TMC_GET_PWMTHRS(X, X),
  698. #else
  699. X_HYBRID_THRESHOLD,
  700. #endif
  701. #if AXIS_HAS_STEALTHCHOP(Y)
  702. TMC_GET_PWMTHRS(Y, Y),
  703. #else
  704. Y_HYBRID_THRESHOLD,
  705. #endif
  706. #if AXIS_HAS_STEALTHCHOP(Z)
  707. TMC_GET_PWMTHRS(Z, Z),
  708. #else
  709. Z_HYBRID_THRESHOLD,
  710. #endif
  711. #if AXIS_HAS_STEALTHCHOP(X2)
  712. TMC_GET_PWMTHRS(X, X2),
  713. #else
  714. X2_HYBRID_THRESHOLD,
  715. #endif
  716. #if AXIS_HAS_STEALTHCHOP(Y2)
  717. TMC_GET_PWMTHRS(Y, Y2),
  718. #else
  719. Y2_HYBRID_THRESHOLD,
  720. #endif
  721. #if AXIS_HAS_STEALTHCHOP(Z2)
  722. TMC_GET_PWMTHRS(Z, Z2),
  723. #else
  724. Z2_HYBRID_THRESHOLD,
  725. #endif
  726. #if AXIS_HAS_STEALTHCHOP(E0)
  727. TMC_GET_PWMTHRS(E, E0),
  728. #else
  729. E0_HYBRID_THRESHOLD,
  730. #endif
  731. #if AXIS_HAS_STEALTHCHOP(E1)
  732. TMC_GET_PWMTHRS(E, E1),
  733. #else
  734. E1_HYBRID_THRESHOLD,
  735. #endif
  736. #if AXIS_HAS_STEALTHCHOP(E2)
  737. TMC_GET_PWMTHRS(E, E2),
  738. #else
  739. E2_HYBRID_THRESHOLD,
  740. #endif
  741. #if AXIS_HAS_STEALTHCHOP(E3)
  742. TMC_GET_PWMTHRS(E, E3),
  743. #else
  744. E3_HYBRID_THRESHOLD,
  745. #endif
  746. #if AXIS_HAS_STEALTHCHOP(E4)
  747. TMC_GET_PWMTHRS(E, E4)
  748. #else
  749. E4_HYBRID_THRESHOLD
  750. #endif
  751. #else
  752. 100, 100, 3, // X, Y, Z
  753. 100, 100, 3, // X2, Y2, Z2
  754. 30, 30, 30, 30, 30 // E0, E1, E2, E3, E4
  755. #endif
  756. };
  757. EEPROM_WRITE(tmc_hybrid_threshold);
  758. //
  759. // TMC2130 Sensorless homing threshold
  760. //
  761. int16_t tmc_sgt[XYZ] = {
  762. #if ENABLED(SENSORLESS_HOMING)
  763. #if X_SENSORLESS
  764. stepperX.sgt(),
  765. #else
  766. 0,
  767. #endif
  768. #if Y_SENSORLESS
  769. stepperY.sgt(),
  770. #else
  771. 0,
  772. #endif
  773. #if Z_SENSORLESS
  774. stepperZ.sgt()
  775. #else
  776. 0
  777. #endif
  778. #else
  779. 0
  780. #endif
  781. };
  782. EEPROM_WRITE(tmc_sgt);
  783. //
  784. // Linear Advance
  785. //
  786. _FIELD_TEST(planner_extruder_advance_K);
  787. #if ENABLED(LIN_ADVANCE)
  788. EEPROM_WRITE(planner.extruder_advance_K);
  789. #else
  790. dummy = 0;
  791. EEPROM_WRITE(dummy);
  792. #endif
  793. _FIELD_TEST(motor_current_setting);
  794. #if HAS_MOTOR_CURRENT_PWM
  795. for (uint8_t q = XYZ; q--;) EEPROM_WRITE(stepper.motor_current_setting[q]);
  796. #else
  797. const uint32_t dummyui32[XYZ] = { 0 };
  798. EEPROM_WRITE(dummyui32);
  799. #endif
  800. //
  801. // CNC Coordinate Systems
  802. //
  803. _FIELD_TEST(coordinate_system);
  804. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  805. EEPROM_WRITE(coordinate_system); // 27 floats
  806. #else
  807. dummy = 0;
  808. for (uint8_t q = MAX_COORDINATE_SYSTEMS * XYZ; q--;) EEPROM_WRITE(dummy);
  809. #endif
  810. //
  811. // Skew correction factors
  812. //
  813. _FIELD_TEST(planner_xy_skew_factor);
  814. #if ENABLED(SKEW_CORRECTION)
  815. EEPROM_WRITE(planner.xy_skew_factor);
  816. EEPROM_WRITE(planner.xz_skew_factor);
  817. EEPROM_WRITE(planner.yz_skew_factor);
  818. #else
  819. dummy = 0;
  820. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
  821. #endif
  822. //
  823. // Advanced Pause filament load & unload lengths
  824. //
  825. _FIELD_TEST(filament_change_unload_length);
  826. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  827. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  828. if (q < COUNT(filament_change_unload_length)) dummy = filament_change_unload_length[q];
  829. EEPROM_WRITE(dummy);
  830. }
  831. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  832. if (q < COUNT(filament_change_load_length)) dummy = filament_change_load_length[q];
  833. EEPROM_WRITE(dummy);
  834. }
  835. #else
  836. dummy = 0;
  837. for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_WRITE(dummy);
  838. #endif
  839. //
  840. // Validate CRC and Data Size
  841. //
  842. if (!eeprom_error) {
  843. const uint16_t eeprom_size = eeprom_index - (EEPROM_OFFSET),
  844. final_crc = working_crc;
  845. // Write the EEPROM header
  846. eeprom_index = EEPROM_OFFSET;
  847. EEPROM_WRITE(version);
  848. EEPROM_WRITE(final_crc);
  849. // Report storage size
  850. #if ENABLED(EEPROM_CHITCHAT)
  851. SERIAL_ECHO_START();
  852. SERIAL_ECHOPAIR("Settings Stored (", eeprom_size);
  853. SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)final_crc);
  854. SERIAL_ECHOLNPGM(")");
  855. #endif
  856. eeprom_error |= size_error(eeprom_size);
  857. }
  858. //
  859. // UBL Mesh
  860. //
  861. #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
  862. if (ubl.storage_slot >= 0)
  863. store_mesh(ubl.storage_slot);
  864. #endif
  865. return !eeprom_error;
  866. }
  867. /**
  868. * M501 - Retrieve Configuration
  869. */
  870. bool MarlinSettings::_load() {
  871. uint16_t working_crc = 0;
  872. EEPROM_START();
  873. char stored_ver[4];
  874. EEPROM_READ_ALWAYS(stored_ver);
  875. uint16_t stored_crc;
  876. EEPROM_READ_ALWAYS(stored_crc);
  877. // Version has to match or defaults are used
  878. if (strncmp(version, stored_ver, 3) != 0) {
  879. if (stored_ver[3] != '\0') {
  880. stored_ver[0] = '?';
  881. stored_ver[1] = '\0';
  882. }
  883. #if ENABLED(EEPROM_CHITCHAT)
  884. SERIAL_ECHO_START();
  885. SERIAL_ECHOPGM("EEPROM version mismatch ");
  886. SERIAL_ECHOPAIR("(EEPROM=", stored_ver);
  887. SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")");
  888. #endif
  889. eeprom_error = true;
  890. }
  891. else {
  892. float dummy = 0;
  893. #if DISABLED(AUTO_BED_LEVELING_UBL) || DISABLED(FWRETRACT) || ENABLED(NO_VOLUMETRICS)
  894. bool dummyb;
  895. #endif
  896. working_crc = 0; // Init to 0. Accumulated by EEPROM_READ
  897. _FIELD_TEST(esteppers);
  898. // Number of esteppers may change
  899. uint8_t esteppers;
  900. EEPROM_READ_ALWAYS(esteppers);
  901. //
  902. // Planner Motion
  903. //
  904. // Get only the number of E stepper parameters previously stored
  905. // Any steppers added later are set to their defaults
  906. const uint32_t def1[] = DEFAULT_MAX_ACCELERATION;
  907. const float def2[] = DEFAULT_AXIS_STEPS_PER_UNIT, def3[] = DEFAULT_MAX_FEEDRATE;
  908. uint32_t tmp1[MOV_AXIS + esteppers];
  909. EEPROM_READ(tmp1); // max_acceleration_mm_per_s2
  910. EEPROM_READ(planner.min_segment_time_us);
  911. float tmp2[MOV_AXIS + esteppers], tmp3[MOV_AXIS + esteppers];
  912. EEPROM_READ(tmp2); // axis_steps_per_mm
  913. EEPROM_READ(tmp3); // max_feedrate_mm_s
  914. if (!validating) LOOP_NUM_AXIS_N(i) {
  915. planner.max_acceleration_mm_per_s2[i] = i < MOV_AXIS + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
  916. planner.axis_steps_per_mm[i] = i < MOV_AXIS + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
  917. planner.max_feedrate_mm_s[i] = i < MOV_AXIS + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
  918. }
  919. EEPROM_READ(planner.acceleration);
  920. EEPROM_READ(planner.retract_acceleration);
  921. EEPROM_READ(planner.travel_acceleration);
  922. EEPROM_READ(planner.min_feedrate_mm_s);
  923. EEPROM_READ(planner.min_travel_feedrate_mm_s);
  924. #if ENABLED(JUNCTION_DEVIATION)
  925. for (uint8_t q = 4; q--;) EEPROM_READ(dummy);
  926. EEPROM_READ(planner.junction_deviation_mm);
  927. #else
  928. EEPROM_READ(planner.max_jerk);
  929. EEPROM_READ(dummy);
  930. #endif
  931. //
  932. // Home Offset (M206)
  933. //
  934. _FIELD_TEST(home_offset);
  935. #if !HAS_HOME_OFFSET
  936. float home_offset[XYZ];
  937. #endif
  938. EEPROM_READ(home_offset);
  939. //
  940. // Hotend Offsets, if any
  941. //
  942. #if HOTENDS > 1
  943. // Skip hotend 0 which must be 0
  944. for (uint8_t e = 1; e < HOTENDS; e++)
  945. LOOP_XYZ(i) EEPROM_READ(hotend_offset[i][e]);
  946. #endif
  947. //
  948. // Global Leveling
  949. //
  950. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  951. EEPROM_READ(new_z_fade_height);
  952. #else
  953. EEPROM_READ(dummy);
  954. #endif
  955. //
  956. // Mesh (Manual) Bed Leveling
  957. //
  958. uint8_t mesh_num_x, mesh_num_y;
  959. EEPROM_READ(dummy);
  960. EEPROM_READ_ALWAYS(mesh_num_x);
  961. EEPROM_READ_ALWAYS(mesh_num_y);
  962. #if ENABLED(MESH_BED_LEVELING)
  963. if (!validating) mbl.z_offset = dummy;
  964. if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
  965. // EEPROM data fits the current mesh
  966. EEPROM_READ(mbl.z_values);
  967. }
  968. else {
  969. // EEPROM data is stale
  970. if (!validating) mbl.reset();
  971. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
  972. }
  973. #else
  974. // MBL is disabled - skip the stored data
  975. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
  976. #endif // MESH_BED_LEVELING
  977. _FIELD_TEST(zprobe_zoffset);
  978. #if !HAS_BED_PROBE
  979. float zprobe_zoffset;
  980. #endif
  981. EEPROM_READ(zprobe_zoffset);
  982. //
  983. // Planar Bed Leveling matrix
  984. //
  985. #if ABL_PLANAR
  986. EEPROM_READ(planner.bed_level_matrix);
  987. #else
  988. for (uint8_t q = 9; q--;) EEPROM_READ(dummy);
  989. #endif
  990. //
  991. // Bilinear Auto Bed Leveling
  992. //
  993. uint8_t grid_max_x, grid_max_y;
  994. EEPROM_READ_ALWAYS(grid_max_x); // 1 byte
  995. EEPROM_READ_ALWAYS(grid_max_y); // 1 byte
  996. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  997. if (grid_max_x == GRID_MAX_POINTS_X && grid_max_y == GRID_MAX_POINTS_Y) {
  998. if (!validating) set_bed_leveling_enabled(false);
  999. EEPROM_READ(bilinear_grid_spacing); // 2 ints
  1000. EEPROM_READ(bilinear_start); // 2 ints
  1001. EEPROM_READ(z_values); // 9 to 256 floats
  1002. }
  1003. else // EEPROM data is stale
  1004. #endif // AUTO_BED_LEVELING_BILINEAR
  1005. {
  1006. // Skip past disabled (or stale) Bilinear Grid data
  1007. int bgs[2], bs[2];
  1008. EEPROM_READ(bgs);
  1009. EEPROM_READ(bs);
  1010. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummy);
  1011. }
  1012. //
  1013. // Unified Bed Leveling active state
  1014. //
  1015. _FIELD_TEST(planner_leveling_active);
  1016. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1017. EEPROM_READ(planner.leveling_active);
  1018. EEPROM_READ(ubl.storage_slot);
  1019. #else
  1020. uint8_t dummyui8;
  1021. EEPROM_READ(dummyb);
  1022. EEPROM_READ(dummyui8);
  1023. #endif // AUTO_BED_LEVELING_UBL
  1024. //
  1025. // BLTOUCH
  1026. //
  1027. {
  1028. _FIELD_TEST(bltouch_last_written_mode);
  1029. #if ENABLED(BLTOUCH)
  1030. bool &eeprom_bltouch_last_written_mode = bltouch_last_written_mode;
  1031. #else
  1032. bool eeprom_bltouch_last_written_mode;
  1033. #endif
  1034. EEPROM_READ(eeprom_bltouch_last_written_mode);
  1035. }
  1036. //
  1037. // DELTA Geometry or Dual Endstops offsets
  1038. //
  1039. #if ENABLED(DELTA)
  1040. _FIELD_TEST(delta_height);
  1041. EEPROM_READ(delta_height); // 1 float
  1042. EEPROM_READ(delta_endstop_adj); // 3 floats
  1043. EEPROM_READ(delta_radius); // 1 float
  1044. EEPROM_READ(delta_diagonal_rod); // 1 float
  1045. EEPROM_READ(delta_segments_per_second); // 1 float
  1046. EEPROM_READ(delta_calibration_radius); // 1 float
  1047. EEPROM_READ(delta_tower_angle_trim); // 3 floats
  1048. #elif ENABLED(HANGPRINTER)
  1049. EEPROM_READ(anchor_A_y); // 1 float
  1050. EEPROM_READ(anchor_A_z); // 1 float
  1051. EEPROM_READ(anchor_B_x); // 1 float
  1052. EEPROM_READ(anchor_B_y); // 1 float
  1053. EEPROM_READ(anchor_B_z); // 1 float
  1054. EEPROM_READ(anchor_C_x); // 1 float
  1055. EEPROM_READ(anchor_C_y); // 1 float
  1056. EEPROM_READ(anchor_C_z); // 1 float
  1057. EEPROM_READ(anchor_D_z); // 1 float
  1058. EEPROM_READ(delta_segments_per_second); // 1 float
  1059. EEPROM_READ(dummy); // 1 float
  1060. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  1061. _FIELD_TEST(x_endstop_adj);
  1062. #if ENABLED(X_DUAL_ENDSTOPS)
  1063. EEPROM_READ(endstops.x_endstop_adj); // 1 float
  1064. #else
  1065. EEPROM_READ(dummy);
  1066. #endif
  1067. #if ENABLED(Y_DUAL_ENDSTOPS)
  1068. EEPROM_READ(endstops.y_endstop_adj); // 1 float
  1069. #else
  1070. EEPROM_READ(dummy);
  1071. #endif
  1072. #if ENABLED(Z_DUAL_ENDSTOPS)
  1073. EEPROM_READ(endstops.z_endstop_adj); // 1 float
  1074. #else
  1075. EEPROM_READ(dummy);
  1076. #endif
  1077. #endif
  1078. //
  1079. // LCD Preheat settings
  1080. //
  1081. _FIELD_TEST(lcd_preheat_hotend_temp);
  1082. #if DISABLED(ULTIPANEL)
  1083. int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  1084. #endif
  1085. EEPROM_READ(lcd_preheat_hotend_temp); // 2 floats
  1086. EEPROM_READ(lcd_preheat_bed_temp); // 2 floats
  1087. EEPROM_READ(lcd_preheat_fan_speed); // 2 floats
  1088. //EEPROM_ASSERT(
  1089. // WITHIN(lcd_preheat_fan_speed, 0, 255),
  1090. // "lcd_preheat_fan_speed out of range"
  1091. //);
  1092. //
  1093. // Hotend PID
  1094. //
  1095. #if ENABLED(PIDTEMP)
  1096. for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
  1097. EEPROM_READ(dummy); // Kp
  1098. if (e < HOTENDS && !isnan(dummy)) {
  1099. // do not need to scale PID values as the values in EEPROM are already scaled
  1100. if (!validating) PID_PARAM(Kp, e) = dummy;
  1101. EEPROM_READ(PID_PARAM(Ki, e));
  1102. EEPROM_READ(PID_PARAM(Kd, e));
  1103. #if ENABLED(PID_EXTRUSION_SCALING)
  1104. EEPROM_READ(PID_PARAM(Kc, e));
  1105. #else
  1106. EEPROM_READ(dummy);
  1107. #endif
  1108. }
  1109. else {
  1110. for (uint8_t q=3; q--;) EEPROM_READ(dummy); // Ki, Kd, Kc
  1111. }
  1112. }
  1113. #else // !PIDTEMP
  1114. // 4 x 4 = 16 slots for PID parameters
  1115. for (uint8_t q = MAX_EXTRUDERS * 4; q--;) EEPROM_READ(dummy); // Kp, Ki, Kd, Kc
  1116. #endif // !PIDTEMP
  1117. //
  1118. // PID Extrusion Scaling
  1119. //
  1120. _FIELD_TEST(lpq_len);
  1121. #if DISABLED(PID_EXTRUSION_SCALING)
  1122. int16_t LPQ_LEN;
  1123. #endif
  1124. EEPROM_READ(LPQ_LEN);
  1125. //
  1126. // Heated Bed PID
  1127. //
  1128. #if ENABLED(PIDTEMPBED)
  1129. EEPROM_READ(dummy); // bedKp
  1130. if (!isnan(dummy)) {
  1131. if (!validating) thermalManager.bedKp = dummy;
  1132. EEPROM_READ(thermalManager.bedKi);
  1133. EEPROM_READ(thermalManager.bedKd);
  1134. }
  1135. #else
  1136. for (uint8_t q=3; q--;) EEPROM_READ(dummy); // bedKp, bedKi, bedKd
  1137. #endif
  1138. //
  1139. // LCD Contrast
  1140. //
  1141. _FIELD_TEST(lcd_contrast);
  1142. #if !HAS_LCD_CONTRAST
  1143. int16_t lcd_contrast;
  1144. #endif
  1145. EEPROM_READ(lcd_contrast);
  1146. //
  1147. // Firmware Retraction
  1148. //
  1149. #if ENABLED(FWRETRACT)
  1150. EEPROM_READ(fwretract.autoretract_enabled);
  1151. EEPROM_READ(fwretract.retract_length);
  1152. EEPROM_READ(fwretract.retract_feedrate_mm_s);
  1153. EEPROM_READ(fwretract.retract_zlift);
  1154. EEPROM_READ(fwretract.retract_recover_length);
  1155. EEPROM_READ(fwretract.retract_recover_feedrate_mm_s);
  1156. EEPROM_READ(fwretract.swap_retract_length);
  1157. EEPROM_READ(fwretract.swap_retract_recover_length);
  1158. EEPROM_READ(fwretract.swap_retract_recover_feedrate_mm_s);
  1159. #else
  1160. EEPROM_READ(dummyb);
  1161. for (uint8_t q=8; q--;) EEPROM_READ(dummy);
  1162. #endif
  1163. //
  1164. // Volumetric & Filament Size
  1165. //
  1166. _FIELD_TEST(parser_volumetric_enabled);
  1167. #if DISABLED(NO_VOLUMETRICS)
  1168. EEPROM_READ(parser.volumetric_enabled);
  1169. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  1170. EEPROM_READ(dummy);
  1171. if (!validating && q < COUNT(planner.filament_size))
  1172. planner.filament_size[q] = dummy;
  1173. }
  1174. #else
  1175. EEPROM_READ(dummyb);
  1176. for (uint8_t q=MAX_EXTRUDERS; q--;) EEPROM_READ(dummy);
  1177. #endif
  1178. if (!validating) reset_stepper_drivers();
  1179. //
  1180. // TMC2130 Stepper Settings
  1181. //
  1182. _FIELD_TEST(tmc_stepper_current);
  1183. #if HAS_TRINAMIC
  1184. #define SET_CURR(Q) stepper##Q.setCurrent(currents[TMC_##Q] ? currents[TMC_##Q] : Q##_CURRENT, R_SENSE, HOLD_MULTIPLIER)
  1185. uint16_t currents[TMC_AXES];
  1186. EEPROM_READ(currents);
  1187. if (!validating) {
  1188. #if AXIS_IS_TMC(X)
  1189. SET_CURR(X);
  1190. #endif
  1191. #if AXIS_IS_TMC(Y)
  1192. SET_CURR(Y);
  1193. #endif
  1194. #if AXIS_IS_TMC(Z)
  1195. SET_CURR(Z);
  1196. #endif
  1197. #if AXIS_IS_TMC(X2)
  1198. SET_CURR(X2);
  1199. #endif
  1200. #if AXIS_IS_TMC(Y2)
  1201. SET_CURR(Y2);
  1202. #endif
  1203. #if AXIS_IS_TMC(Z2)
  1204. SET_CURR(Z2);
  1205. #endif
  1206. #if AXIS_IS_TMC(E0)
  1207. SET_CURR(E0);
  1208. #endif
  1209. #if AXIS_IS_TMC(E1)
  1210. SET_CURR(E1);
  1211. #endif
  1212. #if AXIS_IS_TMC(E2)
  1213. SET_CURR(E2);
  1214. #endif
  1215. #if AXIS_IS_TMC(E3)
  1216. SET_CURR(E3);
  1217. #endif
  1218. #if AXIS_IS_TMC(E4)
  1219. SET_CURR(E4);
  1220. #endif
  1221. }
  1222. #else
  1223. uint16_t val;
  1224. for (uint8_t q=TMC_AXES; q--;) EEPROM_READ(val);
  1225. #endif
  1226. #if ENABLED(HYBRID_THRESHOLD)
  1227. #define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, tmc_hybrid_threshold[TMC_##Q], planner.axis_steps_per_mm[_AXIS(A)])
  1228. uint32_t tmc_hybrid_threshold[TMC_AXES];
  1229. EEPROM_READ(tmc_hybrid_threshold);
  1230. if (!validating) {
  1231. #if AXIS_HAS_STEALTHCHOP(X)
  1232. TMC_SET_PWMTHRS(X, X);
  1233. #endif
  1234. #if AXIS_HAS_STEALTHCHOP(Y)
  1235. TMC_SET_PWMTHRS(Y, Y);
  1236. #endif
  1237. #if AXIS_HAS_STEALTHCHOP(Z)
  1238. TMC_SET_PWMTHRS(Z, Z);
  1239. #endif
  1240. #if AXIS_HAS_STEALTHCHOP(X2)
  1241. TMC_SET_PWMTHRS(X, X2);
  1242. #endif
  1243. #if AXIS_HAS_STEALTHCHOP(Y2)
  1244. TMC_SET_PWMTHRS(Y, Y2);
  1245. #endif
  1246. #if AXIS_HAS_STEALTHCHOP(Z2)
  1247. TMC_SET_PWMTHRS(Z, Z2);
  1248. #endif
  1249. #if AXIS_HAS_STEALTHCHOP(E0)
  1250. TMC_SET_PWMTHRS(E, E0);
  1251. #endif
  1252. #if AXIS_HAS_STEALTHCHOP(E1)
  1253. TMC_SET_PWMTHRS(E, E1);
  1254. #endif
  1255. #if AXIS_HAS_STEALTHCHOP(E2)
  1256. TMC_SET_PWMTHRS(E, E2);
  1257. #endif
  1258. #if AXIS_HAS_STEALTHCHOP(E3)
  1259. TMC_SET_PWMTHRS(E, E3);
  1260. #endif
  1261. #if AXIS_HAS_STEALTHCHOP(E4)
  1262. TMC_SET_PWMTHRS(E, E4);
  1263. #endif
  1264. }
  1265. #else
  1266. uint32_t thrs_val;
  1267. for (uint8_t q=TMC_AXES; q--;) EEPROM_READ(thrs_val);
  1268. #endif
  1269. /*
  1270. * TMC2130 Sensorless homing threshold.
  1271. * X and X2 use the same value
  1272. * Y and Y2 use the same value
  1273. * Z and Z2 use the same value
  1274. */
  1275. int16_t tmc_sgt[XYZ];
  1276. EEPROM_READ(tmc_sgt);
  1277. #if ENABLED(SENSORLESS_HOMING)
  1278. if (!validating) {
  1279. #ifdef X_HOMING_SENSITIVITY
  1280. #if AXIS_HAS_STALLGUARD(X)
  1281. stepperX.sgt(tmc_sgt[0]);
  1282. #endif
  1283. #if AXIS_HAS_STALLGUARD(X2)
  1284. stepperX2.sgt(tmc_sgt[0]);
  1285. #endif
  1286. #endif
  1287. #ifdef Y_HOMING_SENSITIVITY
  1288. #if AXIS_HAS_STALLGUARD(Y)
  1289. stepperY.sgt(tmc_sgt[1]);
  1290. #endif
  1291. #if AXIS_HAS_STALLGUARD(Y2)
  1292. stepperY2.sgt(tmc_sgt[1]);
  1293. #endif
  1294. #endif
  1295. #ifdef Z_HOMING_SENSITIVITY
  1296. #if AXIS_HAS_STALLGUARD(Z)
  1297. stepperZ.sgt(tmc_sgt[2]);
  1298. #endif
  1299. #if AXIS_HAS_STALLGUARD(Z2)
  1300. stepperZ2.sgt(tmc_sgt[2]);
  1301. #endif
  1302. #endif
  1303. }
  1304. #endif
  1305. //
  1306. // Linear Advance
  1307. //
  1308. _FIELD_TEST(planner_extruder_advance_K);
  1309. #if ENABLED(LIN_ADVANCE)
  1310. EEPROM_READ(planner.extruder_advance_K);
  1311. #else
  1312. EEPROM_READ(dummy);
  1313. #endif
  1314. //
  1315. // Motor Current PWM
  1316. //
  1317. _FIELD_TEST(motor_current_setting);
  1318. #if HAS_MOTOR_CURRENT_PWM
  1319. for (uint8_t q = XYZ; q--;) EEPROM_READ(stepper.motor_current_setting[q]);
  1320. #else
  1321. uint32_t dummyui32[XYZ];
  1322. EEPROM_READ(dummyui32);
  1323. #endif
  1324. //
  1325. // CNC Coordinate System
  1326. //
  1327. _FIELD_TEST(coordinate_system);
  1328. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  1329. if (!validating) (void)select_coordinate_system(-1); // Go back to machine space
  1330. EEPROM_READ(coordinate_system); // 27 floats
  1331. #else
  1332. for (uint8_t q = MAX_COORDINATE_SYSTEMS * XYZ; q--;) EEPROM_READ(dummy);
  1333. #endif
  1334. //
  1335. // Skew correction factors
  1336. //
  1337. _FIELD_TEST(planner_xy_skew_factor);
  1338. #if ENABLED(SKEW_CORRECTION_GCODE)
  1339. EEPROM_READ(planner.xy_skew_factor);
  1340. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  1341. EEPROM_READ(planner.xz_skew_factor);
  1342. EEPROM_READ(planner.yz_skew_factor);
  1343. #else
  1344. EEPROM_READ(dummy);
  1345. EEPROM_READ(dummy);
  1346. #endif
  1347. #else
  1348. for (uint8_t q = 3; q--;) EEPROM_READ(dummy);
  1349. #endif
  1350. //
  1351. // Advanced Pause filament load & unload lengths
  1352. //
  1353. _FIELD_TEST(filament_change_unload_length);
  1354. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1355. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  1356. EEPROM_READ(dummy);
  1357. if (!validating && q < COUNT(filament_change_unload_length)) filament_change_unload_length[q] = dummy;
  1358. }
  1359. for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
  1360. EEPROM_READ(dummy);
  1361. if (!validating && q < COUNT(filament_change_load_length)) filament_change_load_length[q] = dummy;
  1362. }
  1363. #else
  1364. for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_READ(dummy);
  1365. #endif
  1366. eeprom_error = size_error(eeprom_index - (EEPROM_OFFSET));
  1367. if (eeprom_error) {
  1368. SERIAL_ECHO_START();
  1369. SERIAL_ECHOPAIR("Index: ", int(eeprom_index - (EEPROM_OFFSET)));
  1370. SERIAL_ECHOLNPAIR(" Size: ", datasize());
  1371. }
  1372. else if (working_crc != stored_crc) {
  1373. eeprom_error = true;
  1374. #if ENABLED(EEPROM_CHITCHAT)
  1375. SERIAL_ERROR_START();
  1376. SERIAL_ERRORPGM("EEPROM CRC mismatch - (stored) ");
  1377. SERIAL_ERROR(stored_crc);
  1378. SERIAL_ERRORPGM(" != ");
  1379. SERIAL_ERROR(working_crc);
  1380. SERIAL_ERRORLNPGM(" (calculated)!");
  1381. #endif
  1382. }
  1383. else if (!validating) {
  1384. #if ENABLED(EEPROM_CHITCHAT)
  1385. SERIAL_ECHO_START();
  1386. SERIAL_ECHO(version);
  1387. SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET));
  1388. SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)working_crc);
  1389. SERIAL_ECHOLNPGM(")");
  1390. #endif
  1391. }
  1392. if (!validating && !eeprom_error) postprocess();
  1393. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1394. if (!validating) {
  1395. ubl.report_state();
  1396. if (!ubl.sanity_check()) {
  1397. SERIAL_EOL();
  1398. #if ENABLED(EEPROM_CHITCHAT)
  1399. ubl.echo_name();
  1400. SERIAL_ECHOLNPGM(" initialized.\n");
  1401. #endif
  1402. }
  1403. else {
  1404. eeprom_error = true;
  1405. #if ENABLED(EEPROM_CHITCHAT)
  1406. SERIAL_PROTOCOLPGM("?Can't enable ");
  1407. ubl.echo_name();
  1408. SERIAL_PROTOCOLLNPGM(".");
  1409. #endif
  1410. ubl.reset();
  1411. }
  1412. if (ubl.storage_slot >= 0) {
  1413. load_mesh(ubl.storage_slot);
  1414. #if ENABLED(EEPROM_CHITCHAT)
  1415. SERIAL_ECHOPAIR("Mesh ", ubl.storage_slot);
  1416. SERIAL_ECHOLNPGM(" loaded from storage.");
  1417. #endif
  1418. }
  1419. else {
  1420. ubl.reset();
  1421. #if ENABLED(EEPROM_CHITCHAT)
  1422. SERIAL_ECHOLNPGM("UBL System reset()");
  1423. #endif
  1424. }
  1425. }
  1426. #endif
  1427. }
  1428. #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
  1429. if (!validating) report();
  1430. #endif
  1431. return !eeprom_error;
  1432. }
  1433. bool MarlinSettings::validate() {
  1434. validating = true;
  1435. const bool success = _load();
  1436. validating = false;
  1437. return success;
  1438. }
  1439. bool MarlinSettings::load() {
  1440. if (validate()) return _load();
  1441. reset();
  1442. return true;
  1443. }
  1444. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1445. #if ENABLED(EEPROM_CHITCHAT)
  1446. void ubl_invalid_slot(const int s) {
  1447. SERIAL_PROTOCOLLNPGM("?Invalid slot.");
  1448. SERIAL_PROTOCOL(s);
  1449. SERIAL_PROTOCOLLNPGM(" mesh slots available.");
  1450. }
  1451. #endif
  1452. uint16_t MarlinSettings::meshes_start_index() {
  1453. return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8; // Pad the end of configuration data so it can float up
  1454. // or down a little bit without disrupting the mesh data
  1455. }
  1456. uint16_t MarlinSettings::calc_num_meshes() {
  1457. return (meshes_end - meshes_start_index()) / sizeof(ubl.z_values);
  1458. }
  1459. int MarlinSettings::mesh_slot_offset(const int8_t slot) {
  1460. return meshes_end - (slot + 1) * sizeof(ubl.z_values);
  1461. }
  1462. void MarlinSettings::store_mesh(const int8_t slot) {
  1463. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1464. const int16_t a = calc_num_meshes();
  1465. if (!WITHIN(slot, 0, a - 1)) {
  1466. #if ENABLED(EEPROM_CHITCHAT)
  1467. ubl_invalid_slot(a);
  1468. SERIAL_PROTOCOLPAIR("E2END=", E2END);
  1469. SERIAL_PROTOCOLPAIR(" meshes_end=", meshes_end);
  1470. SERIAL_PROTOCOLLNPAIR(" slot=", slot);
  1471. SERIAL_EOL();
  1472. #endif
  1473. return;
  1474. }
  1475. int pos = mesh_slot_offset(slot);
  1476. uint16_t crc = 0;
  1477. write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc);
  1478. // Write crc to MAT along with other data, or just tack on to the beginning or end
  1479. #if ENABLED(EEPROM_CHITCHAT)
  1480. SERIAL_PROTOCOLLNPAIR("Mesh saved in slot ", slot);
  1481. #endif
  1482. #else
  1483. // Other mesh types
  1484. #endif
  1485. }
  1486. void MarlinSettings::load_mesh(const int8_t slot, void * const into/*=NULL*/) {
  1487. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1488. const int16_t a = settings.calc_num_meshes();
  1489. if (!WITHIN(slot, 0, a - 1)) {
  1490. #if ENABLED(EEPROM_CHITCHAT)
  1491. ubl_invalid_slot(a);
  1492. #endif
  1493. return;
  1494. }
  1495. int pos = mesh_slot_offset(slot);
  1496. uint16_t crc = 0;
  1497. uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
  1498. read_data(pos, dest, sizeof(ubl.z_values), &crc);
  1499. // Compare crc with crc from MAT, or read from end
  1500. #if ENABLED(EEPROM_CHITCHAT)
  1501. SERIAL_PROTOCOLLNPAIR("Mesh loaded from slot ", slot);
  1502. #endif
  1503. #else
  1504. // Other mesh types
  1505. #endif
  1506. }
  1507. //void MarlinSettings::delete_mesh() { return; }
  1508. //void MarlinSettings::defrag_meshes() { return; }
  1509. #endif // AUTO_BED_LEVELING_UBL
  1510. #else // !EEPROM_SETTINGS
  1511. bool MarlinSettings::save() {
  1512. SERIAL_ERROR_START();
  1513. SERIAL_ERRORLNPGM("EEPROM disabled");
  1514. return false;
  1515. }
  1516. #endif // !EEPROM_SETTINGS
  1517. /**
  1518. * M502 - Reset Configuration
  1519. */
  1520. void MarlinSettings::reset() {
  1521. static const float tmp1[] PROGMEM = DEFAULT_AXIS_STEPS_PER_UNIT, tmp2[] PROGMEM = DEFAULT_MAX_FEEDRATE;
  1522. static const uint32_t tmp3[] PROGMEM = DEFAULT_MAX_ACCELERATION;
  1523. LOOP_NUM_AXIS_N(i) {
  1524. planner.axis_steps_per_mm[i] = pgm_read_float(&tmp1[i < COUNT(tmp1) ? i : COUNT(tmp1) - 1]);
  1525. planner.max_feedrate_mm_s[i] = pgm_read_float(&tmp2[i < COUNT(tmp2) ? i : COUNT(tmp2) - 1]);
  1526. planner.max_acceleration_mm_per_s2[i] = pgm_read_dword_near(&tmp3[i < COUNT(tmp3) ? i : COUNT(tmp3) - 1]);
  1527. }
  1528. planner.min_segment_time_us = DEFAULT_MINSEGMENTTIME;
  1529. planner.acceleration = DEFAULT_ACCELERATION;
  1530. planner.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
  1531. planner.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
  1532. planner.min_feedrate_mm_s = DEFAULT_MINIMUMFEEDRATE;
  1533. planner.min_travel_feedrate_mm_s = DEFAULT_MINTRAVELFEEDRATE;
  1534. #if ENABLED(JUNCTION_DEVIATION)
  1535. planner.junction_deviation_mm = float(JUNCTION_DEVIATION_MM);
  1536. #else
  1537. #if ENABLED(HANGPRINTER)
  1538. planner.max_jerk[A_AXIS] = DEFAULT_AJERK;
  1539. planner.max_jerk[B_AXIS] = DEFAULT_BJERK;
  1540. planner.max_jerk[C_AXIS] = DEFAULT_CJERK;
  1541. planner.max_jerk[D_AXIS] = DEFAULT_DJERK;
  1542. #else
  1543. planner.max_jerk[X_AXIS] = DEFAULT_XJERK;
  1544. planner.max_jerk[Y_AXIS] = DEFAULT_YJERK;
  1545. planner.max_jerk[Z_AXIS] = DEFAULT_ZJERK;
  1546. #endif
  1547. planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
  1548. #endif
  1549. #if HAS_HOME_OFFSET
  1550. ZERO(home_offset);
  1551. #endif
  1552. #if HOTENDS > 1
  1553. constexpr float tmp4[XYZ][HOTENDS] = {
  1554. HOTEND_OFFSET_X,
  1555. HOTEND_OFFSET_Y
  1556. #if HAS_HOTEND_OFFSET_Z
  1557. , HOTEND_OFFSET_Z
  1558. #else
  1559. , { 0 }
  1560. #endif
  1561. };
  1562. static_assert(
  1563. tmp4[X_AXIS][0] == 0 && tmp4[Y_AXIS][0] == 0 && tmp4[Z_AXIS][0] == 0,
  1564. "Offsets for the first hotend must be 0.0."
  1565. );
  1566. LOOP_XYZ(i) HOTEND_LOOP() hotend_offset[i][e] = tmp4[i][e];
  1567. #endif
  1568. //
  1569. // Global Leveling
  1570. //
  1571. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1572. new_z_fade_height = 0.0;
  1573. #endif
  1574. #if HAS_LEVELING
  1575. reset_bed_level();
  1576. #endif
  1577. #if HAS_BED_PROBE
  1578. zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER;
  1579. #endif
  1580. #if ENABLED(DELTA)
  1581. const float adj[ABC] = DELTA_ENDSTOP_ADJ,
  1582. dta[ABC] = DELTA_TOWER_ANGLE_TRIM;
  1583. delta_height = DELTA_HEIGHT;
  1584. COPY(delta_endstop_adj, adj);
  1585. delta_radius = DELTA_RADIUS;
  1586. delta_diagonal_rod = DELTA_DIAGONAL_ROD;
  1587. delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
  1588. delta_calibration_radius = DELTA_CALIBRATION_RADIUS;
  1589. COPY(delta_tower_angle_trim, dta);
  1590. #elif ENABLED(HANGPRINTER)
  1591. anchor_A_y = float(ANCHOR_A_Y);
  1592. anchor_A_z = float(ANCHOR_A_Z);
  1593. anchor_B_x = float(ANCHOR_B_X);
  1594. anchor_B_y = float(ANCHOR_B_Y);
  1595. anchor_B_z = float(ANCHOR_B_Z);
  1596. anchor_C_x = float(ANCHOR_C_X);
  1597. anchor_C_y = float(ANCHOR_C_Y);
  1598. anchor_C_z = float(ANCHOR_C_Z);
  1599. anchor_D_z = float(ANCHOR_D_Z);
  1600. delta_segments_per_second = KINEMATIC_SEGMENTS_PER_SECOND;
  1601. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  1602. #if ENABLED(X_DUAL_ENDSTOPS)
  1603. endstops.x_endstop_adj = (
  1604. #ifdef X_DUAL_ENDSTOPS_ADJUSTMENT
  1605. X_DUAL_ENDSTOPS_ADJUSTMENT
  1606. #else
  1607. 0
  1608. #endif
  1609. );
  1610. #endif
  1611. #if ENABLED(Y_DUAL_ENDSTOPS)
  1612. endstops.y_endstop_adj = (
  1613. #ifdef Y_DUAL_ENDSTOPS_ADJUSTMENT
  1614. Y_DUAL_ENDSTOPS_ADJUSTMENT
  1615. #else
  1616. 0
  1617. #endif
  1618. );
  1619. #endif
  1620. #if ENABLED(Z_DUAL_ENDSTOPS)
  1621. endstops.z_endstop_adj = (
  1622. #ifdef Z_DUAL_ENDSTOPS_ADJUSTMENT
  1623. Z_DUAL_ENDSTOPS_ADJUSTMENT
  1624. #else
  1625. 0
  1626. #endif
  1627. );
  1628. #endif
  1629. #endif
  1630. #if ENABLED(ULTIPANEL)
  1631. lcd_preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
  1632. lcd_preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
  1633. lcd_preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
  1634. lcd_preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
  1635. lcd_preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
  1636. lcd_preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
  1637. #endif
  1638. #if ENABLED(PIDTEMP)
  1639. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  1640. HOTEND_LOOP()
  1641. #endif
  1642. {
  1643. PID_PARAM(Kp, e) = float(DEFAULT_Kp);
  1644. PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
  1645. PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
  1646. #if ENABLED(PID_EXTRUSION_SCALING)
  1647. PID_PARAM(Kc, e) = DEFAULT_Kc;
  1648. #endif
  1649. }
  1650. #if ENABLED(PID_EXTRUSION_SCALING)
  1651. thermalManager.lpq_len = 20; // default last-position-queue size
  1652. #endif
  1653. #endif // PIDTEMP
  1654. #if ENABLED(PIDTEMPBED)
  1655. thermalManager.bedKp = DEFAULT_bedKp;
  1656. thermalManager.bedKi = scalePID_i(DEFAULT_bedKi);
  1657. thermalManager.bedKd = scalePID_d(DEFAULT_bedKd);
  1658. #endif
  1659. #if HAS_LCD_CONTRAST
  1660. lcd_contrast = DEFAULT_LCD_CONTRAST;
  1661. #endif
  1662. #if ENABLED(FWRETRACT)
  1663. fwretract.reset();
  1664. #endif
  1665. #if DISABLED(NO_VOLUMETRICS)
  1666. parser.volumetric_enabled =
  1667. #if ENABLED(VOLUMETRIC_DEFAULT_ON)
  1668. true
  1669. #else
  1670. false
  1671. #endif
  1672. ;
  1673. for (uint8_t q = 0; q < COUNT(planner.filament_size); q++)
  1674. planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
  1675. #endif
  1676. endstops.enable_globally(
  1677. #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
  1678. true
  1679. #else
  1680. false
  1681. #endif
  1682. );
  1683. reset_stepper_drivers();
  1684. #if ENABLED(LIN_ADVANCE)
  1685. planner.extruder_advance_K = LIN_ADVANCE_K;
  1686. #endif
  1687. #if HAS_MOTOR_CURRENT_PWM
  1688. uint32_t tmp_motor_current_setting[XYZ] = PWM_MOTOR_CURRENT;
  1689. for (uint8_t q = XYZ; q--;)
  1690. stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
  1691. #endif
  1692. #if ENABLED(SKEW_CORRECTION_GCODE)
  1693. planner.xy_skew_factor = XY_SKEW_FACTOR;
  1694. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  1695. planner.xz_skew_factor = XZ_SKEW_FACTOR;
  1696. planner.yz_skew_factor = YZ_SKEW_FACTOR;
  1697. #endif
  1698. #endif
  1699. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1700. for (uint8_t e = 0; e < EXTRUDERS; e++) {
  1701. filament_change_unload_length[e] = FILAMENT_CHANGE_UNLOAD_LENGTH;
  1702. filament_change_load_length[e] = FILAMENT_CHANGE_FAST_LOAD_LENGTH;
  1703. }
  1704. #endif
  1705. postprocess();
  1706. #if ENABLED(EEPROM_CHITCHAT)
  1707. SERIAL_ECHO_START();
  1708. SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
  1709. #endif
  1710. }
  1711. #if DISABLED(DISABLE_M503)
  1712. #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START(); }while(0)
  1713. #if HAS_TRINAMIC
  1714. void say_M906() { SERIAL_ECHOPGM(" M906"); }
  1715. #if ENABLED(HYBRID_THRESHOLD)
  1716. void say_M913() { SERIAL_ECHOPGM(" M913"); }
  1717. #endif
  1718. #if ENABLED(SENSORLESS_HOMING)
  1719. void say_M914() { SERIAL_ECHOPGM(" M914"); }
  1720. #endif
  1721. #endif
  1722. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1723. void say_M603() { SERIAL_ECHOPGM(" M603 "); }
  1724. #endif
  1725. inline void say_units(const bool colon=false) {
  1726. serialprintPGM(
  1727. #if ENABLED(INCH_MODE_SUPPORT)
  1728. parser.linear_unit_factor != 1.0 ? PSTR(" (in)") :
  1729. #endif
  1730. PSTR(" (mm)")
  1731. );
  1732. if (colon) SERIAL_ECHOLNPGM(":");
  1733. }
  1734. /**
  1735. * M503 - Report current settings in RAM
  1736. *
  1737. * Unless specifically disabled, M503 is available even without EEPROM
  1738. */
  1739. void MarlinSettings::report(const bool forReplay) {
  1740. /**
  1741. * Announce current units, in case inches are being displayed
  1742. */
  1743. CONFIG_ECHO_START;
  1744. #if ENABLED(INCH_MODE_SUPPORT)
  1745. #define LINEAR_UNIT(N) (float(N) / parser.linear_unit_factor)
  1746. #define VOLUMETRIC_UNIT(N) (float(N) / (parser.volumetric_enabled ? parser.volumetric_unit_factor : parser.linear_unit_factor))
  1747. SERIAL_ECHOPGM(" G2");
  1748. SERIAL_CHAR(parser.linear_unit_factor == 1.0 ? '1' : '0');
  1749. SERIAL_ECHOPGM(" ;");
  1750. say_units();
  1751. #else
  1752. #define LINEAR_UNIT(N) (N)
  1753. #define VOLUMETRIC_UNIT(N) (N)
  1754. SERIAL_ECHOPGM(" G21 ;");
  1755. say_units();
  1756. #endif
  1757. SERIAL_EOL();
  1758. #if ENABLED(ULTIPANEL)
  1759. // Temperature units - for Ultipanel temperature options
  1760. CONFIG_ECHO_START;
  1761. #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
  1762. #define TEMP_UNIT(N) parser.to_temp_units(N)
  1763. SERIAL_ECHOPGM(" M149 ");
  1764. SERIAL_CHAR(parser.temp_units_code());
  1765. SERIAL_ECHOPGM(" ; Units in ");
  1766. serialprintPGM(parser.temp_units_name());
  1767. #else
  1768. #define TEMP_UNIT(N) (N)
  1769. SERIAL_ECHOLNPGM(" M149 C ; Units in Celsius");
  1770. #endif
  1771. #endif
  1772. SERIAL_EOL();
  1773. #if DISABLED(NO_VOLUMETRICS)
  1774. /**
  1775. * Volumetric extrusion M200
  1776. */
  1777. if (!forReplay) {
  1778. CONFIG_ECHO_START;
  1779. SERIAL_ECHOPGM("Filament settings:");
  1780. if (parser.volumetric_enabled)
  1781. SERIAL_EOL();
  1782. else
  1783. SERIAL_ECHOLNPGM(" Disabled");
  1784. }
  1785. CONFIG_ECHO_START;
  1786. SERIAL_ECHOPAIR(" M200 D", LINEAR_UNIT(planner.filament_size[0]));
  1787. SERIAL_EOL();
  1788. #if EXTRUDERS > 1
  1789. CONFIG_ECHO_START;
  1790. SERIAL_ECHOPAIR(" M200 T1 D", LINEAR_UNIT(planner.filament_size[1]));
  1791. SERIAL_EOL();
  1792. #if EXTRUDERS > 2
  1793. CONFIG_ECHO_START;
  1794. SERIAL_ECHOPAIR(" M200 T2 D", LINEAR_UNIT(planner.filament_size[2]));
  1795. SERIAL_EOL();
  1796. #if EXTRUDERS > 3
  1797. CONFIG_ECHO_START;
  1798. SERIAL_ECHOPAIR(" M200 T3 D", LINEAR_UNIT(planner.filament_size[3]));
  1799. SERIAL_EOL();
  1800. #if EXTRUDERS > 4
  1801. CONFIG_ECHO_START;
  1802. SERIAL_ECHOPAIR(" M200 T4 D", LINEAR_UNIT(planner.filament_size[4]));
  1803. SERIAL_EOL();
  1804. #endif // EXTRUDERS > 4
  1805. #endif // EXTRUDERS > 3
  1806. #endif // EXTRUDERS > 2
  1807. #endif // EXTRUDERS > 1
  1808. if (!parser.volumetric_enabled) {
  1809. CONFIG_ECHO_START;
  1810. SERIAL_ECHOLNPGM(" M200 D0");
  1811. }
  1812. #endif // !NO_VOLUMETRICS
  1813. if (!forReplay) {
  1814. CONFIG_ECHO_START;
  1815. SERIAL_ECHOLNPGM("Steps per unit:");
  1816. }
  1817. CONFIG_ECHO_START;
  1818. #if ENABLED(HANGPRINTER)
  1819. SERIAL_ECHOPAIR(" M92 A", LINEAR_UNIT(planner.axis_steps_per_mm[A_AXIS]));
  1820. SERIAL_ECHOPAIR(" B", LINEAR_UNIT(planner.axis_steps_per_mm[B_AXIS]));
  1821. SERIAL_ECHOPAIR(" C", LINEAR_UNIT(planner.axis_steps_per_mm[C_AXIS]));
  1822. SERIAL_ECHOPAIR(" D", LINEAR_UNIT(planner.axis_steps_per_mm[D_AXIS]));
  1823. #else
  1824. SERIAL_ECHOPAIR(" M92 X", LINEAR_UNIT(planner.axis_steps_per_mm[X_AXIS]));
  1825. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.axis_steps_per_mm[Y_AXIS]));
  1826. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.axis_steps_per_mm[Z_AXIS]));
  1827. #endif
  1828. #if DISABLED(DISTINCT_E_FACTORS)
  1829. SERIAL_ECHOPAIR(" E", VOLUMETRIC_UNIT(planner.axis_steps_per_mm[E_AXIS]));
  1830. #endif
  1831. SERIAL_EOL();
  1832. #if ENABLED(DISTINCT_E_FACTORS)
  1833. CONFIG_ECHO_START;
  1834. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1835. SERIAL_ECHOPAIR(" M92 T", (int)i);
  1836. SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.axis_steps_per_mm[E_AXIS + i]));
  1837. }
  1838. #endif
  1839. if (!forReplay) {
  1840. CONFIG_ECHO_START;
  1841. SERIAL_ECHOLNPGM("Maximum feedrates (units/s):");
  1842. }
  1843. CONFIG_ECHO_START;
  1844. #if ENABLED(HANGPRINTER)
  1845. SERIAL_ECHOPAIR(" M203 A", LINEAR_UNIT(planner.max_feedrate_mm_s[A_AXIS]));
  1846. SERIAL_ECHOPAIR(" B", LINEAR_UNIT(planner.max_feedrate_mm_s[B_AXIS]));
  1847. SERIAL_ECHOPAIR(" C", LINEAR_UNIT(planner.max_feedrate_mm_s[C_AXIS]));
  1848. SERIAL_ECHOPAIR(" D", LINEAR_UNIT(planner.max_feedrate_mm_s[D_AXIS]));
  1849. #else
  1850. SERIAL_ECHOPAIR(" M203 X", LINEAR_UNIT(planner.max_feedrate_mm_s[X_AXIS]));
  1851. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.max_feedrate_mm_s[Y_AXIS]));
  1852. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.max_feedrate_mm_s[Z_AXIS]));
  1853. #endif
  1854. #if DISABLED(DISTINCT_E_FACTORS)
  1855. SERIAL_ECHOPAIR(" E", VOLUMETRIC_UNIT(planner.max_feedrate_mm_s[E_AXIS]));
  1856. #endif
  1857. SERIAL_EOL();
  1858. #if ENABLED(DISTINCT_E_FACTORS)
  1859. CONFIG_ECHO_START;
  1860. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1861. SERIAL_ECHOPAIR(" M203 T", (int)i);
  1862. SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.max_feedrate_mm_s[E_AXIS + i]));
  1863. }
  1864. #endif
  1865. if (!forReplay) {
  1866. CONFIG_ECHO_START;
  1867. SERIAL_ECHOLNPGM("Maximum Acceleration (units/s2):");
  1868. }
  1869. CONFIG_ECHO_START;
  1870. #if ENABLED(HANGPRINTER)
  1871. SERIAL_ECHOPAIR(" M201 A", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[A_AXIS]));
  1872. SERIAL_ECHOPAIR(" B", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[B_AXIS]));
  1873. SERIAL_ECHOPAIR(" C", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[C_AXIS]));
  1874. SERIAL_ECHOPAIR(" D", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[D_AXIS]));
  1875. #else
  1876. SERIAL_ECHOPAIR(" M201 X", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[X_AXIS]));
  1877. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[Y_AXIS]));
  1878. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[Z_AXIS]));
  1879. #endif
  1880. #if DISABLED(DISTINCT_E_FACTORS)
  1881. SERIAL_ECHOPAIR(" E", VOLUMETRIC_UNIT(planner.max_acceleration_mm_per_s2[E_AXIS]));
  1882. #endif
  1883. SERIAL_EOL();
  1884. #if ENABLED(DISTINCT_E_FACTORS)
  1885. CONFIG_ECHO_START;
  1886. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1887. SERIAL_ECHOPAIR(" M201 T", (int)i);
  1888. SERIAL_ECHOLNPAIR(" E", VOLUMETRIC_UNIT(planner.max_acceleration_mm_per_s2[E_AXIS + i]));
  1889. }
  1890. #endif
  1891. if (!forReplay) {
  1892. CONFIG_ECHO_START;
  1893. SERIAL_ECHOLNPGM("Acceleration (units/s2): P<print_accel> R<retract_accel> T<travel_accel>");
  1894. }
  1895. CONFIG_ECHO_START;
  1896. SERIAL_ECHOPAIR(" M204 P", LINEAR_UNIT(planner.acceleration));
  1897. SERIAL_ECHOPAIR(" R", LINEAR_UNIT(planner.retract_acceleration));
  1898. SERIAL_ECHOLNPAIR(" T", LINEAR_UNIT(planner.travel_acceleration));
  1899. if (!forReplay) {
  1900. CONFIG_ECHO_START;
  1901. SERIAL_ECHOPGM("Advanced: Q<min_segment_time_us> S<min_feedrate> T<min_travel_feedrate>");
  1902. #if ENABLED(JUNCTION_DEVIATION)
  1903. SERIAL_ECHOPGM(" J<junc_dev>");
  1904. #else
  1905. #if ENABLED(HANGPRINTER)
  1906. SERIAL_ECHOPGM(" A<max_a_jerk> B<max_b_jerk> C<max_c_jerk> D<max_d_jerk>");
  1907. #else
  1908. SERIAL_ECHOPGM(" X<max_x_jerk> Y<max_y_jerk> Z<max_z_jerk>");
  1909. #endif
  1910. #endif
  1911. #if DISABLED(JUNCTION_DEVIATION) || ENABLED(LIN_ADVANCE)
  1912. SERIAL_ECHOPGM(" E<max_e_jerk>");
  1913. #endif
  1914. SERIAL_EOL();
  1915. }
  1916. CONFIG_ECHO_START;
  1917. SERIAL_ECHOPAIR(" M205 Q", LINEAR_UNIT(planner.min_segment_time_us));
  1918. SERIAL_ECHOPAIR(" S", LINEAR_UNIT(planner.min_feedrate_mm_s));
  1919. SERIAL_ECHOPAIR(" T", LINEAR_UNIT(planner.min_travel_feedrate_mm_s));
  1920. #if ENABLED(JUNCTION_DEVIATION)
  1921. SERIAL_ECHOPAIR(" J", LINEAR_UNIT(planner.junction_deviation_mm));
  1922. #else
  1923. #if ENABLED(HANGPRINTER)
  1924. SERIAL_ECHOPAIR(" A", LINEAR_UNIT(planner.max_jerk[A_AXIS]));
  1925. SERIAL_ECHOPAIR(" B", LINEAR_UNIT(planner.max_jerk[B_AXIS]));
  1926. SERIAL_ECHOPAIR(" C", LINEAR_UNIT(planner.max_jerk[C_AXIS]));
  1927. SERIAL_ECHOPAIR(" D", LINEAR_UNIT(planner.max_jerk[D_AXIS]));
  1928. #else
  1929. SERIAL_ECHOPAIR(" X", LINEAR_UNIT(planner.max_jerk[X_AXIS]));
  1930. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.max_jerk[Y_AXIS]));
  1931. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.max_jerk[Z_AXIS]));
  1932. #endif
  1933. SERIAL_ECHOPAIR(" E", LINEAR_UNIT(planner.max_jerk[E_AXIS]));
  1934. #endif
  1935. SERIAL_EOL();
  1936. #if HAS_M206_COMMAND
  1937. if (!forReplay) {
  1938. CONFIG_ECHO_START;
  1939. SERIAL_ECHOLNPGM("Home offset:");
  1940. }
  1941. CONFIG_ECHO_START;
  1942. SERIAL_ECHOPAIR(" M206 X", LINEAR_UNIT(home_offset[X_AXIS]));
  1943. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(home_offset[Y_AXIS]));
  1944. SERIAL_ECHOLNPAIR(" Z", LINEAR_UNIT(home_offset[Z_AXIS]));
  1945. #endif
  1946. #if HOTENDS > 1
  1947. if (!forReplay) {
  1948. CONFIG_ECHO_START;
  1949. SERIAL_ECHOLNPGM("Hotend offsets:");
  1950. }
  1951. CONFIG_ECHO_START;
  1952. for (uint8_t e = 1; e < HOTENDS; e++) {
  1953. SERIAL_ECHOPAIR(" M218 T", (int)e);
  1954. SERIAL_ECHOPAIR(" X", LINEAR_UNIT(hotend_offset[X_AXIS][e]));
  1955. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(hotend_offset[Y_AXIS][e]));
  1956. #if HAS_HOTEND_OFFSET_Z
  1957. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(hotend_offset[Z_AXIS][e]));
  1958. #endif
  1959. SERIAL_EOL();
  1960. }
  1961. #endif
  1962. /**
  1963. * Bed Leveling
  1964. */
  1965. #if HAS_LEVELING
  1966. #if ENABLED(MESH_BED_LEVELING)
  1967. if (!forReplay) {
  1968. CONFIG_ECHO_START;
  1969. SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
  1970. }
  1971. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1972. if (!forReplay) {
  1973. CONFIG_ECHO_START;
  1974. ubl.echo_name();
  1975. SERIAL_ECHOLNPGM(":");
  1976. }
  1977. #elif HAS_ABL
  1978. if (!forReplay) {
  1979. CONFIG_ECHO_START;
  1980. SERIAL_ECHOLNPGM("Auto Bed Leveling:");
  1981. }
  1982. #endif
  1983. CONFIG_ECHO_START;
  1984. SERIAL_ECHOPAIR(" M420 S", planner.leveling_active ? 1 : 0);
  1985. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1986. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
  1987. #endif
  1988. SERIAL_EOL();
  1989. #if ENABLED(MESH_BED_LEVELING)
  1990. if (leveling_is_valid()) {
  1991. for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
  1992. for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
  1993. CONFIG_ECHO_START;
  1994. SERIAL_ECHOPAIR(" G29 S3 X", (int)px + 1);
  1995. SERIAL_ECHOPAIR(" Y", (int)py + 1);
  1996. SERIAL_ECHOPGM(" Z");
  1997. SERIAL_ECHO_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
  1998. SERIAL_EOL();
  1999. }
  2000. }
  2001. }
  2002. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  2003. if (!forReplay) {
  2004. SERIAL_EOL();
  2005. ubl.report_state();
  2006. SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.storage_slot);
  2007. SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
  2008. SERIAL_ECHOLNPGM(" meshes.\n");
  2009. }
  2010. //ubl.report_current_mesh(PORTVAR_SOLO); // This is too verbose for large mesh's. A better (more terse)
  2011. // solution needs to be found.
  2012. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  2013. if (leveling_is_valid()) {
  2014. for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
  2015. for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
  2016. CONFIG_ECHO_START;
  2017. SERIAL_ECHOPAIR(" G29 W I", (int)px);
  2018. SERIAL_ECHOPAIR(" J", (int)py);
  2019. SERIAL_ECHOPGM(" Z");
  2020. SERIAL_ECHO_F(LINEAR_UNIT(z_values[px][py]), 5);
  2021. SERIAL_EOL();
  2022. }
  2023. }
  2024. }
  2025. #endif
  2026. #endif // HAS_LEVELING
  2027. #if ENABLED(DELTA)
  2028. if (!forReplay) {
  2029. CONFIG_ECHO_START;
  2030. SERIAL_ECHOLNPGM("Endstop adjustment:");
  2031. }
  2032. CONFIG_ECHO_START;
  2033. SERIAL_ECHOPAIR(" M666 X", LINEAR_UNIT(delta_endstop_adj[X_AXIS]));
  2034. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(delta_endstop_adj[Y_AXIS]));
  2035. SERIAL_ECHOLNPAIR(" Z", LINEAR_UNIT(delta_endstop_adj[Z_AXIS]));
  2036. if (!forReplay) {
  2037. CONFIG_ECHO_START;
  2038. SERIAL_ECHOLNPGM("Delta settings: L<diagonal_rod> R<radius> H<height> S<segments_per_s> B<calibration radius> XYZ<tower angle corrections>");
  2039. }
  2040. CONFIG_ECHO_START;
  2041. SERIAL_ECHOPAIR(" M665 L", LINEAR_UNIT(delta_diagonal_rod));
  2042. SERIAL_ECHOPAIR(" R", LINEAR_UNIT(delta_radius));
  2043. SERIAL_ECHOPAIR(" H", LINEAR_UNIT(delta_height));
  2044. SERIAL_ECHOPAIR(" S", delta_segments_per_second);
  2045. SERIAL_ECHOPAIR(" B", LINEAR_UNIT(delta_calibration_radius));
  2046. SERIAL_ECHOPAIR(" X", LINEAR_UNIT(delta_tower_angle_trim[A_AXIS]));
  2047. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(delta_tower_angle_trim[B_AXIS]));
  2048. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(delta_tower_angle_trim[C_AXIS]));
  2049. SERIAL_EOL();
  2050. #elif ENABLED(HANGPRINTER)
  2051. if (!forReplay) {
  2052. CONFIG_ECHO_START;
  2053. SERIAL_ECHOLNPGM("Hangprinter settings: W<Ay> E<Az> R<Bx> T<By> Y<Bz> U<Cx> I<Cy> O<Cz> P<Dz> S<segments_per_s>");
  2054. }
  2055. CONFIG_ECHO_START;
  2056. SERIAL_ECHOPAIR(" M665 W", anchor_A_y);
  2057. SERIAL_ECHOPAIR(" E", anchor_A_z);
  2058. SERIAL_ECHOPAIR(" R", anchor_B_x);
  2059. SERIAL_ECHOPAIR(" T", anchor_B_y);
  2060. SERIAL_ECHOPAIR(" Y", anchor_B_z);
  2061. SERIAL_ECHOPAIR(" U", anchor_C_x);
  2062. SERIAL_ECHOPAIR(" I", anchor_C_y);
  2063. SERIAL_ECHOPAIR(" O", anchor_C_z);
  2064. SERIAL_ECHOPAIR(" P", anchor_D_z);
  2065. SERIAL_ECHOPAIR(" S", delta_segments_per_second);
  2066. SERIAL_EOL();
  2067. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  2068. if (!forReplay) {
  2069. CONFIG_ECHO_START;
  2070. SERIAL_ECHOLNPGM("Endstop adjustment:");
  2071. }
  2072. CONFIG_ECHO_START;
  2073. SERIAL_ECHOPGM(" M666");
  2074. #if ENABLED(X_DUAL_ENDSTOPS)
  2075. SERIAL_ECHOPAIR(" X", LINEAR_UNIT(endstops.x_endstop_adj));
  2076. #endif
  2077. #if ENABLED(Y_DUAL_ENDSTOPS)
  2078. SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(endstops.y_endstop_adj));
  2079. #endif
  2080. #if ENABLED(Z_DUAL_ENDSTOPS)
  2081. SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(endstops.z_endstop_adj));
  2082. #endif
  2083. SERIAL_EOL();
  2084. #endif // [XYZ]_DUAL_ENDSTOPS
  2085. #if ENABLED(ULTIPANEL)
  2086. if (!forReplay) {
  2087. CONFIG_ECHO_START;
  2088. SERIAL_ECHOLNPGM("Material heatup parameters:");
  2089. }
  2090. for (uint8_t i = 0; i < COUNT(lcd_preheat_hotend_temp); i++) {
  2091. CONFIG_ECHO_START;
  2092. SERIAL_ECHOPAIR(" M145 S", (int)i);
  2093. SERIAL_ECHOPAIR(" H", TEMP_UNIT(lcd_preheat_hotend_temp[i]));
  2094. SERIAL_ECHOPAIR(" B", TEMP_UNIT(lcd_preheat_bed_temp[i]));
  2095. SERIAL_ECHOLNPAIR(" F", lcd_preheat_fan_speed[i]);
  2096. }
  2097. #endif // ULTIPANEL
  2098. #if HAS_PID_HEATING
  2099. if (!forReplay) {
  2100. CONFIG_ECHO_START;
  2101. SERIAL_ECHOLNPGM("PID settings:");
  2102. }
  2103. #if ENABLED(PIDTEMP)
  2104. #if HOTENDS > 1
  2105. if (forReplay) {
  2106. HOTEND_LOOP() {
  2107. CONFIG_ECHO_START;
  2108. SERIAL_ECHOPAIR(" M301 E", e);
  2109. SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, e));
  2110. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, e)));
  2111. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, e)));
  2112. #if ENABLED(PID_EXTRUSION_SCALING)
  2113. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, e));
  2114. if (e == 0) SERIAL_ECHOPAIR(" L", thermalManager.lpq_len);
  2115. #endif
  2116. SERIAL_EOL();
  2117. }
  2118. }
  2119. else
  2120. #endif // HOTENDS > 1
  2121. // !forReplay || HOTENDS == 1
  2122. {
  2123. CONFIG_ECHO_START;
  2124. SERIAL_ECHOPAIR(" M301 P", PID_PARAM(Kp, 0)); // for compatibility with hosts, only echo values for E0
  2125. SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, 0)));
  2126. SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
  2127. #if ENABLED(PID_EXTRUSION_SCALING)
  2128. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, 0));
  2129. SERIAL_ECHOPAIR(" L", thermalManager.lpq_len);
  2130. #endif
  2131. SERIAL_EOL();
  2132. }
  2133. #endif // PIDTEMP
  2134. #if ENABLED(PIDTEMPBED)
  2135. CONFIG_ECHO_START;
  2136. SERIAL_ECHOPAIR(" M304 P", thermalManager.bedKp);
  2137. SERIAL_ECHOPAIR(" I", unscalePID_i(thermalManager.bedKi));
  2138. SERIAL_ECHOPAIR(" D", unscalePID_d(thermalManager.bedKd));
  2139. SERIAL_EOL();
  2140. #endif
  2141. #endif // PIDTEMP || PIDTEMPBED
  2142. #if HAS_LCD_CONTRAST
  2143. if (!forReplay) {
  2144. CONFIG_ECHO_START;
  2145. SERIAL_ECHOLNPGM("LCD Contrast:");
  2146. }
  2147. CONFIG_ECHO_START;
  2148. SERIAL_ECHOLNPAIR(" M250 C", lcd_contrast);
  2149. #endif
  2150. #if ENABLED(FWRETRACT)
  2151. if (!forReplay) {
  2152. CONFIG_ECHO_START;
  2153. SERIAL_ECHOLNPGM("Retract: S<length> F<units/m> Z<lift>");
  2154. }
  2155. CONFIG_ECHO_START;
  2156. SERIAL_ECHOPAIR(" M207 S", LINEAR_UNIT(fwretract.retract_length));
  2157. SERIAL_ECHOPAIR(" W", LINEAR_UNIT(fwretract.swap_retract_length));
  2158. SERIAL_ECHOPAIR(" F", MMS_TO_MMM(LINEAR_UNIT(fwretract.retract_feedrate_mm_s)));
  2159. SERIAL_ECHOLNPAIR(" Z", LINEAR_UNIT(fwretract.retract_zlift));
  2160. if (!forReplay) {
  2161. CONFIG_ECHO_START;
  2162. SERIAL_ECHOLNPGM("Recover: S<length> F<units/m>");
  2163. }
  2164. CONFIG_ECHO_START;
  2165. SERIAL_ECHOPAIR(" M208 S", LINEAR_UNIT(fwretract.retract_recover_length));
  2166. SERIAL_ECHOPAIR(" W", LINEAR_UNIT(fwretract.swap_retract_recover_length));
  2167. SERIAL_ECHOLNPAIR(" F", MMS_TO_MMM(LINEAR_UNIT(fwretract.retract_recover_feedrate_mm_s)));
  2168. if (!forReplay) {
  2169. CONFIG_ECHO_START;
  2170. SERIAL_ECHOLNPGM("Auto-Retract: S=0 to disable, 1 to interpret E-only moves as retract/recover");
  2171. }
  2172. CONFIG_ECHO_START;
  2173. SERIAL_ECHOLNPAIR(" M209 S", fwretract.autoretract_enabled ? 1 : 0);
  2174. #endif // FWRETRACT
  2175. /**
  2176. * Probe Offset
  2177. */
  2178. #if HAS_BED_PROBE
  2179. if (!forReplay) {
  2180. CONFIG_ECHO_START;
  2181. SERIAL_ECHOPGM("Z-Probe Offset");
  2182. say_units(true);
  2183. }
  2184. CONFIG_ECHO_START;
  2185. SERIAL_ECHOLNPAIR(" M851 Z", LINEAR_UNIT(zprobe_zoffset));
  2186. #endif
  2187. /**
  2188. * Bed Skew Correction
  2189. */
  2190. #if ENABLED(SKEW_CORRECTION_GCODE)
  2191. if (!forReplay) {
  2192. CONFIG_ECHO_START;
  2193. SERIAL_ECHOLNPGM("Skew Factor: ");
  2194. }
  2195. CONFIG_ECHO_START;
  2196. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  2197. SERIAL_ECHOPGM(" M852 I");
  2198. SERIAL_ECHO_F(LINEAR_UNIT(planner.xy_skew_factor), 6);
  2199. SERIAL_ECHOPGM(" J");
  2200. SERIAL_ECHO_F(LINEAR_UNIT(planner.xz_skew_factor), 6);
  2201. SERIAL_ECHOPGM(" K");
  2202. SERIAL_ECHO_F(LINEAR_UNIT(planner.yz_skew_factor), 6);
  2203. SERIAL_EOL();
  2204. #else
  2205. SERIAL_ECHOPGM(" M852 S");
  2206. SERIAL_ECHO_F(LINEAR_UNIT(planner.xy_skew_factor), 6);
  2207. SERIAL_EOL();
  2208. #endif
  2209. #endif
  2210. #if HAS_TRINAMIC
  2211. /**
  2212. * TMC2130 / TMC2208 stepper driver current
  2213. */
  2214. if (!forReplay) {
  2215. CONFIG_ECHO_START;
  2216. SERIAL_ECHOLNPGM("Stepper driver current:");
  2217. }
  2218. CONFIG_ECHO_START;
  2219. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
  2220. say_M906();
  2221. #endif
  2222. #if AXIS_IS_TMC(X)
  2223. SERIAL_ECHOPAIR(" X", stepperX.getCurrent());
  2224. #endif
  2225. #if AXIS_IS_TMC(Y)
  2226. SERIAL_ECHOPAIR(" Y", stepperY.getCurrent());
  2227. #endif
  2228. #if AXIS_IS_TMC(Z)
  2229. SERIAL_ECHOPAIR(" Z", stepperZ.getCurrent());
  2230. #endif
  2231. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
  2232. SERIAL_EOL();
  2233. #endif
  2234. #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
  2235. say_M906();
  2236. SERIAL_ECHOPGM(" I1");
  2237. #endif
  2238. #if AXIS_IS_TMC(X2)
  2239. SERIAL_ECHOPAIR(" X", stepperX2.getCurrent());
  2240. #endif
  2241. #if AXIS_IS_TMC(Y2)
  2242. SERIAL_ECHOPAIR(" Y", stepperY2.getCurrent());
  2243. #endif
  2244. #if AXIS_IS_TMC(Z2)
  2245. SERIAL_ECHOPAIR(" Z", stepperZ2.getCurrent());
  2246. #endif
  2247. #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
  2248. SERIAL_EOL();
  2249. #endif
  2250. #if AXIS_IS_TMC(E0)
  2251. say_M906();
  2252. SERIAL_ECHOLNPAIR(" T0 E", stepperE0.getCurrent());
  2253. #endif
  2254. #if E_STEPPERS > 1 && AXIS_IS_TMC(E1)
  2255. say_M906();
  2256. SERIAL_ECHOLNPAIR(" T1 E", stepperE1.getCurrent());
  2257. #endif
  2258. #if E_STEPPERS > 2 && AXIS_IS_TMC(E2)
  2259. say_M906();
  2260. SERIAL_ECHOLNPAIR(" T2 E", stepperE2.getCurrent());
  2261. #endif
  2262. #if E_STEPPERS > 3 && AXIS_IS_TMC(E3)
  2263. say_M906();
  2264. SERIAL_ECHOLNPAIR(" T3 E", stepperE3.getCurrent());
  2265. #endif
  2266. #if E_STEPPERS > 4 && AXIS_IS_TMC(E4)
  2267. say_M906();
  2268. SERIAL_ECHOLNPAIR(" T4 E", stepperE4.getCurrent());
  2269. #endif
  2270. SERIAL_EOL();
  2271. /**
  2272. * TMC2130 / TMC2208 / TRAMS Hybrid Threshold
  2273. */
  2274. #if ENABLED(HYBRID_THRESHOLD)
  2275. if (!forReplay) {
  2276. CONFIG_ECHO_START;
  2277. SERIAL_ECHOLNPGM("Hybrid Threshold:");
  2278. }
  2279. CONFIG_ECHO_START;
  2280. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
  2281. say_M913();
  2282. #endif
  2283. #if AXIS_IS_TMC(X)
  2284. SERIAL_ECHOPAIR(" X", TMC_GET_PWMTHRS(X, X));
  2285. #endif
  2286. #if AXIS_IS_TMC(Y)
  2287. SERIAL_ECHOPAIR(" Y", TMC_GET_PWMTHRS(Y, Y));
  2288. #endif
  2289. #if AXIS_IS_TMC(Z)
  2290. SERIAL_ECHOPAIR(" Z", TMC_GET_PWMTHRS(Z, Z));
  2291. #endif
  2292. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
  2293. SERIAL_EOL();
  2294. #endif
  2295. #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
  2296. say_M913();
  2297. SERIAL_ECHOPGM(" I1");
  2298. #endif
  2299. #if AXIS_IS_TMC(X2)
  2300. SERIAL_ECHOPAIR(" X", TMC_GET_PWMTHRS(X, X2));
  2301. #endif
  2302. #if AXIS_IS_TMC(Y2)
  2303. SERIAL_ECHOPAIR(" Y", TMC_GET_PWMTHRS(Y, Y2));
  2304. #endif
  2305. #if AXIS_IS_TMC(Z2)
  2306. SERIAL_ECHOPAIR(" Z", TMC_GET_PWMTHRS(Z, Z2));
  2307. #endif
  2308. #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
  2309. SERIAL_EOL();
  2310. #endif
  2311. #if AXIS_IS_TMC(E0)
  2312. say_M913();
  2313. SERIAL_ECHOLNPAIR(" T0 E", TMC_GET_PWMTHRS(E, E0));
  2314. #endif
  2315. #if E_STEPPERS > 1 && AXIS_IS_TMC(E1)
  2316. say_M913();
  2317. SERIAL_ECHOLNPAIR(" T1 E", TMC_GET_PWMTHRS(E, E1));
  2318. #endif
  2319. #if E_STEPPERS > 2 && AXIS_IS_TMC(E2)
  2320. say_M913();
  2321. SERIAL_ECHOLNPAIR(" T2 E", TMC_GET_PWMTHRS(E, E2));
  2322. #endif
  2323. #if E_STEPPERS > 3 && AXIS_IS_TMC(E3)
  2324. say_M913();
  2325. SERIAL_ECHOLNPAIR(" T3 E", TMC_GET_PWMTHRS(E, E3));
  2326. #endif
  2327. #if E_STEPPERS > 4 && AXIS_IS_TMC(E4)
  2328. say_M913();
  2329. SERIAL_ECHOLNPAIR(" T4 E", TMC_GET_PWMTHRS(E, E4));
  2330. #endif
  2331. SERIAL_EOL();
  2332. #endif // HYBRID_THRESHOLD
  2333. /**
  2334. * TMC2130 Sensorless homing thresholds
  2335. */
  2336. #if ENABLED(SENSORLESS_HOMING)
  2337. if (!forReplay) {
  2338. CONFIG_ECHO_START;
  2339. SERIAL_ECHOLNPGM("Sensorless homing threshold:");
  2340. }
  2341. CONFIG_ECHO_START;
  2342. #if X_SENSORLESS || Y_SENSORLESS || Z_SENSORLESS
  2343. say_M914();
  2344. #if X_SENSORLESS
  2345. SERIAL_ECHOPAIR(" X", stepperX.sgt());
  2346. #endif
  2347. #if Y_SENSORLESS
  2348. SERIAL_ECHOPAIR(" Y", stepperY.sgt());
  2349. #endif
  2350. #if Z_SENSORLESS
  2351. SERIAL_ECHOPAIR(" Z", stepperZ.sgt());
  2352. #endif
  2353. SERIAL_EOL();
  2354. #endif
  2355. #define X2_SENSORLESS (defined(X_HOMING_SENSITIVITY) && AXIS_HAS_STALLGUARD(X2))
  2356. #define Y2_SENSORLESS (defined(Y_HOMING_SENSITIVITY) && AXIS_HAS_STALLGUARD(Y2))
  2357. #define Z2_SENSORLESS (defined(Z_HOMING_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z2))
  2358. #if X2_SENSORLESS || Y2_SENSORLESS || Z2_SENSORLESS
  2359. say_M914();
  2360. SERIAL_ECHOPGM(" I1");
  2361. #if X2_SENSORLESS
  2362. SERIAL_ECHOPAIR(" X", stepperX2.sgt());
  2363. #endif
  2364. #if Y2_SENSORLESS
  2365. SERIAL_ECHOPAIR(" Y", stepperY2.sgt());
  2366. #endif
  2367. #if Z2_SENSORLESS
  2368. SERIAL_ECHOPAIR(" Z", stepperZ2.sgt());
  2369. #endif
  2370. SERIAL_EOL();
  2371. #endif
  2372. #endif // SENSORLESS_HOMING
  2373. #endif // HAS_TRINAMIC
  2374. /**
  2375. * Linear Advance
  2376. */
  2377. #if ENABLED(LIN_ADVANCE)
  2378. if (!forReplay) {
  2379. CONFIG_ECHO_START;
  2380. SERIAL_ECHOLNPGM("Linear Advance:");
  2381. }
  2382. CONFIG_ECHO_START;
  2383. SERIAL_ECHOLNPAIR(" M900 K", planner.extruder_advance_K);
  2384. #endif
  2385. #if HAS_MOTOR_CURRENT_PWM
  2386. CONFIG_ECHO_START;
  2387. if (!forReplay) {
  2388. SERIAL_ECHOLNPGM("Stepper motor currents:");
  2389. CONFIG_ECHO_START;
  2390. }
  2391. SERIAL_ECHOPAIR(" M907 X", stepper.motor_current_setting[0]);
  2392. SERIAL_ECHOPAIR(" Z", stepper.motor_current_setting[1]);
  2393. SERIAL_ECHOPAIR(" E", stepper.motor_current_setting[2]);
  2394. SERIAL_EOL();
  2395. #endif
  2396. /**
  2397. * Advanced Pause filament load & unload lengths
  2398. */
  2399. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2400. if (!forReplay) {
  2401. CONFIG_ECHO_START;
  2402. SERIAL_ECHOLNPGM("Filament load/unload lengths:");
  2403. }
  2404. CONFIG_ECHO_START;
  2405. #if EXTRUDERS == 1
  2406. say_M603();
  2407. SERIAL_ECHOPAIR("L", LINEAR_UNIT(filament_change_load_length[0]));
  2408. SERIAL_ECHOLNPAIR(" U", LINEAR_UNIT(filament_change_unload_length[0]));
  2409. #else
  2410. say_M603();
  2411. SERIAL_ECHOPAIR("T0 L", LINEAR_UNIT(filament_change_load_length[0]));
  2412. SERIAL_ECHOLNPAIR(" U", LINEAR_UNIT(filament_change_unload_length[0]));
  2413. CONFIG_ECHO_START;
  2414. say_M603();
  2415. SERIAL_ECHOPAIR("T1 L", LINEAR_UNIT(filament_change_load_length[1]));
  2416. SERIAL_ECHOLNPAIR(" U", LINEAR_UNIT(filament_change_unload_length[1]));
  2417. #if EXTRUDERS > 2
  2418. CONFIG_ECHO_START;
  2419. say_M603();
  2420. SERIAL_ECHOPAIR("T2 L", LINEAR_UNIT(filament_change_load_length[2]));
  2421. SERIAL_ECHOLNPAIR(" U", LINEAR_UNIT(filament_change_unload_length[2]));
  2422. #if EXTRUDERS > 3
  2423. CONFIG_ECHO_START;
  2424. say_M603();
  2425. SERIAL_ECHOPAIR("T3 L", LINEAR_UNIT(filament_change_load_length[3]));
  2426. SERIAL_ECHOLNPAIR(" U", LINEAR_UNIT(filament_change_unload_length[3]));
  2427. #if EXTRUDERS > 4
  2428. CONFIG_ECHO_START;
  2429. say_M603();
  2430. SERIAL_ECHOPAIR("T4 L", LINEAR_UNIT(filament_change_load_length[4]));
  2431. SERIAL_ECHOLNPAIR(" U", LINEAR_UNIT(filament_change_unload_length[4]));
  2432. #endif // EXTRUDERS > 4
  2433. #endif // EXTRUDERS > 3
  2434. #endif // EXTRUDERS > 2
  2435. #endif // EXTRUDERS == 1
  2436. #endif // ADVANCED_PAUSE_FEATURE
  2437. }
  2438. #endif // !DISABLE_M503