configuration_store.cpp 84 KB

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