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

configuration_store.cpp 109KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 "V80"
  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 "endstops.h"
  45. #include "planner.h"
  46. #include "stepper.h"
  47. #include "temperature.h"
  48. #if ENABLED(DWIN_CREALITY_LCD)
  49. #include "../lcd/dwin/dwin.h"
  50. #endif
  51. #include "../lcd/ultralcd.h"
  52. #include "../libs/vector_3.h" // for matrix_3x3
  53. #include "../gcode/gcode.h"
  54. #include "../MarlinCore.h"
  55. #if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
  56. #include "../HAL/shared/eeprom_api.h"
  57. #endif
  58. #include "probe.h"
  59. #if HAS_LEVELING
  60. #include "../feature/bedlevel/bedlevel.h"
  61. #endif
  62. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  63. #include "../feature/z_stepper_align.h"
  64. #endif
  65. #if ENABLED(EXTENSIBLE_UI)
  66. #include "../lcd/extui/ui_api.h"
  67. #endif
  68. #if HAS_SERVOS
  69. #include "servo.h"
  70. #endif
  71. #if HAS_SERVOS && HAS_SERVO_ANGLES
  72. #define EEPROM_NUM_SERVOS NUM_SERVOS
  73. #else
  74. #define EEPROM_NUM_SERVOS NUM_SERVO_PLUGS
  75. #endif
  76. #include "../feature/fwretract.h"
  77. #if ENABLED(POWER_LOSS_RECOVERY)
  78. #include "../feature/powerloss.h"
  79. #endif
  80. #if ENABLED(POWER_MONITOR)
  81. #include "../feature/power_monitor.h"
  82. #endif
  83. #include "../feature/pause.h"
  84. #if ENABLED(BACKLASH_COMPENSATION)
  85. #include "../feature/backlash.h"
  86. #endif
  87. #if HAS_FILAMENT_SENSOR
  88. #include "../feature/runout.h"
  89. #endif
  90. #if ENABLED(EXTRA_LIN_ADVANCE_K)
  91. extern float other_extruder_advance_K[EXTRUDERS];
  92. #endif
  93. #if EXTRUDERS > 1
  94. #include "tool_change.h"
  95. void M217_report(const bool eeprom);
  96. #endif
  97. #if ENABLED(BLTOUCH)
  98. #include "../feature/bltouch.h"
  99. #endif
  100. #if HAS_TRINAMIC_CONFIG
  101. #include "stepper/indirection.h"
  102. #include "../feature/tmc_util.h"
  103. #endif
  104. #if ENABLED(PROBE_TEMP_COMPENSATION)
  105. #include "../feature/probe_temp_comp.h"
  106. #endif
  107. #include "../feature/controllerfan.h"
  108. #if ENABLED(CONTROLLER_FAN_EDITABLE)
  109. void M710_report(const bool forReplay);
  110. #endif
  111. #if ENABLED(CASE_LIGHT_MENU) && DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  112. #include "../feature/caselight.h"
  113. #define HAS_CASE_LIGHT_BRIGHTNESS 1
  114. #endif
  115. #pragma pack(push, 1) // No padding between variables
  116. typedef struct { uint16_t X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7; } tmc_stepper_current_t;
  117. typedef struct { uint32_t X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7; } tmc_hybrid_threshold_t;
  118. typedef struct { int16_t X, Y, Z, X2, Y2, Z2, Z3, Z4; } tmc_sgt_t;
  119. typedef struct { bool X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7; } tmc_stealth_enabled_t;
  120. // Limit an index to an array size
  121. #define ALIM(I,ARR) _MIN(I, COUNT(ARR) - 1)
  122. // Defaults for reset / fill in on load
  123. static const uint32_t _DMA[] PROGMEM = DEFAULT_MAX_ACCELERATION;
  124. static const float _DASU[] PROGMEM = DEFAULT_AXIS_STEPS_PER_UNIT;
  125. static const feedRate_t _DMF[] PROGMEM = DEFAULT_MAX_FEEDRATE;
  126. extern const char SP_X_STR[], SP_Y_STR[], SP_Z_STR[], SP_E_STR[];
  127. /**
  128. * Current EEPROM Layout
  129. *
  130. * Keep this data structure up to date so
  131. * EEPROM size is known at compile time!
  132. */
  133. typedef struct SettingsDataStruct {
  134. char version[4]; // Vnn\0
  135. uint16_t crc; // Data Checksum
  136. //
  137. // DISTINCT_E_FACTORS
  138. //
  139. uint8_t esteppers; // XYZE_N - XYZ
  140. planner_settings_t planner_settings;
  141. xyze_float_t planner_max_jerk; // M205 XYZE planner.max_jerk
  142. float planner_junction_deviation_mm; // M205 J planner.junction_deviation_mm
  143. xyz_pos_t home_offset; // M206 XYZ / M665 TPZ
  144. #if HAS_HOTEND_OFFSET
  145. xyz_pos_t hotend_offset[HOTENDS - 1]; // M218 XYZ
  146. #endif
  147. //
  148. // FILAMENT_RUNOUT_SENSOR
  149. //
  150. bool runout_sensor_enabled; // M412 S
  151. float runout_distance_mm; // M412 D
  152. //
  153. // ENABLE_LEVELING_FADE_HEIGHT
  154. //
  155. float planner_z_fade_height; // M420 Zn planner.z_fade_height
  156. //
  157. // MESH_BED_LEVELING
  158. //
  159. float mbl_z_offset; // mbl.z_offset
  160. uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
  161. float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)] // mbl.z_values
  162. [TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)];
  163. //
  164. // HAS_BED_PROBE
  165. //
  166. xyz_pos_t probe_offset;
  167. //
  168. // ABL_PLANAR
  169. //
  170. matrix_3x3 planner_bed_level_matrix; // planner.bed_level_matrix
  171. //
  172. // AUTO_BED_LEVELING_BILINEAR
  173. //
  174. uint8_t grid_max_x, grid_max_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
  175. xy_pos_t bilinear_grid_spacing, bilinear_start; // G29 L F
  176. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  177. bed_mesh_t z_values; // G29
  178. #else
  179. float z_values[3][3];
  180. #endif
  181. //
  182. // AUTO_BED_LEVELING_UBL
  183. //
  184. bool planner_leveling_active; // M420 S planner.leveling_active
  185. int8_t ubl_storage_slot; // ubl.storage_slot
  186. //
  187. // SERVO_ANGLES
  188. //
  189. uint16_t servo_angles[EEPROM_NUM_SERVOS][2]; // M281 P L U
  190. //
  191. // Temperature first layer compensation values
  192. //
  193. #if ENABLED(PROBE_TEMP_COMPENSATION)
  194. int16_t z_offsets_probe[COUNT(temp_comp.z_offsets_probe)], // M871 P I V
  195. z_offsets_bed[COUNT(temp_comp.z_offsets_bed)] // M871 B I V
  196. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  197. , z_offsets_ext[COUNT(temp_comp.z_offsets_ext)] // M871 E I V
  198. #endif
  199. ;
  200. #endif
  201. //
  202. // BLTOUCH
  203. //
  204. bool bltouch_last_written_mode;
  205. //
  206. // DELTA / [XYZ]_DUAL_ENDSTOPS
  207. //
  208. #if ENABLED(DELTA)
  209. float delta_height; // M666 H
  210. abc_float_t delta_endstop_adj; // M666 XYZ
  211. float delta_radius, // M665 R
  212. delta_diagonal_rod, // M665 L
  213. delta_segments_per_second; // M665 S
  214. abc_float_t delta_tower_angle_trim; // M665 XYZ
  215. #elif HAS_EXTRA_ENDSTOPS
  216. float x2_endstop_adj, // M666 X
  217. y2_endstop_adj, // M666 Y
  218. z2_endstop_adj, // M666 (S2) Z
  219. z3_endstop_adj, // M666 (S3) Z
  220. z4_endstop_adj; // M666 (S4) Z
  221. #endif
  222. //
  223. // Z_STEPPER_AUTO_ALIGN, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS
  224. //
  225. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  226. xy_pos_t z_stepper_align_xy[NUM_Z_STEPPER_DRIVERS]; // M422 S X Y
  227. #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
  228. xy_pos_t z_stepper_align_stepper_xy[NUM_Z_STEPPER_DRIVERS]; // M422 W X Y
  229. #endif
  230. #endif
  231. //
  232. // ULTIPANEL
  233. //
  234. int16_t ui_preheat_hotend_temp[2], // M145 S0 H
  235. ui_preheat_bed_temp[2]; // M145 S0 B
  236. uint8_t ui_preheat_fan_speed[2]; // M145 S0 F
  237. //
  238. // PIDTEMP
  239. //
  240. PIDCF_t hotendPID[HOTENDS]; // M301 En PIDCF / M303 En U
  241. int16_t lpq_len; // M301 L
  242. //
  243. // PIDTEMPBED
  244. //
  245. PID_t bedPID; // M304 PID / M303 E-1 U
  246. //
  247. // User-defined Thermistors
  248. //
  249. #if HAS_USER_THERMISTORS
  250. user_thermistor_t user_thermistor[USER_THERMISTORS]; // M305 P0 R4700 T100000 B3950
  251. #endif
  252. //
  253. // Power monitor
  254. //
  255. uint8_t power_monitor_flags; // M430 I V W
  256. //
  257. // HAS_LCD_CONTRAST
  258. //
  259. int16_t lcd_contrast; // M250 C
  260. //
  261. // Controller fan settings
  262. //
  263. controllerFan_settings_t controllerFan_settings; // M710
  264. //
  265. // POWER_LOSS_RECOVERY
  266. //
  267. bool recovery_enabled; // M413 S
  268. //
  269. // FWRETRACT
  270. //
  271. fwretract_settings_t fwretract_settings; // M207 S F Z W, M208 S F W R
  272. bool autoretract_enabled; // M209 S
  273. //
  274. // !NO_VOLUMETRIC
  275. //
  276. bool parser_volumetric_enabled; // M200 S parser.volumetric_enabled
  277. float planner_filament_size[EXTRUDERS]; // M200 T D planner.filament_size[]
  278. float planner_volumetric_extruder_limit[EXTRUDERS]; // M200 T L planner.volumetric_extruder_limit[]
  279. //
  280. // HAS_TRINAMIC_CONFIG
  281. //
  282. tmc_stepper_current_t tmc_stepper_current; // M906 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
  283. tmc_hybrid_threshold_t tmc_hybrid_threshold; // M913 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
  284. tmc_sgt_t tmc_sgt; // M914 X Y Z X2 Y2 Z2 Z3 Z4
  285. tmc_stealth_enabled_t tmc_stealth_enabled; // M569 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
  286. //
  287. // LIN_ADVANCE
  288. //
  289. float planner_extruder_advance_K[_MAX(EXTRUDERS, 1)]; // M900 K planner.extruder_advance_K
  290. //
  291. // HAS_MOTOR_CURRENT_PWM
  292. //
  293. uint32_t motor_current_setting[3]; // M907 X Z E
  294. //
  295. // CNC_COORDINATE_SYSTEMS
  296. //
  297. xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS]; // G54-G59.3
  298. //
  299. // SKEW_CORRECTION
  300. //
  301. skew_factor_t planner_skew_factor; // M852 I J K planner.skew_factor
  302. //
  303. // ADVANCED_PAUSE_FEATURE
  304. //
  305. #if EXTRUDERS
  306. fil_change_settings_t fc_settings[EXTRUDERS]; // M603 T U L
  307. #endif
  308. //
  309. // Tool-change settings
  310. //
  311. #if EXTRUDERS > 1
  312. toolchange_settings_t toolchange_settings; // M217 S P R
  313. #endif
  314. //
  315. // BACKLASH_COMPENSATION
  316. //
  317. xyz_float_t backlash_distance_mm; // M425 X Y Z
  318. uint8_t backlash_correction; // M425 F
  319. float backlash_smoothing_mm; // M425 S
  320. //
  321. // EXTENSIBLE_UI
  322. //
  323. #if ENABLED(EXTENSIBLE_UI)
  324. // This is a significant hardware change; don't reserve space when not present
  325. uint8_t extui_data[ExtUI::eeprom_data_size];
  326. #endif
  327. //
  328. // HAS_CASE_LIGHT_BRIGHTNESS
  329. //
  330. #if HAS_CASE_LIGHT_BRIGHTNESS
  331. uint8_t case_light_brightness;
  332. #endif
  333. } SettingsData;
  334. //static_assert(sizeof(SettingsData) <= MARLIN_EEPROM_SIZE, "EEPROM too small to contain SettingsData!");
  335. MarlinSettings settings;
  336. uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); }
  337. /**
  338. * Post-process after Retrieve or Reset
  339. */
  340. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  341. float new_z_fade_height;
  342. #endif
  343. void MarlinSettings::postprocess() {
  344. xyze_pos_t oldpos = current_position;
  345. // steps per s2 needs to be updated to agree with units per s2
  346. planner.reset_acceleration_rates();
  347. // Make sure delta kinematics are updated before refreshing the
  348. // planner position so the stepper counts will be set correctly.
  349. TERN_(DELTA, recalc_delta_settings());
  350. TERN_(PIDTEMP, thermalManager.updatePID());
  351. #if DISABLED(NO_VOLUMETRICS)
  352. planner.calculate_volumetric_multipliers();
  353. #elif EXTRUDERS
  354. for (uint8_t i = COUNT(planner.e_factor); i--;)
  355. planner.refresh_e_factor(i);
  356. #endif
  357. // Software endstops depend on home_offset
  358. LOOP_XYZ(i) {
  359. update_workspace_offset((AxisEnum)i);
  360. update_software_endstops((AxisEnum)i);
  361. }
  362. TERN_(ENABLE_LEVELING_FADE_HEIGHT, set_z_fade_height(new_z_fade_height, false)); // false = no report
  363. TERN_(AUTO_BED_LEVELING_BILINEAR, refresh_bed_level());
  364. TERN_(HAS_MOTOR_CURRENT_PWM, stepper.refresh_motor_power());
  365. TERN_(FWRETRACT, fwretract.refresh_autoretract());
  366. TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk());
  367. TERN_(HAS_CASE_LIGHT_BRIGHTNESS, update_case_light());
  368. // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
  369. // and init stepper.count[], planner.position[] with current_position
  370. planner.refresh_positioning();
  371. // Various factors can change the current position
  372. if (oldpos != current_position)
  373. report_current_position();
  374. }
  375. #if BOTH(PRINTCOUNTER, EEPROM_SETTINGS)
  376. #include "printcounter.h"
  377. static_assert(
  378. !WITHIN(STATS_EEPROM_ADDRESS, EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)) &&
  379. !WITHIN(STATS_EEPROM_ADDRESS + sizeof(printStatistics), EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)),
  380. "STATS_EEPROM_ADDRESS collides with EEPROM settings storage."
  381. );
  382. #endif
  383. #if ENABLED(SD_FIRMWARE_UPDATE)
  384. #if ENABLED(EEPROM_SETTINGS)
  385. static_assert(
  386. !WITHIN(SD_FIRMWARE_UPDATE_EEPROM_ADDR, EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)),
  387. "SD_FIRMWARE_UPDATE_EEPROM_ADDR collides with EEPROM settings storage."
  388. );
  389. #endif
  390. bool MarlinSettings::sd_update_status() {
  391. uint8_t val;
  392. persistentStore.read_data(SD_FIRMWARE_UPDATE_EEPROM_ADDR, &val);
  393. return (val == SD_FIRMWARE_UPDATE_ACTIVE_VALUE);
  394. }
  395. bool MarlinSettings::set_sd_update_status(const bool enable) {
  396. if (enable != sd_update_status())
  397. persistentStore.write_data(
  398. SD_FIRMWARE_UPDATE_EEPROM_ADDR,
  399. enable ? SD_FIRMWARE_UPDATE_ACTIVE_VALUE : SD_FIRMWARE_UPDATE_INACTIVE_VALUE
  400. );
  401. return true;
  402. }
  403. #endif // SD_FIRMWARE_UPDATE
  404. #ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE
  405. static_assert(
  406. EEPROM_OFFSET + sizeof(SettingsData) < ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE,
  407. "ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE is insufficient to capture all EEPROM data."
  408. );
  409. #endif
  410. #define DEBUG_OUT ENABLED(EEPROM_CHITCHAT)
  411. #include "../core/debug_out.h"
  412. #if ENABLED(EEPROM_SETTINGS)
  413. #define EEPROM_START() if (!persistentStore.access_start()) { SERIAL_ECHO_MSG("No EEPROM."); return false; } \
  414. int eeprom_index = EEPROM_OFFSET
  415. #define EEPROM_FINISH() persistentStore.access_finish()
  416. #define EEPROM_SKIP(VAR) (eeprom_index += sizeof(VAR))
  417. #define EEPROM_WRITE(VAR) do{ persistentStore.write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc); }while(0)
  418. #define EEPROM_READ(VAR) do{ persistentStore.read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, !validating); }while(0)
  419. #define EEPROM_READ_ALWAYS(VAR) do{ persistentStore.read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc); }while(0)
  420. #define EEPROM_ASSERT(TST,ERR) do{ if (!(TST)) { SERIAL_ERROR_MSG(ERR); eeprom_error = true; } }while(0)
  421. #if ENABLED(DEBUG_EEPROM_READWRITE)
  422. #define _FIELD_TEST(FIELD) \
  423. EEPROM_ASSERT( \
  424. eeprom_error || eeprom_index == offsetof(SettingsData, FIELD) + EEPROM_OFFSET, \
  425. "Field " STRINGIFY(FIELD) " mismatch." \
  426. )
  427. #else
  428. #define _FIELD_TEST(FIELD) NOOP
  429. #endif
  430. const char version[4] = EEPROM_VERSION;
  431. bool MarlinSettings::eeprom_error, MarlinSettings::validating;
  432. bool MarlinSettings::size_error(const uint16_t size) {
  433. if (size != datasize()) {
  434. DEBUG_ERROR_MSG("EEPROM datasize error.");
  435. return true;
  436. }
  437. return false;
  438. }
  439. /**
  440. * M500 - Store Configuration
  441. */
  442. bool MarlinSettings::save() {
  443. float dummyf = 0;
  444. char ver[4] = "ERR";
  445. uint16_t working_crc = 0;
  446. EEPROM_START();
  447. eeprom_error = false;
  448. // Write or Skip version. (Flash doesn't allow rewrite without erase.)
  449. TERN(FLASH_EEPROM_EMULATION, EEPROM_SKIP, EEPROM_WRITE)(ver);
  450. EEPROM_SKIP(working_crc); // Skip the checksum slot
  451. working_crc = 0; // clear before first "real data"
  452. _FIELD_TEST(esteppers);
  453. const uint8_t esteppers = COUNT(planner.settings.axis_steps_per_mm) - XYZ;
  454. EEPROM_WRITE(esteppers);
  455. //
  456. // Planner Motion
  457. //
  458. {
  459. EEPROM_WRITE(planner.settings);
  460. #if HAS_CLASSIC_JERK
  461. EEPROM_WRITE(planner.max_jerk);
  462. #if HAS_LINEAR_E_JERK
  463. dummyf = float(DEFAULT_EJERK);
  464. EEPROM_WRITE(dummyf);
  465. #endif
  466. #else
  467. const xyze_pos_t planner_max_jerk = { 10, 10, 0.4, float(DEFAULT_EJERK) };
  468. EEPROM_WRITE(planner_max_jerk);
  469. #endif
  470. TERN_(CLASSIC_JERK, dummyf = 0.02f);
  471. EEPROM_WRITE(TERN(CLASSIC_JERK, dummyf, planner.junction_deviation_mm));
  472. }
  473. //
  474. // Home Offset
  475. //
  476. {
  477. _FIELD_TEST(home_offset);
  478. #if HAS_SCARA_OFFSET
  479. EEPROM_WRITE(scara_home_offset);
  480. #else
  481. #if !HAS_HOME_OFFSET
  482. const xyz_pos_t home_offset{0};
  483. #endif
  484. EEPROM_WRITE(home_offset);
  485. #endif
  486. #if HAS_HOTEND_OFFSET
  487. // Skip hotend 0 which must be 0
  488. LOOP_S_L_N(e, 1, HOTENDS)
  489. EEPROM_WRITE(hotend_offset[e]);
  490. #endif
  491. }
  492. //
  493. // Filament Runout Sensor
  494. //
  495. {
  496. #if HAS_FILAMENT_SENSOR
  497. const bool &runout_sensor_enabled = runout.enabled;
  498. #else
  499. constexpr bool runout_sensor_enabled = true;
  500. #endif
  501. #if HAS_FILAMENT_RUNOUT_DISTANCE
  502. const float &runout_distance_mm = runout.runout_distance();
  503. #else
  504. constexpr float runout_distance_mm = 0;
  505. #endif
  506. _FIELD_TEST(runout_sensor_enabled);
  507. EEPROM_WRITE(runout_sensor_enabled);
  508. EEPROM_WRITE(runout_distance_mm);
  509. }
  510. //
  511. // Global Leveling
  512. //
  513. {
  514. const float zfh = TERN(ENABLE_LEVELING_FADE_HEIGHT, planner.z_fade_height, 10.0f);
  515. EEPROM_WRITE(zfh);
  516. }
  517. //
  518. // Mesh Bed Leveling
  519. //
  520. {
  521. #if ENABLED(MESH_BED_LEVELING)
  522. static_assert(
  523. sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]),
  524. "MBL Z array is the wrong size."
  525. );
  526. #else
  527. dummyf = 0;
  528. #endif
  529. const uint8_t mesh_num_x = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3),
  530. mesh_num_y = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3);
  531. EEPROM_WRITE(TERN(MESH_BED_LEVELING, mbl.z_offset, dummyf));
  532. EEPROM_WRITE(mesh_num_x);
  533. EEPROM_WRITE(mesh_num_y);
  534. #if ENABLED(MESH_BED_LEVELING)
  535. EEPROM_WRITE(mbl.z_values);
  536. #else
  537. for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummyf);
  538. #endif
  539. }
  540. //
  541. // Probe XYZ Offsets
  542. //
  543. {
  544. _FIELD_TEST(probe_offset);
  545. #if HAS_BED_PROBE
  546. const xyz_pos_t &zpo = probe.offset;
  547. #else
  548. constexpr xyz_pos_t zpo{0};
  549. #endif
  550. EEPROM_WRITE(zpo);
  551. }
  552. //
  553. // Planar Bed Leveling matrix
  554. //
  555. {
  556. #if ABL_PLANAR
  557. EEPROM_WRITE(planner.bed_level_matrix);
  558. #else
  559. dummyf = 0;
  560. for (uint8_t q = 9; q--;) EEPROM_WRITE(dummyf);
  561. #endif
  562. }
  563. //
  564. // Bilinear Auto Bed Leveling
  565. //
  566. {
  567. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  568. static_assert(
  569. sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]),
  570. "Bilinear Z array is the wrong size."
  571. );
  572. #else
  573. const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
  574. #endif
  575. const uint8_t grid_max_x = TERN(AUTO_BED_LEVELING_BILINEAR, GRID_MAX_POINTS_X, 3),
  576. grid_max_y = TERN(AUTO_BED_LEVELING_BILINEAR, GRID_MAX_POINTS_Y, 3);
  577. EEPROM_WRITE(grid_max_x);
  578. EEPROM_WRITE(grid_max_y);
  579. EEPROM_WRITE(bilinear_grid_spacing);
  580. EEPROM_WRITE(bilinear_start);
  581. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  582. EEPROM_WRITE(z_values); // 9-256 floats
  583. #else
  584. dummyf = 0;
  585. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
  586. #endif
  587. }
  588. //
  589. // Unified Bed Leveling
  590. //
  591. {
  592. _FIELD_TEST(planner_leveling_active);
  593. const bool ubl_active = TERN(AUTO_BED_LEVELING_UBL, planner.leveling_active, false);
  594. const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, ubl.storage_slot, -1);
  595. EEPROM_WRITE(ubl_active);
  596. EEPROM_WRITE(storage_slot);
  597. }
  598. //
  599. // Servo Angles
  600. //
  601. {
  602. _FIELD_TEST(servo_angles);
  603. #if !HAS_SERVO_ANGLES
  604. uint16_t servo_angles[EEPROM_NUM_SERVOS][2] = { { 0, 0 } };
  605. #endif
  606. EEPROM_WRITE(servo_angles);
  607. }
  608. //
  609. // Thermal first layer compensation values
  610. //
  611. #if ENABLED(PROBE_TEMP_COMPENSATION)
  612. EEPROM_WRITE(temp_comp.z_offsets_probe);
  613. EEPROM_WRITE(temp_comp.z_offsets_bed);
  614. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  615. EEPROM_WRITE(temp_comp.z_offsets_ext);
  616. #endif
  617. #else
  618. // No placeholder data for this feature
  619. #endif
  620. //
  621. // BLTOUCH
  622. //
  623. {
  624. _FIELD_TEST(bltouch_last_written_mode);
  625. const bool bltouch_last_written_mode = TERN(BLTOUCH, bltouch.last_written_mode, false);
  626. EEPROM_WRITE(bltouch_last_written_mode);
  627. }
  628. //
  629. // DELTA Geometry or Dual Endstops offsets
  630. //
  631. {
  632. #if ENABLED(DELTA)
  633. _FIELD_TEST(delta_height);
  634. EEPROM_WRITE(delta_height); // 1 float
  635. EEPROM_WRITE(delta_endstop_adj); // 3 floats
  636. EEPROM_WRITE(delta_radius); // 1 float
  637. EEPROM_WRITE(delta_diagonal_rod); // 1 float
  638. EEPROM_WRITE(delta_segments_per_second); // 1 float
  639. EEPROM_WRITE(delta_tower_angle_trim); // 3 floats
  640. #elif HAS_EXTRA_ENDSTOPS
  641. _FIELD_TEST(x2_endstop_adj);
  642. // Write dual endstops in X, Y, Z order. Unused = 0.0
  643. dummyf = 0;
  644. EEPROM_WRITE(TERN(X_DUAL_ENDSTOPS, endstops.x2_endstop_adj, dummyf)); // 1 float
  645. EEPROM_WRITE(TERN(Y_DUAL_ENDSTOPS, endstops.y2_endstop_adj, dummyf)); // 1 float
  646. EEPROM_WRITE(TERN(Z_MULTI_ENDSTOPS, endstops.z2_endstop_adj, dummyf)); // 1 float
  647. #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3
  648. EEPROM_WRITE(endstops.z3_endstop_adj); // 1 float
  649. #else
  650. EEPROM_WRITE(dummyf);
  651. #endif
  652. #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4
  653. EEPROM_WRITE(endstops.z4_endstop_adj); // 1 float
  654. #else
  655. EEPROM_WRITE(dummyf);
  656. #endif
  657. #endif
  658. }
  659. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  660. EEPROM_WRITE(z_stepper_align.xy);
  661. #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
  662. EEPROM_WRITE(z_stepper_align.stepper_xy);
  663. #endif
  664. #endif
  665. //
  666. // LCD Preheat settings
  667. //
  668. {
  669. _FIELD_TEST(ui_preheat_hotend_temp);
  670. #if HAS_HOTEND && HAS_LCD_MENU
  671. const int16_t (&ui_preheat_hotend_temp)[2] = ui.preheat_hotend_temp,
  672. (&ui_preheat_bed_temp)[2] = ui.preheat_bed_temp;
  673. const uint8_t (&ui_preheat_fan_speed)[2] = ui.preheat_fan_speed;
  674. #elif ENABLED(DWIN_CREALITY_LCD)
  675. const int16_t (&ui_preheat_hotend_temp)[2] = HMI_ValueStruct.preheat_hotend_temp,
  676. (&ui_preheat_bed_temp)[2] = HMI_ValueStruct.preheat_bed_temp;
  677. const uint8_t (&ui_preheat_fan_speed)[2] = HMI_ValueStruct.preheat_fan_speed;
  678. #else
  679. constexpr int16_t ui_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
  680. ui_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED };
  681. constexpr uint8_t ui_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED };
  682. #endif
  683. EEPROM_WRITE(ui_preheat_hotend_temp);
  684. EEPROM_WRITE(ui_preheat_bed_temp);
  685. EEPROM_WRITE(ui_preheat_fan_speed);
  686. }
  687. //
  688. // PIDTEMP
  689. //
  690. {
  691. _FIELD_TEST(hotendPID);
  692. HOTEND_LOOP() {
  693. PIDCF_t pidcf = {
  694. #if DISABLED(PIDTEMP)
  695. NAN, NAN, NAN,
  696. NAN, NAN
  697. #else
  698. PID_PARAM(Kp, e),
  699. unscalePID_i(PID_PARAM(Ki, e)),
  700. unscalePID_d(PID_PARAM(Kd, e)),
  701. PID_PARAM(Kc, e),
  702. PID_PARAM(Kf, e)
  703. #endif
  704. };
  705. EEPROM_WRITE(pidcf);
  706. }
  707. _FIELD_TEST(lpq_len);
  708. #if DISABLED(PID_EXTRUSION_SCALING)
  709. const int16_t lpq_len = 20;
  710. #endif
  711. EEPROM_WRITE(TERN(PID_EXTRUSION_SCALING, thermalManager.lpq_len, lpq_len));
  712. }
  713. //
  714. // PIDTEMPBED
  715. //
  716. {
  717. _FIELD_TEST(bedPID);
  718. const PID_t bed_pid = {
  719. #if DISABLED(PIDTEMPBED)
  720. NAN, NAN, NAN
  721. #else
  722. // Store the unscaled PID values
  723. thermalManager.temp_bed.pid.Kp,
  724. unscalePID_i(thermalManager.temp_bed.pid.Ki),
  725. unscalePID_d(thermalManager.temp_bed.pid.Kd)
  726. #endif
  727. };
  728. EEPROM_WRITE(bed_pid);
  729. }
  730. //
  731. // User-defined Thermistors
  732. //
  733. #if HAS_USER_THERMISTORS
  734. {
  735. _FIELD_TEST(user_thermistor);
  736. EEPROM_WRITE(thermalManager.user_thermistor);
  737. }
  738. #endif
  739. //
  740. // Power monitor
  741. //
  742. {
  743. #if HAS_POWER_MONITOR
  744. const uint8_t &power_monitor_flags = power_monitor.flags;
  745. #else
  746. constexpr uint8_t power_monitor_flags = 0x00;
  747. #endif
  748. _FIELD_TEST(power_monitor_flags);
  749. EEPROM_WRITE(power_monitor_flags);
  750. }
  751. //
  752. // LCD Contrast
  753. //
  754. {
  755. _FIELD_TEST(lcd_contrast);
  756. const int16_t lcd_contrast =
  757. #if HAS_LCD_CONTRAST
  758. ui.contrast
  759. #else
  760. 127
  761. #endif
  762. ;
  763. EEPROM_WRITE(lcd_contrast);
  764. }
  765. //
  766. // Controller Fan
  767. //
  768. {
  769. _FIELD_TEST(controllerFan_settings);
  770. #if ENABLED(USE_CONTROLLER_FAN)
  771. const controllerFan_settings_t &cfs = controllerFan.settings;
  772. #else
  773. controllerFan_settings_t cfs = controllerFan_defaults;
  774. #endif
  775. EEPROM_WRITE(cfs);
  776. }
  777. //
  778. // Power-Loss Recovery
  779. //
  780. {
  781. _FIELD_TEST(recovery_enabled);
  782. const bool recovery_enabled = TERN(POWER_LOSS_RECOVERY, recovery.enabled, ENABLED(PLR_ENABLED_DEFAULT));
  783. EEPROM_WRITE(recovery_enabled);
  784. }
  785. //
  786. // Firmware Retraction
  787. //
  788. {
  789. _FIELD_TEST(fwretract_settings);
  790. #if DISABLED(FWRETRACT)
  791. const fwretract_settings_t autoretract_defaults = { 3, 45, 0, 0, 0, 13, 0, 8 };
  792. #endif
  793. EEPROM_WRITE(TERN(FWRETRACT, fwretract.settings, autoretract_defaults));
  794. #if DISABLED(FWRETRACT_AUTORETRACT)
  795. const bool autoretract_enabled = false;
  796. #endif
  797. EEPROM_WRITE(TERN(FWRETRACT_AUTORETRACT, fwretract.autoretract_enabled, autoretract_enabled));
  798. }
  799. //
  800. // Volumetric & Filament Size
  801. //
  802. {
  803. _FIELD_TEST(parser_volumetric_enabled);
  804. #if DISABLED(NO_VOLUMETRICS)
  805. EEPROM_WRITE(parser.volumetric_enabled);
  806. EEPROM_WRITE(planner.filament_size);
  807. #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
  808. EEPROM_WRITE(planner.volumetric_extruder_limit);
  809. #else
  810. dummyf = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
  811. for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
  812. #endif
  813. #else
  814. const bool volumetric_enabled = false;
  815. EEPROM_WRITE(volumetric_enabled);
  816. dummyf = DEFAULT_NOMINAL_FILAMENT_DIA;
  817. for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
  818. dummyf = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
  819. for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
  820. #endif
  821. }
  822. //
  823. // TMC Configuration
  824. //
  825. {
  826. _FIELD_TEST(tmc_stepper_current);
  827. tmc_stepper_current_t tmc_stepper_current = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  828. #if HAS_TRINAMIC_CONFIG
  829. #if AXIS_IS_TMC(X)
  830. tmc_stepper_current.X = stepperX.getMilliamps();
  831. #endif
  832. #if AXIS_IS_TMC(Y)
  833. tmc_stepper_current.Y = stepperY.getMilliamps();
  834. #endif
  835. #if AXIS_IS_TMC(Z)
  836. tmc_stepper_current.Z = stepperZ.getMilliamps();
  837. #endif
  838. #if AXIS_IS_TMC(X2)
  839. tmc_stepper_current.X2 = stepperX2.getMilliamps();
  840. #endif
  841. #if AXIS_IS_TMC(Y2)
  842. tmc_stepper_current.Y2 = stepperY2.getMilliamps();
  843. #endif
  844. #if AXIS_IS_TMC(Z2)
  845. tmc_stepper_current.Z2 = stepperZ2.getMilliamps();
  846. #endif
  847. #if AXIS_IS_TMC(Z3)
  848. tmc_stepper_current.Z3 = stepperZ3.getMilliamps();
  849. #endif
  850. #if AXIS_IS_TMC(Z4)
  851. tmc_stepper_current.Z4 = stepperZ4.getMilliamps();
  852. #endif
  853. #if MAX_EXTRUDERS
  854. #if AXIS_IS_TMC(E0)
  855. tmc_stepper_current.E0 = stepperE0.getMilliamps();
  856. #endif
  857. #if MAX_EXTRUDERS > 1
  858. #if AXIS_IS_TMC(E1)
  859. tmc_stepper_current.E1 = stepperE1.getMilliamps();
  860. #endif
  861. #if MAX_EXTRUDERS > 2
  862. #if AXIS_IS_TMC(E2)
  863. tmc_stepper_current.E2 = stepperE2.getMilliamps();
  864. #endif
  865. #if MAX_EXTRUDERS > 3
  866. #if AXIS_IS_TMC(E3)
  867. tmc_stepper_current.E3 = stepperE3.getMilliamps();
  868. #endif
  869. #if MAX_EXTRUDERS > 4
  870. #if AXIS_IS_TMC(E4)
  871. tmc_stepper_current.E4 = stepperE4.getMilliamps();
  872. #endif
  873. #if MAX_EXTRUDERS > 5
  874. #if AXIS_IS_TMC(E5)
  875. tmc_stepper_current.E5 = stepperE5.getMilliamps();
  876. #endif
  877. #if MAX_EXTRUDERS > 6
  878. #if AXIS_IS_TMC(E6)
  879. tmc_stepper_current.E6 = stepperE6.getMilliamps();
  880. #endif
  881. #if MAX_EXTRUDERS > 7
  882. #if AXIS_IS_TMC(E7)
  883. tmc_stepper_current.E7 = stepperE7.getMilliamps();
  884. #endif
  885. #endif // MAX_EXTRUDERS > 7
  886. #endif // MAX_EXTRUDERS > 6
  887. #endif // MAX_EXTRUDERS > 5
  888. #endif // MAX_EXTRUDERS > 4
  889. #endif // MAX_EXTRUDERS > 3
  890. #endif // MAX_EXTRUDERS > 2
  891. #endif // MAX_EXTRUDERS > 1
  892. #endif // MAX_EXTRUDERS
  893. #endif
  894. EEPROM_WRITE(tmc_stepper_current);
  895. }
  896. //
  897. // TMC Hybrid Threshold, and placeholder values
  898. //
  899. {
  900. _FIELD_TEST(tmc_hybrid_threshold);
  901. #if ENABLED(HYBRID_THRESHOLD)
  902. tmc_hybrid_threshold_t tmc_hybrid_threshold = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  903. #if AXIS_HAS_STEALTHCHOP(X)
  904. tmc_hybrid_threshold.X = stepperX.get_pwm_thrs();
  905. #endif
  906. #if AXIS_HAS_STEALTHCHOP(Y)
  907. tmc_hybrid_threshold.Y = stepperY.get_pwm_thrs();
  908. #endif
  909. #if AXIS_HAS_STEALTHCHOP(Z)
  910. tmc_hybrid_threshold.Z = stepperZ.get_pwm_thrs();
  911. #endif
  912. #if AXIS_HAS_STEALTHCHOP(X2)
  913. tmc_hybrid_threshold.X2 = stepperX2.get_pwm_thrs();
  914. #endif
  915. #if AXIS_HAS_STEALTHCHOP(Y2)
  916. tmc_hybrid_threshold.Y2 = stepperY2.get_pwm_thrs();
  917. #endif
  918. #if AXIS_HAS_STEALTHCHOP(Z2)
  919. tmc_hybrid_threshold.Z2 = stepperZ2.get_pwm_thrs();
  920. #endif
  921. #if AXIS_HAS_STEALTHCHOP(Z3)
  922. tmc_hybrid_threshold.Z3 = stepperZ3.get_pwm_thrs();
  923. #endif
  924. #if AXIS_HAS_STEALTHCHOP(Z4)
  925. tmc_hybrid_threshold.Z4 = stepperZ4.get_pwm_thrs();
  926. #endif
  927. #if MAX_EXTRUDERS
  928. #if AXIS_HAS_STEALTHCHOP(E0)
  929. tmc_hybrid_threshold.E0 = stepperE0.get_pwm_thrs();
  930. #endif
  931. #if MAX_EXTRUDERS > 1
  932. #if AXIS_HAS_STEALTHCHOP(E1)
  933. tmc_hybrid_threshold.E1 = stepperE1.get_pwm_thrs();
  934. #endif
  935. #if MAX_EXTRUDERS > 2
  936. #if AXIS_HAS_STEALTHCHOP(E2)
  937. tmc_hybrid_threshold.E2 = stepperE2.get_pwm_thrs();
  938. #endif
  939. #if MAX_EXTRUDERS > 3
  940. #if AXIS_HAS_STEALTHCHOP(E3)
  941. tmc_hybrid_threshold.E3 = stepperE3.get_pwm_thrs();
  942. #endif
  943. #if MAX_EXTRUDERS > 4
  944. #if AXIS_HAS_STEALTHCHOP(E4)
  945. tmc_hybrid_threshold.E4 = stepperE4.get_pwm_thrs();
  946. #endif
  947. #if MAX_EXTRUDERS > 5
  948. #if AXIS_HAS_STEALTHCHOP(E5)
  949. tmc_hybrid_threshold.E5 = stepperE5.get_pwm_thrs();
  950. #endif
  951. #if MAX_EXTRUDERS > 6
  952. #if AXIS_HAS_STEALTHCHOP(E6)
  953. tmc_hybrid_threshold.E6 = stepperE6.get_pwm_thrs();
  954. #endif
  955. #if MAX_EXTRUDERS > 7
  956. #if AXIS_HAS_STEALTHCHOP(E7)
  957. tmc_hybrid_threshold.E7 = stepperE7.get_pwm_thrs();
  958. #endif
  959. #endif // MAX_EXTRUDERS > 7
  960. #endif // MAX_EXTRUDERS > 6
  961. #endif // MAX_EXTRUDERS > 5
  962. #endif // MAX_EXTRUDERS > 4
  963. #endif // MAX_EXTRUDERS > 3
  964. #endif // MAX_EXTRUDERS > 2
  965. #endif // MAX_EXTRUDERS > 1
  966. #endif // MAX_EXTRUDERS
  967. #else
  968. const tmc_hybrid_threshold_t tmc_hybrid_threshold = {
  969. .X = 100, .Y = 100, .Z = 3,
  970. .X2 = 100, .Y2 = 100, .Z2 = 3, .Z3 = 3, .Z4 = 3,
  971. .E0 = 30, .E1 = 30, .E2 = 30,
  972. .E3 = 30, .E4 = 30, .E5 = 30
  973. };
  974. #endif
  975. EEPROM_WRITE(tmc_hybrid_threshold);
  976. }
  977. //
  978. // TMC StallGuard threshold
  979. //
  980. {
  981. tmc_sgt_t tmc_sgt{0};
  982. #if USE_SENSORLESS
  983. TERN_(X_SENSORLESS, tmc_sgt.X = stepperX.homing_threshold());
  984. TERN_(X2_SENSORLESS, tmc_sgt.X2 = stepperX2.homing_threshold());
  985. TERN_(Y_SENSORLESS, tmc_sgt.Y = stepperY.homing_threshold());
  986. TERN_(Y2_SENSORLESS, tmc_sgt.Y2 = stepperY2.homing_threshold());
  987. TERN_(Z_SENSORLESS, tmc_sgt.Z = stepperZ.homing_threshold());
  988. TERN_(Z2_SENSORLESS, tmc_sgt.Z2 = stepperZ2.homing_threshold());
  989. TERN_(Z3_SENSORLESS, tmc_sgt.Z3 = stepperZ3.homing_threshold());
  990. TERN_(Z4_SENSORLESS, tmc_sgt.Z4 = stepperZ4.homing_threshold());
  991. #endif
  992. EEPROM_WRITE(tmc_sgt);
  993. }
  994. //
  995. // TMC stepping mode
  996. //
  997. {
  998. _FIELD_TEST(tmc_stealth_enabled);
  999. tmc_stealth_enabled_t tmc_stealth_enabled = { false, false, false, false, false, false, false, false, false, false, false, false, false };
  1000. #if HAS_STEALTHCHOP
  1001. #if AXIS_HAS_STEALTHCHOP(X)
  1002. tmc_stealth_enabled.X = stepperX.get_stealthChop_status();
  1003. #endif
  1004. #if AXIS_HAS_STEALTHCHOP(Y)
  1005. tmc_stealth_enabled.Y = stepperY.get_stealthChop_status();
  1006. #endif
  1007. #if AXIS_HAS_STEALTHCHOP(Z)
  1008. tmc_stealth_enabled.Z = stepperZ.get_stealthChop_status();
  1009. #endif
  1010. #if AXIS_HAS_STEALTHCHOP(X2)
  1011. tmc_stealth_enabled.X2 = stepperX2.get_stealthChop_status();
  1012. #endif
  1013. #if AXIS_HAS_STEALTHCHOP(Y2)
  1014. tmc_stealth_enabled.Y2 = stepperY2.get_stealthChop_status();
  1015. #endif
  1016. #if AXIS_HAS_STEALTHCHOP(Z2)
  1017. tmc_stealth_enabled.Z2 = stepperZ2.get_stealthChop_status();
  1018. #endif
  1019. #if AXIS_HAS_STEALTHCHOP(Z3)
  1020. tmc_stealth_enabled.Z3 = stepperZ3.get_stealthChop_status();
  1021. #endif
  1022. #if AXIS_HAS_STEALTHCHOP(Z4)
  1023. tmc_stealth_enabled.Z4 = stepperZ4.get_stealthChop_status();
  1024. #endif
  1025. #if MAX_EXTRUDERS
  1026. #if AXIS_HAS_STEALTHCHOP(E0)
  1027. tmc_stealth_enabled.E0 = stepperE0.get_stealthChop_status();
  1028. #endif
  1029. #if MAX_EXTRUDERS > 1
  1030. #if AXIS_HAS_STEALTHCHOP(E1)
  1031. tmc_stealth_enabled.E1 = stepperE1.get_stealthChop_status();
  1032. #endif
  1033. #if MAX_EXTRUDERS > 2
  1034. #if AXIS_HAS_STEALTHCHOP(E2)
  1035. tmc_stealth_enabled.E2 = stepperE2.get_stealthChop_status();
  1036. #endif
  1037. #if MAX_EXTRUDERS > 3
  1038. #if AXIS_HAS_STEALTHCHOP(E3)
  1039. tmc_stealth_enabled.E3 = stepperE3.get_stealthChop_status();
  1040. #endif
  1041. #if MAX_EXTRUDERS > 4
  1042. #if AXIS_HAS_STEALTHCHOP(E4)
  1043. tmc_stealth_enabled.E4 = stepperE4.get_stealthChop_status();
  1044. #endif
  1045. #if MAX_EXTRUDERS > 5
  1046. #if AXIS_HAS_STEALTHCHOP(E5)
  1047. tmc_stealth_enabled.E5 = stepperE5.get_stealthChop_status();
  1048. #endif
  1049. #if MAX_EXTRUDERS > 6
  1050. #if AXIS_HAS_STEALTHCHOP(E6)
  1051. tmc_stealth_enabled.E6 = stepperE6.get_stealthChop_status();
  1052. #endif
  1053. #if MAX_EXTRUDERS > 7
  1054. #if AXIS_HAS_STEALTHCHOP(E7)
  1055. tmc_stealth_enabled.E7 = stepperE7.get_stealthChop_status();
  1056. #endif
  1057. #endif // MAX_EXTRUDERS > 7
  1058. #endif // MAX_EXTRUDERS > 6
  1059. #endif // MAX_EXTRUDERS > 5
  1060. #endif // MAX_EXTRUDERS > 4
  1061. #endif // MAX_EXTRUDERS > 3
  1062. #endif // MAX_EXTRUDERS > 2
  1063. #endif // MAX_EXTRUDERS > 1
  1064. #endif // MAX_EXTRUDERS
  1065. #endif
  1066. EEPROM_WRITE(tmc_stealth_enabled);
  1067. }
  1068. //
  1069. // Linear Advance
  1070. //
  1071. {
  1072. _FIELD_TEST(planner_extruder_advance_K);
  1073. #if ENABLED(LIN_ADVANCE)
  1074. EEPROM_WRITE(planner.extruder_advance_K);
  1075. #else
  1076. dummyf = 0;
  1077. for (uint8_t q = _MAX(EXTRUDERS, 1); q--;) EEPROM_WRITE(dummyf);
  1078. #endif
  1079. }
  1080. //
  1081. // Motor Current PWM
  1082. //
  1083. {
  1084. _FIELD_TEST(motor_current_setting);
  1085. #if HAS_MOTOR_CURRENT_PWM
  1086. EEPROM_WRITE(stepper.motor_current_setting);
  1087. #else
  1088. const uint32_t no_current[3] = { 0 };
  1089. EEPROM_WRITE(no_current);
  1090. #endif
  1091. }
  1092. //
  1093. // CNC Coordinate Systems
  1094. //
  1095. _FIELD_TEST(coordinate_system);
  1096. #if DISABLED(CNC_COORDINATE_SYSTEMS)
  1097. const xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS] = { { 0 } };
  1098. #endif
  1099. EEPROM_WRITE(TERN(CNC_COORDINATE_SYSTEMS, gcode.coordinate_system, coordinate_system));
  1100. //
  1101. // Skew correction factors
  1102. //
  1103. _FIELD_TEST(planner_skew_factor);
  1104. EEPROM_WRITE(planner.skew_factor);
  1105. //
  1106. // Advanced Pause filament load & unload lengths
  1107. //
  1108. #if EXTRUDERS
  1109. {
  1110. #if DISABLED(ADVANCED_PAUSE_FEATURE)
  1111. const fil_change_settings_t fc_settings[EXTRUDERS] = { 0, 0 };
  1112. #endif
  1113. _FIELD_TEST(fc_settings);
  1114. EEPROM_WRITE(fc_settings);
  1115. }
  1116. #endif
  1117. //
  1118. // Multiple Extruders
  1119. //
  1120. #if EXTRUDERS > 1
  1121. _FIELD_TEST(toolchange_settings);
  1122. EEPROM_WRITE(toolchange_settings);
  1123. #endif
  1124. //
  1125. // Backlash Compensation
  1126. //
  1127. {
  1128. #if ENABLED(BACKLASH_GCODE)
  1129. const xyz_float_t &backlash_distance_mm = backlash.distance_mm;
  1130. const uint8_t &backlash_correction = backlash.correction;
  1131. #else
  1132. const xyz_float_t backlash_distance_mm{0};
  1133. const uint8_t backlash_correction = 0;
  1134. #endif
  1135. #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
  1136. const float &backlash_smoothing_mm = backlash.smoothing_mm;
  1137. #else
  1138. const float backlash_smoothing_mm = 3;
  1139. #endif
  1140. _FIELD_TEST(backlash_distance_mm);
  1141. EEPROM_WRITE(backlash_distance_mm);
  1142. EEPROM_WRITE(backlash_correction);
  1143. EEPROM_WRITE(backlash_smoothing_mm);
  1144. }
  1145. //
  1146. // Extensible UI User Data
  1147. //
  1148. #if ENABLED(EXTENSIBLE_UI)
  1149. {
  1150. char extui_data[ExtUI::eeprom_data_size] = { 0 };
  1151. ExtUI::onStoreSettings(extui_data);
  1152. _FIELD_TEST(extui_data);
  1153. EEPROM_WRITE(extui_data);
  1154. }
  1155. #endif
  1156. //
  1157. // Case Light Brightness
  1158. //
  1159. #if HAS_CASE_LIGHT_BRIGHTNESS
  1160. EEPROM_WRITE(case_light_brightness);
  1161. #endif
  1162. //
  1163. // Validate CRC and Data Size
  1164. //
  1165. if (!eeprom_error) {
  1166. const uint16_t eeprom_size = eeprom_index - (EEPROM_OFFSET),
  1167. final_crc = working_crc;
  1168. // Write the EEPROM header
  1169. eeprom_index = EEPROM_OFFSET;
  1170. EEPROM_WRITE(version);
  1171. EEPROM_WRITE(final_crc);
  1172. // Report storage size
  1173. DEBUG_ECHO_START();
  1174. DEBUG_ECHOLNPAIR("Settings Stored (", eeprom_size, " bytes; crc ", (uint32_t)final_crc, ")");
  1175. eeprom_error |= size_error(eeprom_size);
  1176. }
  1177. EEPROM_FINISH();
  1178. //
  1179. // UBL Mesh
  1180. //
  1181. #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
  1182. if (ubl.storage_slot >= 0)
  1183. store_mesh(ubl.storage_slot);
  1184. #endif
  1185. if (!eeprom_error) LCD_MESSAGEPGM(MSG_SETTINGS_STORED);
  1186. TERN_(EXTENSIBLE_UI, ExtUI::onConfigurationStoreWritten(!eeprom_error));
  1187. return !eeprom_error;
  1188. }
  1189. /**
  1190. * M501 - Retrieve Configuration
  1191. */
  1192. bool MarlinSettings::_load() {
  1193. uint16_t working_crc = 0;
  1194. EEPROM_START();
  1195. char stored_ver[4];
  1196. EEPROM_READ_ALWAYS(stored_ver);
  1197. uint16_t stored_crc;
  1198. EEPROM_READ_ALWAYS(stored_crc);
  1199. // Version has to match or defaults are used
  1200. if (strncmp(version, stored_ver, 3) != 0) {
  1201. if (stored_ver[3] != '\0') {
  1202. stored_ver[0] = '?';
  1203. stored_ver[1] = '\0';
  1204. }
  1205. DEBUG_ECHO_START();
  1206. DEBUG_ECHOLNPAIR("EEPROM version mismatch (EEPROM=", stored_ver, " Marlin=" EEPROM_VERSION ")");
  1207. TERN(EEPROM_AUTO_INIT,,ui.eeprom_alert_version());
  1208. eeprom_error = true;
  1209. }
  1210. else {
  1211. float dummyf = 0;
  1212. working_crc = 0; // Init to 0. Accumulated by EEPROM_READ
  1213. _FIELD_TEST(esteppers);
  1214. // Number of esteppers may change
  1215. uint8_t esteppers;
  1216. EEPROM_READ_ALWAYS(esteppers);
  1217. //
  1218. // Planner Motion
  1219. //
  1220. {
  1221. // Get only the number of E stepper parameters previously stored
  1222. // Any steppers added later are set to their defaults
  1223. uint32_t tmp1[XYZ + esteppers];
  1224. float tmp2[XYZ + esteppers];
  1225. feedRate_t tmp3[XYZ + esteppers];
  1226. EEPROM_READ(tmp1); // max_acceleration_mm_per_s2
  1227. EEPROM_READ(planner.settings.min_segment_time_us);
  1228. EEPROM_READ(tmp2); // axis_steps_per_mm
  1229. EEPROM_READ(tmp3); // max_feedrate_mm_s
  1230. if (!validating) LOOP_XYZE_N(i) {
  1231. const bool in = (i < esteppers + XYZ);
  1232. planner.settings.max_acceleration_mm_per_s2[i] = in ? tmp1[i] : pgm_read_dword(&_DMA[ALIM(i, _DMA)]);
  1233. planner.settings.axis_steps_per_mm[i] = in ? tmp2[i] : pgm_read_float(&_DASU[ALIM(i, _DASU)]);
  1234. planner.settings.max_feedrate_mm_s[i] = in ? tmp3[i] : pgm_read_float(&_DMF[ALIM(i, _DMF)]);
  1235. }
  1236. EEPROM_READ(planner.settings.acceleration);
  1237. EEPROM_READ(planner.settings.retract_acceleration);
  1238. EEPROM_READ(planner.settings.travel_acceleration);
  1239. EEPROM_READ(planner.settings.min_feedrate_mm_s);
  1240. EEPROM_READ(planner.settings.min_travel_feedrate_mm_s);
  1241. #if HAS_CLASSIC_JERK
  1242. EEPROM_READ(planner.max_jerk);
  1243. #if HAS_LINEAR_E_JERK
  1244. EEPROM_READ(dummyf);
  1245. #endif
  1246. #else
  1247. for (uint8_t q = 4; q--;) EEPROM_READ(dummyf);
  1248. #endif
  1249. EEPROM_READ(TERN(CLASSIC_JERK, dummyf, planner.junction_deviation_mm));
  1250. }
  1251. //
  1252. // Home Offset (M206 / M665)
  1253. //
  1254. {
  1255. _FIELD_TEST(home_offset);
  1256. #if HAS_SCARA_OFFSET
  1257. EEPROM_READ(scara_home_offset);
  1258. #else
  1259. #if !HAS_HOME_OFFSET
  1260. xyz_pos_t home_offset;
  1261. #endif
  1262. EEPROM_READ(home_offset);
  1263. #endif
  1264. }
  1265. //
  1266. // Hotend Offsets, if any
  1267. //
  1268. {
  1269. #if HAS_HOTEND_OFFSET
  1270. // Skip hotend 0 which must be 0
  1271. LOOP_S_L_N(e, 1, HOTENDS)
  1272. EEPROM_READ(hotend_offset[e]);
  1273. #endif
  1274. }
  1275. //
  1276. // Filament Runout Sensor
  1277. //
  1278. {
  1279. #if HAS_FILAMENT_SENSOR
  1280. const bool &runout_sensor_enabled = runout.enabled;
  1281. #else
  1282. bool runout_sensor_enabled;
  1283. #endif
  1284. _FIELD_TEST(runout_sensor_enabled);
  1285. EEPROM_READ(runout_sensor_enabled);
  1286. float runout_distance_mm;
  1287. EEPROM_READ(runout_distance_mm);
  1288. #if HAS_FILAMENT_RUNOUT_DISTANCE
  1289. if (!validating) runout.set_runout_distance(runout_distance_mm);
  1290. #endif
  1291. }
  1292. //
  1293. // Global Leveling
  1294. //
  1295. EEPROM_READ(TERN(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height, dummyf));
  1296. //
  1297. // Mesh (Manual) Bed Leveling
  1298. //
  1299. {
  1300. uint8_t mesh_num_x, mesh_num_y;
  1301. EEPROM_READ(dummyf);
  1302. EEPROM_READ_ALWAYS(mesh_num_x);
  1303. EEPROM_READ_ALWAYS(mesh_num_y);
  1304. #if ENABLED(MESH_BED_LEVELING)
  1305. if (!validating) mbl.z_offset = dummyf;
  1306. if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
  1307. // EEPROM data fits the current mesh
  1308. EEPROM_READ(mbl.z_values);
  1309. }
  1310. else {
  1311. // EEPROM data is stale
  1312. if (!validating) mbl.reset();
  1313. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
  1314. }
  1315. #else
  1316. // MBL is disabled - skip the stored data
  1317. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
  1318. #endif // MESH_BED_LEVELING
  1319. }
  1320. //
  1321. // Probe Z Offset
  1322. //
  1323. {
  1324. _FIELD_TEST(probe_offset);
  1325. #if HAS_BED_PROBE
  1326. const xyz_pos_t &zpo = probe.offset;
  1327. #else
  1328. xyz_pos_t zpo;
  1329. #endif
  1330. EEPROM_READ(zpo);
  1331. }
  1332. //
  1333. // Planar Bed Leveling matrix
  1334. //
  1335. {
  1336. #if ABL_PLANAR
  1337. EEPROM_READ(planner.bed_level_matrix);
  1338. #else
  1339. for (uint8_t q = 9; q--;) EEPROM_READ(dummyf);
  1340. #endif
  1341. }
  1342. //
  1343. // Bilinear Auto Bed Leveling
  1344. //
  1345. {
  1346. uint8_t grid_max_x, grid_max_y;
  1347. EEPROM_READ_ALWAYS(grid_max_x); // 1 byte
  1348. EEPROM_READ_ALWAYS(grid_max_y); // 1 byte
  1349. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  1350. if (grid_max_x == GRID_MAX_POINTS_X && grid_max_y == GRID_MAX_POINTS_Y) {
  1351. if (!validating) set_bed_leveling_enabled(false);
  1352. EEPROM_READ(bilinear_grid_spacing); // 2 ints
  1353. EEPROM_READ(bilinear_start); // 2 ints
  1354. EEPROM_READ(z_values); // 9 to 256 floats
  1355. }
  1356. else // EEPROM data is stale
  1357. #endif // AUTO_BED_LEVELING_BILINEAR
  1358. {
  1359. // Skip past disabled (or stale) Bilinear Grid data
  1360. xy_pos_t bgs, bs;
  1361. EEPROM_READ(bgs);
  1362. EEPROM_READ(bs);
  1363. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummyf);
  1364. }
  1365. }
  1366. //
  1367. // Unified Bed Leveling active state
  1368. //
  1369. {
  1370. _FIELD_TEST(planner_leveling_active);
  1371. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1372. const bool &planner_leveling_active = planner.leveling_active;
  1373. const int8_t &ubl_storage_slot = ubl.storage_slot;
  1374. #else
  1375. bool planner_leveling_active;
  1376. int8_t ubl_storage_slot;
  1377. #endif
  1378. EEPROM_READ(planner_leveling_active);
  1379. EEPROM_READ(ubl_storage_slot);
  1380. }
  1381. //
  1382. // SERVO_ANGLES
  1383. //
  1384. {
  1385. _FIELD_TEST(servo_angles);
  1386. #if ENABLED(EDITABLE_SERVO_ANGLES)
  1387. uint16_t (&servo_angles_arr)[EEPROM_NUM_SERVOS][2] = servo_angles;
  1388. #else
  1389. uint16_t servo_angles_arr[EEPROM_NUM_SERVOS][2];
  1390. #endif
  1391. EEPROM_READ(servo_angles_arr);
  1392. }
  1393. //
  1394. // Thermal first layer compensation values
  1395. //
  1396. #if ENABLED(PROBE_TEMP_COMPENSATION)
  1397. EEPROM_READ(temp_comp.z_offsets_probe);
  1398. EEPROM_READ(temp_comp.z_offsets_bed);
  1399. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  1400. EEPROM_READ(temp_comp.z_offsets_ext);
  1401. #endif
  1402. temp_comp.reset_index();
  1403. #else
  1404. // No placeholder data for this feature
  1405. #endif
  1406. //
  1407. // BLTOUCH
  1408. //
  1409. {
  1410. _FIELD_TEST(bltouch_last_written_mode);
  1411. #if ENABLED(BLTOUCH)
  1412. const bool &bltouch_last_written_mode = bltouch.last_written_mode;
  1413. #else
  1414. bool bltouch_last_written_mode;
  1415. #endif
  1416. EEPROM_READ(bltouch_last_written_mode);
  1417. }
  1418. //
  1419. // DELTA Geometry or Dual Endstops offsets
  1420. //
  1421. {
  1422. #if ENABLED(DELTA)
  1423. _FIELD_TEST(delta_height);
  1424. EEPROM_READ(delta_height); // 1 float
  1425. EEPROM_READ(delta_endstop_adj); // 3 floats
  1426. EEPROM_READ(delta_radius); // 1 float
  1427. EEPROM_READ(delta_diagonal_rod); // 1 float
  1428. EEPROM_READ(delta_segments_per_second); // 1 float
  1429. EEPROM_READ(delta_tower_angle_trim); // 3 floats
  1430. #elif HAS_EXTRA_ENDSTOPS
  1431. _FIELD_TEST(x2_endstop_adj);
  1432. EEPROM_READ(TERN(X_DUAL_ENDSTOPS, endstops.x2_endstop_adj, dummyf)); // 1 float
  1433. EEPROM_READ(TERN(Y_DUAL_ENDSTOPS, endstops.y2_endstop_adj, dummyf)); // 1 float
  1434. EEPROM_READ(TERN(Z_MULTI_ENDSTOPS, endstops.z2_endstop_adj, dummyf)); // 1 float
  1435. #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3
  1436. EEPROM_READ(endstops.z3_endstop_adj); // 1 float
  1437. #else
  1438. EEPROM_READ(dummyf);
  1439. #endif
  1440. #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4
  1441. EEPROM_READ(endstops.z4_endstop_adj); // 1 float
  1442. #else
  1443. EEPROM_READ(dummyf);
  1444. #endif
  1445. #endif
  1446. }
  1447. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  1448. EEPROM_READ(z_stepper_align.xy);
  1449. #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
  1450. EEPROM_READ(z_stepper_align.stepper_xy);
  1451. #endif
  1452. #endif
  1453. //
  1454. // LCD Preheat settings
  1455. //
  1456. {
  1457. _FIELD_TEST(ui_preheat_hotend_temp);
  1458. #if HAS_HOTEND && HAS_LCD_MENU
  1459. int16_t (&ui_preheat_hotend_temp)[2] = ui.preheat_hotend_temp,
  1460. (&ui_preheat_bed_temp)[2] = ui.preheat_bed_temp;
  1461. uint8_t (&ui_preheat_fan_speed)[2] = ui.preheat_fan_speed;
  1462. #elif ENABLED(DWIN_CREALITY_LCD)
  1463. int16_t (&ui_preheat_hotend_temp)[2] = HMI_ValueStruct.preheat_hotend_temp,
  1464. (&ui_preheat_bed_temp)[2] = HMI_ValueStruct.preheat_bed_temp;
  1465. uint8_t (&ui_preheat_fan_speed)[2] = HMI_ValueStruct.preheat_fan_speed;
  1466. #else
  1467. int16_t ui_preheat_hotend_temp[2], ui_preheat_bed_temp[2];
  1468. uint8_t ui_preheat_fan_speed[2];
  1469. #endif
  1470. EEPROM_READ(ui_preheat_hotend_temp); // 2 floats
  1471. EEPROM_READ(ui_preheat_bed_temp); // 2 floats
  1472. EEPROM_READ(ui_preheat_fan_speed); // 2 floats
  1473. }
  1474. //
  1475. // Hotend PID
  1476. //
  1477. {
  1478. HOTEND_LOOP() {
  1479. PIDCF_t pidcf;
  1480. EEPROM_READ(pidcf);
  1481. #if ENABLED(PIDTEMP)
  1482. if (!validating && !isnan(pidcf.Kp)) {
  1483. // Scale PID values since EEPROM values are unscaled
  1484. PID_PARAM(Kp, e) = pidcf.Kp;
  1485. PID_PARAM(Ki, e) = scalePID_i(pidcf.Ki);
  1486. PID_PARAM(Kd, e) = scalePID_d(pidcf.Kd);
  1487. TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = pidcf.Kc);
  1488. TERN_(PID_FAN_SCALING, PID_PARAM(Kf, e) = pidcf.Kf);
  1489. }
  1490. #endif
  1491. }
  1492. }
  1493. //
  1494. // PID Extrusion Scaling
  1495. //
  1496. {
  1497. _FIELD_TEST(lpq_len);
  1498. #if ENABLED(PID_EXTRUSION_SCALING)
  1499. const int16_t &lpq_len = thermalManager.lpq_len;
  1500. #else
  1501. int16_t lpq_len;
  1502. #endif
  1503. EEPROM_READ(lpq_len);
  1504. }
  1505. //
  1506. // Heated Bed PID
  1507. //
  1508. {
  1509. PID_t pid;
  1510. EEPROM_READ(pid);
  1511. #if ENABLED(PIDTEMPBED)
  1512. if (!validating && !isnan(pid.Kp)) {
  1513. // Scale PID values since EEPROM values are unscaled
  1514. thermalManager.temp_bed.pid.Kp = pid.Kp;
  1515. thermalManager.temp_bed.pid.Ki = scalePID_i(pid.Ki);
  1516. thermalManager.temp_bed.pid.Kd = scalePID_d(pid.Kd);
  1517. }
  1518. #endif
  1519. }
  1520. //
  1521. // User-defined Thermistors
  1522. //
  1523. #if HAS_USER_THERMISTORS
  1524. {
  1525. _FIELD_TEST(user_thermistor);
  1526. EEPROM_READ(thermalManager.user_thermistor);
  1527. }
  1528. #endif
  1529. //
  1530. // Power monitor
  1531. //
  1532. {
  1533. #if HAS_POWER_MONITOR
  1534. uint8_t &power_monitor_flags = power_monitor.flags;
  1535. #else
  1536. uint8_t power_monitor_flags;
  1537. #endif
  1538. _FIELD_TEST(power_monitor_flags);
  1539. EEPROM_READ(power_monitor_flags);
  1540. }
  1541. //
  1542. // LCD Contrast
  1543. //
  1544. {
  1545. _FIELD_TEST(lcd_contrast);
  1546. int16_t lcd_contrast;
  1547. EEPROM_READ(lcd_contrast);
  1548. TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));
  1549. }
  1550. //
  1551. // Controller Fan
  1552. //
  1553. {
  1554. _FIELD_TEST(controllerFan_settings);
  1555. #if ENABLED(CONTROLLER_FAN_EDITABLE)
  1556. const controllerFan_settings_t &cfs = controllerFan.settings;
  1557. #else
  1558. controllerFan_settings_t cfs = { 0 };
  1559. #endif
  1560. EEPROM_READ(cfs);
  1561. }
  1562. //
  1563. // Power-Loss Recovery
  1564. //
  1565. {
  1566. _FIELD_TEST(recovery_enabled);
  1567. #if ENABLED(POWER_LOSS_RECOVERY)
  1568. const bool &recovery_enabled = recovery.enabled;
  1569. #else
  1570. bool recovery_enabled;
  1571. #endif
  1572. EEPROM_READ(recovery_enabled);
  1573. }
  1574. //
  1575. // Firmware Retraction
  1576. //
  1577. {
  1578. _FIELD_TEST(fwretract_settings);
  1579. #if ENABLED(FWRETRACT)
  1580. EEPROM_READ(fwretract.settings);
  1581. #else
  1582. fwretract_settings_t fwretract_settings;
  1583. EEPROM_READ(fwretract_settings);
  1584. #endif
  1585. #if BOTH(FWRETRACT, FWRETRACT_AUTORETRACT)
  1586. EEPROM_READ(fwretract.autoretract_enabled);
  1587. #else
  1588. bool autoretract_enabled;
  1589. EEPROM_READ(autoretract_enabled);
  1590. #endif
  1591. }
  1592. //
  1593. // Volumetric & Filament Size
  1594. //
  1595. {
  1596. struct {
  1597. bool volumetric_enabled;
  1598. float filament_size[EXTRUDERS];
  1599. float volumetric_extruder_limit[EXTRUDERS];
  1600. } storage;
  1601. _FIELD_TEST(parser_volumetric_enabled);
  1602. EEPROM_READ(storage);
  1603. #if DISABLED(NO_VOLUMETRICS)
  1604. if (!validating) {
  1605. parser.volumetric_enabled = storage.volumetric_enabled;
  1606. COPY(planner.filament_size, storage.filament_size);
  1607. #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
  1608. COPY(planner.volumetric_extruder_limit, storage.volumetric_extruder_limit);
  1609. #endif
  1610. }
  1611. #endif
  1612. }
  1613. //
  1614. // TMC Stepper Settings
  1615. //
  1616. if (!validating) reset_stepper_drivers();
  1617. // TMC Stepper Current
  1618. {
  1619. _FIELD_TEST(tmc_stepper_current);
  1620. tmc_stepper_current_t currents;
  1621. EEPROM_READ(currents);
  1622. #if HAS_TRINAMIC_CONFIG
  1623. #define SET_CURR(Q) stepper##Q.rms_current(currents.Q ? currents.Q : Q##_CURRENT)
  1624. if (!validating) {
  1625. #if AXIS_IS_TMC(X)
  1626. SET_CURR(X);
  1627. #endif
  1628. #if AXIS_IS_TMC(Y)
  1629. SET_CURR(Y);
  1630. #endif
  1631. #if AXIS_IS_TMC(Z)
  1632. SET_CURR(Z);
  1633. #endif
  1634. #if AXIS_IS_TMC(X2)
  1635. SET_CURR(X2);
  1636. #endif
  1637. #if AXIS_IS_TMC(Y2)
  1638. SET_CURR(Y2);
  1639. #endif
  1640. #if AXIS_IS_TMC(Z2)
  1641. SET_CURR(Z2);
  1642. #endif
  1643. #if AXIS_IS_TMC(Z3)
  1644. SET_CURR(Z3);
  1645. #endif
  1646. #if AXIS_IS_TMC(Z4)
  1647. SET_CURR(Z4);
  1648. #endif
  1649. #if AXIS_IS_TMC(E0)
  1650. SET_CURR(E0);
  1651. #endif
  1652. #if AXIS_IS_TMC(E1)
  1653. SET_CURR(E1);
  1654. #endif
  1655. #if AXIS_IS_TMC(E2)
  1656. SET_CURR(E2);
  1657. #endif
  1658. #if AXIS_IS_TMC(E3)
  1659. SET_CURR(E3);
  1660. #endif
  1661. #if AXIS_IS_TMC(E4)
  1662. SET_CURR(E4);
  1663. #endif
  1664. #if AXIS_IS_TMC(E5)
  1665. SET_CURR(E5);
  1666. #endif
  1667. #if AXIS_IS_TMC(E6)
  1668. SET_CURR(E6);
  1669. #endif
  1670. #if AXIS_IS_TMC(E7)
  1671. SET_CURR(E7);
  1672. #endif
  1673. }
  1674. #endif
  1675. }
  1676. // TMC Hybrid Threshold
  1677. {
  1678. tmc_hybrid_threshold_t tmc_hybrid_threshold;
  1679. _FIELD_TEST(tmc_hybrid_threshold);
  1680. EEPROM_READ(tmc_hybrid_threshold);
  1681. #if ENABLED(HYBRID_THRESHOLD)
  1682. if (!validating) {
  1683. #if AXIS_HAS_STEALTHCHOP(X)
  1684. stepperX.set_pwm_thrs(tmc_hybrid_threshold.X);
  1685. #endif
  1686. #if AXIS_HAS_STEALTHCHOP(Y)
  1687. stepperY.set_pwm_thrs(tmc_hybrid_threshold.Y);
  1688. #endif
  1689. #if AXIS_HAS_STEALTHCHOP(Z)
  1690. stepperZ.set_pwm_thrs(tmc_hybrid_threshold.Z);
  1691. #endif
  1692. #if AXIS_HAS_STEALTHCHOP(X2)
  1693. stepperX2.set_pwm_thrs(tmc_hybrid_threshold.X2);
  1694. #endif
  1695. #if AXIS_HAS_STEALTHCHOP(Y2)
  1696. stepperY2.set_pwm_thrs(tmc_hybrid_threshold.Y2);
  1697. #endif
  1698. #if AXIS_HAS_STEALTHCHOP(Z2)
  1699. stepperZ2.set_pwm_thrs(tmc_hybrid_threshold.Z2);
  1700. #endif
  1701. #if AXIS_HAS_STEALTHCHOP(Z3)
  1702. stepperZ3.set_pwm_thrs(tmc_hybrid_threshold.Z3);
  1703. #endif
  1704. #if AXIS_HAS_STEALTHCHOP(Z4)
  1705. stepperZ4.set_pwm_thrs(tmc_hybrid_threshold.Z4);
  1706. #endif
  1707. #if AXIS_HAS_STEALTHCHOP(E0)
  1708. stepperE0.set_pwm_thrs(tmc_hybrid_threshold.E0);
  1709. #endif
  1710. #if AXIS_HAS_STEALTHCHOP(E1)
  1711. stepperE1.set_pwm_thrs(tmc_hybrid_threshold.E1);
  1712. #endif
  1713. #if AXIS_HAS_STEALTHCHOP(E2)
  1714. stepperE2.set_pwm_thrs(tmc_hybrid_threshold.E2);
  1715. #endif
  1716. #if AXIS_HAS_STEALTHCHOP(E3)
  1717. stepperE3.set_pwm_thrs(tmc_hybrid_threshold.E3);
  1718. #endif
  1719. #if AXIS_HAS_STEALTHCHOP(E4)
  1720. stepperE4.set_pwm_thrs(tmc_hybrid_threshold.E4);
  1721. #endif
  1722. #if AXIS_HAS_STEALTHCHOP(E5)
  1723. stepperE5.set_pwm_thrs(tmc_hybrid_threshold.E5);
  1724. #endif
  1725. #if AXIS_HAS_STEALTHCHOP(E6)
  1726. stepperE6.set_pwm_thrs(tmc_hybrid_threshold.E6);
  1727. #endif
  1728. #if AXIS_HAS_STEALTHCHOP(E7)
  1729. stepperE7.set_pwm_thrs(tmc_hybrid_threshold.E7);
  1730. #endif
  1731. }
  1732. #endif
  1733. }
  1734. //
  1735. // TMC StallGuard threshold.
  1736. //
  1737. {
  1738. tmc_sgt_t tmc_sgt;
  1739. _FIELD_TEST(tmc_sgt);
  1740. EEPROM_READ(tmc_sgt);
  1741. #if USE_SENSORLESS
  1742. if (!validating) {
  1743. TERN_(X_SENSORLESS, stepperX.homing_threshold(tmc_sgt.X));
  1744. TERN_(X2_SENSORLESS, stepperX2.homing_threshold(tmc_sgt.X2));
  1745. TERN_(Y_SENSORLESS, stepperY.homing_threshold(tmc_sgt.Y));
  1746. TERN_(Y2_SENSORLESS, stepperY2.homing_threshold(tmc_sgt.Y2));
  1747. TERN_(Z_SENSORLESS, stepperZ.homing_threshold(tmc_sgt.Z));
  1748. TERN_(Z2_SENSORLESS, stepperZ2.homing_threshold(tmc_sgt.Z2));
  1749. TERN_(Z3_SENSORLESS, stepperZ3.homing_threshold(tmc_sgt.Z3));
  1750. TERN_(Z4_SENSORLESS, stepperZ4.homing_threshold(tmc_sgt.Z4));
  1751. }
  1752. #endif
  1753. }
  1754. // TMC stepping mode
  1755. {
  1756. _FIELD_TEST(tmc_stealth_enabled);
  1757. tmc_stealth_enabled_t tmc_stealth_enabled;
  1758. EEPROM_READ(tmc_stealth_enabled);
  1759. #if HAS_TRINAMIC_CONFIG
  1760. #define SET_STEPPING_MODE(ST) stepper##ST.stored.stealthChop_enabled = tmc_stealth_enabled.ST; stepper##ST.refresh_stepping_mode();
  1761. if (!validating) {
  1762. #if AXIS_HAS_STEALTHCHOP(X)
  1763. SET_STEPPING_MODE(X);
  1764. #endif
  1765. #if AXIS_HAS_STEALTHCHOP(Y)
  1766. SET_STEPPING_MODE(Y);
  1767. #endif
  1768. #if AXIS_HAS_STEALTHCHOP(Z)
  1769. SET_STEPPING_MODE(Z);
  1770. #endif
  1771. #if AXIS_HAS_STEALTHCHOP(X2)
  1772. SET_STEPPING_MODE(X2);
  1773. #endif
  1774. #if AXIS_HAS_STEALTHCHOP(Y2)
  1775. SET_STEPPING_MODE(Y2);
  1776. #endif
  1777. #if AXIS_HAS_STEALTHCHOP(Z2)
  1778. SET_STEPPING_MODE(Z2);
  1779. #endif
  1780. #if AXIS_HAS_STEALTHCHOP(Z3)
  1781. SET_STEPPING_MODE(Z3);
  1782. #endif
  1783. #if AXIS_HAS_STEALTHCHOP(Z4)
  1784. SET_STEPPING_MODE(Z4);
  1785. #endif
  1786. #if AXIS_HAS_STEALTHCHOP(E0)
  1787. SET_STEPPING_MODE(E0);
  1788. #endif
  1789. #if AXIS_HAS_STEALTHCHOP(E1)
  1790. SET_STEPPING_MODE(E1);
  1791. #endif
  1792. #if AXIS_HAS_STEALTHCHOP(E2)
  1793. SET_STEPPING_MODE(E2);
  1794. #endif
  1795. #if AXIS_HAS_STEALTHCHOP(E3)
  1796. SET_STEPPING_MODE(E3);
  1797. #endif
  1798. #if AXIS_HAS_STEALTHCHOP(E4)
  1799. SET_STEPPING_MODE(E4);
  1800. #endif
  1801. #if AXIS_HAS_STEALTHCHOP(E5)
  1802. SET_STEPPING_MODE(E5);
  1803. #endif
  1804. #if AXIS_HAS_STEALTHCHOP(E6)
  1805. SET_STEPPING_MODE(E6);
  1806. #endif
  1807. #if AXIS_HAS_STEALTHCHOP(E7)
  1808. SET_STEPPING_MODE(E7);
  1809. #endif
  1810. }
  1811. #endif
  1812. }
  1813. //
  1814. // Linear Advance
  1815. //
  1816. {
  1817. float extruder_advance_K[_MAX(EXTRUDERS, 1)];
  1818. _FIELD_TEST(planner_extruder_advance_K);
  1819. EEPROM_READ(extruder_advance_K);
  1820. #if ENABLED(LIN_ADVANCE)
  1821. if (!validating)
  1822. COPY(planner.extruder_advance_K, extruder_advance_K);
  1823. #endif
  1824. }
  1825. //
  1826. // Motor Current PWM
  1827. //
  1828. {
  1829. uint32_t motor_current_setting[3];
  1830. _FIELD_TEST(motor_current_setting);
  1831. EEPROM_READ(motor_current_setting);
  1832. #if HAS_MOTOR_CURRENT_PWM
  1833. if (!validating)
  1834. COPY(stepper.motor_current_setting, motor_current_setting);
  1835. #endif
  1836. }
  1837. //
  1838. // CNC Coordinate System
  1839. //
  1840. {
  1841. _FIELD_TEST(coordinate_system);
  1842. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  1843. if (!validating) (void)gcode.select_coordinate_system(-1); // Go back to machine space
  1844. EEPROM_READ(gcode.coordinate_system);
  1845. #else
  1846. xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS];
  1847. EEPROM_READ(coordinate_system);
  1848. #endif
  1849. }
  1850. //
  1851. // Skew correction factors
  1852. //
  1853. {
  1854. skew_factor_t skew_factor;
  1855. _FIELD_TEST(planner_skew_factor);
  1856. EEPROM_READ(skew_factor);
  1857. #if ENABLED(SKEW_CORRECTION_GCODE)
  1858. if (!validating) {
  1859. planner.skew_factor.xy = skew_factor.xy;
  1860. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  1861. planner.skew_factor.xz = skew_factor.xz;
  1862. planner.skew_factor.yz = skew_factor.yz;
  1863. #endif
  1864. }
  1865. #endif
  1866. }
  1867. //
  1868. // Advanced Pause filament load & unload lengths
  1869. //
  1870. #if EXTRUDERS
  1871. {
  1872. #if DISABLED(ADVANCED_PAUSE_FEATURE)
  1873. fil_change_settings_t fc_settings[EXTRUDERS];
  1874. #endif
  1875. _FIELD_TEST(fc_settings);
  1876. EEPROM_READ(fc_settings);
  1877. }
  1878. #endif
  1879. //
  1880. // Tool-change settings
  1881. //
  1882. #if EXTRUDERS > 1
  1883. _FIELD_TEST(toolchange_settings);
  1884. EEPROM_READ(toolchange_settings);
  1885. #endif
  1886. //
  1887. // Backlash Compensation
  1888. //
  1889. {
  1890. #if ENABLED(BACKLASH_GCODE)
  1891. const xyz_float_t &backlash_distance_mm = backlash.distance_mm;
  1892. const uint8_t &backlash_correction = backlash.correction;
  1893. #else
  1894. float backlash_distance_mm[XYZ];
  1895. uint8_t backlash_correction;
  1896. #endif
  1897. #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
  1898. const float &backlash_smoothing_mm = backlash.smoothing_mm;
  1899. #else
  1900. float backlash_smoothing_mm;
  1901. #endif
  1902. _FIELD_TEST(backlash_distance_mm);
  1903. EEPROM_READ(backlash_distance_mm);
  1904. EEPROM_READ(backlash_correction);
  1905. EEPROM_READ(backlash_smoothing_mm);
  1906. }
  1907. //
  1908. // Extensible UI User Data
  1909. //
  1910. #if ENABLED(EXTENSIBLE_UI)
  1911. // This is a significant hardware change; don't reserve EEPROM space when not present
  1912. {
  1913. const char extui_data[ExtUI::eeprom_data_size] = { 0 };
  1914. _FIELD_TEST(extui_data);
  1915. EEPROM_READ(extui_data);
  1916. if (!validating) ExtUI::onLoadSettings(extui_data);
  1917. }
  1918. #endif
  1919. //
  1920. // Case Light Brightness
  1921. //
  1922. #if HAS_CASE_LIGHT_BRIGHTNESS
  1923. _FIELD_TEST(case_light_brightness);
  1924. EEPROM_READ(case_light_brightness);
  1925. #endif
  1926. eeprom_error = size_error(eeprom_index - (EEPROM_OFFSET));
  1927. if (eeprom_error) {
  1928. DEBUG_ECHO_START();
  1929. DEBUG_ECHOLNPAIR("Index: ", int(eeprom_index - (EEPROM_OFFSET)), " Size: ", datasize());
  1930. TERN(EEPROM_AUTO_INIT,,ui.eeprom_alert_index());
  1931. }
  1932. else if (working_crc != stored_crc) {
  1933. eeprom_error = true;
  1934. DEBUG_ERROR_START();
  1935. DEBUG_ECHOLNPAIR("EEPROM CRC mismatch - (stored) ", stored_crc, " != ", working_crc, " (calculated)!");
  1936. TERN(EEPROM_AUTO_INIT,,ui.eeprom_alert_crc());
  1937. }
  1938. else if (!validating) {
  1939. DEBUG_ECHO_START();
  1940. DEBUG_ECHO(version);
  1941. DEBUG_ECHOLNPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET), " bytes; crc ", (uint32_t)working_crc, ")");
  1942. }
  1943. if (!validating && !eeprom_error) postprocess();
  1944. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1945. if (!validating) {
  1946. ubl.report_state();
  1947. if (!ubl.sanity_check()) {
  1948. SERIAL_EOL();
  1949. #if ENABLED(EEPROM_CHITCHAT)
  1950. ubl.echo_name();
  1951. DEBUG_ECHOLNPGM(" initialized.\n");
  1952. #endif
  1953. }
  1954. else {
  1955. eeprom_error = true;
  1956. #if ENABLED(EEPROM_CHITCHAT)
  1957. DEBUG_ECHOPGM("?Can't enable ");
  1958. ubl.echo_name();
  1959. DEBUG_ECHOLNPGM(".");
  1960. #endif
  1961. ubl.reset();
  1962. }
  1963. if (ubl.storage_slot >= 0) {
  1964. load_mesh(ubl.storage_slot);
  1965. DEBUG_ECHOLNPAIR("Mesh ", ubl.storage_slot, " loaded from storage.");
  1966. }
  1967. else {
  1968. ubl.reset();
  1969. DEBUG_ECHOLNPGM("UBL reset");
  1970. }
  1971. }
  1972. #endif
  1973. }
  1974. #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
  1975. // Report the EEPROM settings
  1976. if (!validating && (DISABLED(EEPROM_BOOT_SILENT) || IsRunning())) report();
  1977. #endif
  1978. EEPROM_FINISH();
  1979. return !eeprom_error;
  1980. }
  1981. #ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE
  1982. extern bool restoreEEPROM();
  1983. #endif
  1984. bool MarlinSettings::validate() {
  1985. validating = true;
  1986. #ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE
  1987. bool success = _load();
  1988. if (!success && restoreEEPROM()) {
  1989. SERIAL_ECHOLNPGM("Recovered backup EEPROM settings from SPI Flash");
  1990. success = _load();
  1991. }
  1992. #else
  1993. const bool success = _load();
  1994. #endif
  1995. validating = false;
  1996. return success;
  1997. }
  1998. bool MarlinSettings::load() {
  1999. if (validate()) {
  2000. const bool success = _load();
  2001. TERN_(EXTENSIBLE_UI, ExtUI::onConfigurationStoreRead(success));
  2002. return success;
  2003. }
  2004. reset();
  2005. #if ENABLED(EEPROM_AUTO_INIT)
  2006. (void)save();
  2007. SERIAL_ECHO_MSG("EEPROM Initialized");
  2008. #endif
  2009. return false;
  2010. }
  2011. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2012. inline void ubl_invalid_slot(const int s) {
  2013. #if ENABLED(EEPROM_CHITCHAT)
  2014. DEBUG_ECHOLNPGM("?Invalid slot.");
  2015. DEBUG_ECHO(s);
  2016. DEBUG_ECHOLNPGM(" mesh slots available.");
  2017. #else
  2018. UNUSED(s);
  2019. #endif
  2020. }
  2021. const uint16_t MarlinSettings::meshes_end = persistentStore.capacity() - 129; // 128 (+1 because of the change to capacity rather than last valid address)
  2022. // is a placeholder for the size of the MAT; the MAT will always
  2023. // live at the very end of the eeprom
  2024. uint16_t MarlinSettings::meshes_start_index() {
  2025. return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8; // Pad the end of configuration data so it can float up
  2026. // or down a little bit without disrupting the mesh data
  2027. }
  2028. uint16_t MarlinSettings::calc_num_meshes() {
  2029. return (meshes_end - meshes_start_index()) / sizeof(ubl.z_values);
  2030. }
  2031. int MarlinSettings::mesh_slot_offset(const int8_t slot) {
  2032. return meshes_end - (slot + 1) * sizeof(ubl.z_values);
  2033. }
  2034. void MarlinSettings::store_mesh(const int8_t slot) {
  2035. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2036. const int16_t a = calc_num_meshes();
  2037. if (!WITHIN(slot, 0, a - 1)) {
  2038. ubl_invalid_slot(a);
  2039. DEBUG_ECHOLNPAIR("E2END=", persistentStore.capacity() - 1, " meshes_end=", meshes_end, " slot=", slot);
  2040. DEBUG_EOL();
  2041. return;
  2042. }
  2043. int pos = mesh_slot_offset(slot);
  2044. uint16_t crc = 0;
  2045. // Write crc to MAT along with other data, or just tack on to the beginning or end
  2046. persistentStore.access_start();
  2047. const bool status = persistentStore.write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc);
  2048. persistentStore.access_finish();
  2049. if (status) SERIAL_ECHOLNPGM("?Unable to save mesh data.");
  2050. else DEBUG_ECHOLNPAIR("Mesh saved in slot ", slot);
  2051. #else
  2052. // Other mesh types
  2053. #endif
  2054. }
  2055. void MarlinSettings::load_mesh(const int8_t slot, void * const into/*=nullptr*/) {
  2056. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2057. const int16_t a = settings.calc_num_meshes();
  2058. if (!WITHIN(slot, 0, a - 1)) {
  2059. ubl_invalid_slot(a);
  2060. return;
  2061. }
  2062. int pos = mesh_slot_offset(slot);
  2063. uint16_t crc = 0;
  2064. uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
  2065. persistentStore.access_start();
  2066. const uint16_t status = persistentStore.read_data(pos, dest, sizeof(ubl.z_values), &crc);
  2067. persistentStore.access_finish();
  2068. if (status) SERIAL_ECHOLNPGM("?Unable to load mesh data.");
  2069. else DEBUG_ECHOLNPAIR("Mesh loaded from slot ", slot);
  2070. EEPROM_FINISH();
  2071. #else
  2072. // Other mesh types
  2073. #endif
  2074. }
  2075. //void MarlinSettings::delete_mesh() { return; }
  2076. //void MarlinSettings::defrag_meshes() { return; }
  2077. #endif // AUTO_BED_LEVELING_UBL
  2078. #else // !EEPROM_SETTINGS
  2079. bool MarlinSettings::save() {
  2080. DEBUG_ERROR_MSG("EEPROM disabled");
  2081. return false;
  2082. }
  2083. #endif // !EEPROM_SETTINGS
  2084. /**
  2085. * M502 - Reset Configuration
  2086. */
  2087. void MarlinSettings::reset() {
  2088. LOOP_XYZE_N(i) {
  2089. planner.settings.max_acceleration_mm_per_s2[i] = pgm_read_dword(&_DMA[ALIM(i, _DMA)]);
  2090. planner.settings.axis_steps_per_mm[i] = pgm_read_float(&_DASU[ALIM(i, _DASU)]);
  2091. planner.settings.max_feedrate_mm_s[i] = pgm_read_float(&_DMF[ALIM(i, _DMF)]);
  2092. }
  2093. planner.settings.min_segment_time_us = DEFAULT_MINSEGMENTTIME;
  2094. planner.settings.acceleration = DEFAULT_ACCELERATION;
  2095. planner.settings.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
  2096. planner.settings.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
  2097. planner.settings.min_feedrate_mm_s = feedRate_t(DEFAULT_MINIMUMFEEDRATE);
  2098. planner.settings.min_travel_feedrate_mm_s = feedRate_t(DEFAULT_MINTRAVELFEEDRATE);
  2099. #if HAS_CLASSIC_JERK
  2100. #ifndef DEFAULT_XJERK
  2101. #define DEFAULT_XJERK 0
  2102. #endif
  2103. #ifndef DEFAULT_YJERK
  2104. #define DEFAULT_YJERK 0
  2105. #endif
  2106. #ifndef DEFAULT_ZJERK
  2107. #define DEFAULT_ZJERK 0
  2108. #endif
  2109. planner.max_jerk.set(DEFAULT_XJERK, DEFAULT_YJERK, DEFAULT_ZJERK);
  2110. TERN_(HAS_CLASSIC_E_JERK, planner.max_jerk.e = DEFAULT_EJERK;);
  2111. #endif
  2112. #if HAS_JUNCTION_DEVIATION
  2113. planner.junction_deviation_mm = float(JUNCTION_DEVIATION_MM);
  2114. #endif
  2115. #if HAS_SCARA_OFFSET
  2116. scara_home_offset.reset();
  2117. #elif HAS_HOME_OFFSET
  2118. home_offset.reset();
  2119. #endif
  2120. TERN_(HAS_HOTEND_OFFSET, reset_hotend_offsets());
  2121. //
  2122. // Filament Runout Sensor
  2123. //
  2124. #if HAS_FILAMENT_SENSOR
  2125. runout.enabled = true;
  2126. runout.reset();
  2127. TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM));
  2128. #endif
  2129. //
  2130. // Tool-change Settings
  2131. //
  2132. #if EXTRUDERS > 1
  2133. #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
  2134. toolchange_settings.swap_length = TOOLCHANGE_FS_LENGTH;
  2135. toolchange_settings.extra_resume = TOOLCHANGE_FS_EXTRA_RESUME_LENGTH;
  2136. toolchange_settings.retract_speed = TOOLCHANGE_FS_RETRACT_SPEED;
  2137. toolchange_settings.unretract_speed = TOOLCHANGE_FS_UNRETRACT_SPEED;
  2138. toolchange_settings.extra_prime = TOOLCHANGE_FS_EXTRA_PRIME;
  2139. toolchange_settings.prime_speed = TOOLCHANGE_FS_PRIME_SPEED;
  2140. toolchange_settings.fan_speed = TOOLCHANGE_FS_FAN_SPEED;
  2141. toolchange_settings.fan_time = TOOLCHANGE_FS_FAN_TIME;
  2142. #endif
  2143. #if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
  2144. enable_first_prime = false;
  2145. #endif
  2146. #if ENABLED(TOOLCHANGE_PARK)
  2147. constexpr xyz_pos_t tpxy = TOOLCHANGE_PARK_XY;
  2148. toolchange_settings.enable_park = true;
  2149. toolchange_settings.change_point = tpxy;
  2150. #endif
  2151. toolchange_settings.z_raise = TOOLCHANGE_ZRAISE;
  2152. #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
  2153. migration = migration_defaults;
  2154. #endif
  2155. #endif
  2156. #if ENABLED(BACKLASH_GCODE)
  2157. backlash.correction = (BACKLASH_CORRECTION) * 255;
  2158. constexpr xyz_float_t tmp = BACKLASH_DISTANCE_MM;
  2159. backlash.distance_mm = tmp;
  2160. #ifdef BACKLASH_SMOOTHING_MM
  2161. backlash.smoothing_mm = BACKLASH_SMOOTHING_MM;
  2162. #endif
  2163. #endif
  2164. TERN_(EXTENSIBLE_UI, ExtUI::onFactoryReset());
  2165. //
  2166. // Case Light Brightness
  2167. //
  2168. TERN_(HAS_CASE_LIGHT_BRIGHTNESS, case_light_brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS);
  2169. //
  2170. // Magnetic Parking Extruder
  2171. //
  2172. TERN_(MAGNETIC_PARKING_EXTRUDER, mpe_settings_init());
  2173. //
  2174. // Global Leveling
  2175. //
  2176. TERN_(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height = 0.0);
  2177. TERN_(HAS_LEVELING, reset_bed_level());
  2178. #if HAS_BED_PROBE
  2179. constexpr float dpo[] = NOZZLE_TO_PROBE_OFFSET;
  2180. static_assert(COUNT(dpo) == 3, "NOZZLE_TO_PROBE_OFFSET must contain offsets for X, Y, and Z.");
  2181. #if HAS_PROBE_XY_OFFSET
  2182. LOOP_XYZ(a) probe.offset[a] = dpo[a];
  2183. #else
  2184. probe.offset.x = probe.offset.y = 0;
  2185. probe.offset.z = dpo[Z_AXIS];
  2186. #endif
  2187. #endif
  2188. //
  2189. // Z Stepper Auto-alignment points
  2190. //
  2191. TERN_(Z_STEPPER_AUTO_ALIGN, z_stepper_align.reset_to_default());
  2192. //
  2193. // Servo Angles
  2194. //
  2195. TERN_(EDITABLE_SERVO_ANGLES, COPY(servo_angles, base_servo_angles)); // When not editable only one copy of servo angles exists
  2196. //
  2197. // BLTOUCH
  2198. //
  2199. //#if ENABLED(BLTOUCH)
  2200. // bltouch.last_written_mode;
  2201. //#endif
  2202. //
  2203. // Endstop Adjustments
  2204. //
  2205. #if ENABLED(DELTA)
  2206. const abc_float_t adj = DELTA_ENDSTOP_ADJ, dta = DELTA_TOWER_ANGLE_TRIM;
  2207. delta_height = DELTA_HEIGHT;
  2208. delta_endstop_adj = adj;
  2209. delta_radius = DELTA_RADIUS;
  2210. delta_diagonal_rod = DELTA_DIAGONAL_ROD;
  2211. delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
  2212. delta_tower_angle_trim = dta;
  2213. #endif
  2214. #if ENABLED(X_DUAL_ENDSTOPS)
  2215. #ifndef X2_ENDSTOP_ADJUSTMENT
  2216. #define X2_ENDSTOP_ADJUSTMENT 0
  2217. #endif
  2218. endstops.x2_endstop_adj = X2_ENDSTOP_ADJUSTMENT;
  2219. #endif
  2220. #if ENABLED(Y_DUAL_ENDSTOPS)
  2221. #ifndef Y2_ENDSTOP_ADJUSTMENT
  2222. #define Y2_ENDSTOP_ADJUSTMENT 0
  2223. #endif
  2224. endstops.y2_endstop_adj = Y2_ENDSTOP_ADJUSTMENT;
  2225. #endif
  2226. #if ENABLED(Z_MULTI_ENDSTOPS)
  2227. #ifndef Z2_ENDSTOP_ADJUSTMENT
  2228. #define Z2_ENDSTOP_ADJUSTMENT 0
  2229. #endif
  2230. endstops.z2_endstop_adj = Z2_ENDSTOP_ADJUSTMENT;
  2231. #if NUM_Z_STEPPER_DRIVERS >= 3
  2232. #ifndef Z3_ENDSTOP_ADJUSTMENT
  2233. #define Z3_ENDSTOP_ADJUSTMENT 0
  2234. #endif
  2235. endstops.z3_endstop_adj = Z3_ENDSTOP_ADJUSTMENT;
  2236. #endif
  2237. #if NUM_Z_STEPPER_DRIVERS >= 4
  2238. #ifndef Z4_ENDSTOP_ADJUSTMENT
  2239. #define Z4_ENDSTOP_ADJUSTMENT 0
  2240. #endif
  2241. endstops.z4_endstop_adj = Z4_ENDSTOP_ADJUSTMENT;
  2242. #endif
  2243. #endif
  2244. //
  2245. // Preheat parameters
  2246. //
  2247. #if HAS_HOTEND
  2248. #if ENABLED(DWIN_CREALITY_LCD)
  2249. HMI_ValueStruct.preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
  2250. HMI_ValueStruct.preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
  2251. HMI_ValueStruct.preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
  2252. HMI_ValueStruct.preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
  2253. HMI_ValueStruct.preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
  2254. HMI_ValueStruct.preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
  2255. #elif HAS_LCD_MENU
  2256. ui.preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
  2257. ui.preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
  2258. ui.preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
  2259. ui.preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
  2260. ui.preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
  2261. ui.preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
  2262. #endif
  2263. #endif
  2264. //
  2265. // Hotend PID
  2266. //
  2267. #if ENABLED(PIDTEMP)
  2268. HOTEND_LOOP() {
  2269. PID_PARAM(Kp, e) = float(DEFAULT_Kp);
  2270. PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
  2271. PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
  2272. TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = DEFAULT_Kc);
  2273. TERN_(PID_FAN_SCALING, PID_PARAM(Kf, e) = DEFAULT_Kf);
  2274. }
  2275. #endif
  2276. //
  2277. // PID Extrusion Scaling
  2278. //
  2279. TERN_(PID_EXTRUSION_SCALING, thermalManager.lpq_len = 20); // Default last-position-queue size
  2280. //
  2281. // Heated Bed PID
  2282. //
  2283. #if ENABLED(PIDTEMPBED)
  2284. thermalManager.temp_bed.pid.Kp = DEFAULT_bedKp;
  2285. thermalManager.temp_bed.pid.Ki = scalePID_i(DEFAULT_bedKi);
  2286. thermalManager.temp_bed.pid.Kd = scalePID_d(DEFAULT_bedKd);
  2287. #endif
  2288. //
  2289. // User-Defined Thermistors
  2290. //
  2291. TERN_(HAS_USER_THERMISTORS, thermalManager.reset_user_thermistors());
  2292. //
  2293. // Power Monitor
  2294. //
  2295. TERN_(POWER_MONITOR, power_monitor.reset());
  2296. //
  2297. // LCD Contrast
  2298. //
  2299. TERN_(HAS_LCD_CONTRAST, ui.set_contrast(DEFAULT_LCD_CONTRAST));
  2300. //
  2301. // Controller Fan
  2302. //
  2303. TERN_(USE_CONTROLLER_FAN, controllerFan.reset());
  2304. //
  2305. // Power-Loss Recovery
  2306. //
  2307. TERN_(POWER_LOSS_RECOVERY, recovery.enable(ENABLED(PLR_ENABLED_DEFAULT)));
  2308. //
  2309. // Firmware Retraction
  2310. //
  2311. TERN_(FWRETRACT, fwretract.reset());
  2312. //
  2313. // Volumetric & Filament Size
  2314. //
  2315. #if DISABLED(NO_VOLUMETRICS)
  2316. parser.volumetric_enabled = ENABLED(VOLUMETRIC_DEFAULT_ON);
  2317. LOOP_L_N(q, COUNT(planner.filament_size))
  2318. planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
  2319. #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
  2320. LOOP_L_N(q, COUNT(planner.volumetric_extruder_limit))
  2321. planner.volumetric_extruder_limit[q] = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
  2322. #endif
  2323. #endif
  2324. endstops.enable_globally(ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT));
  2325. reset_stepper_drivers();
  2326. //
  2327. // Linear Advance
  2328. //
  2329. #if ENABLED(LIN_ADVANCE)
  2330. LOOP_L_N(i, EXTRUDERS) {
  2331. planner.extruder_advance_K[i] = LIN_ADVANCE_K;
  2332. TERN_(EXTRA_LIN_ADVANCE_K, other_extruder_advance_K[i] = LIN_ADVANCE_K);
  2333. }
  2334. #endif
  2335. //
  2336. // Motor Current PWM
  2337. //
  2338. #if HAS_MOTOR_CURRENT_PWM
  2339. constexpr uint32_t tmp_motor_current_setting[3] = PWM_MOTOR_CURRENT;
  2340. LOOP_L_N(q, 3)
  2341. stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
  2342. #endif
  2343. //
  2344. // CNC Coordinate System
  2345. //
  2346. TERN_(CNC_COORDINATE_SYSTEMS, (void)gcode.select_coordinate_system(-1)); // Go back to machine space
  2347. //
  2348. // Skew Correction
  2349. //
  2350. #if ENABLED(SKEW_CORRECTION_GCODE)
  2351. planner.skew_factor.xy = XY_SKEW_FACTOR;
  2352. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  2353. planner.skew_factor.xz = XZ_SKEW_FACTOR;
  2354. planner.skew_factor.yz = YZ_SKEW_FACTOR;
  2355. #endif
  2356. #endif
  2357. //
  2358. // Advanced Pause filament load & unload lengths
  2359. //
  2360. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2361. LOOP_L_N(e, EXTRUDERS) {
  2362. fc_settings[e].unload_length = FILAMENT_CHANGE_UNLOAD_LENGTH;
  2363. fc_settings[e].load_length = FILAMENT_CHANGE_FAST_LOAD_LENGTH;
  2364. }
  2365. #endif
  2366. postprocess();
  2367. DEBUG_ECHO_START();
  2368. DEBUG_ECHOLNPGM("Hardcoded Default Settings Loaded");
  2369. TERN_(EXTENSIBLE_UI, ExtUI::onFactoryReset());
  2370. }
  2371. #if DISABLED(DISABLE_M503)
  2372. static void config_heading(const bool repl, PGM_P const pstr, const bool eol=true) {
  2373. if (!repl) {
  2374. SERIAL_ECHO_START();
  2375. SERIAL_ECHOPGM("; ");
  2376. serialprintPGM(pstr);
  2377. if (eol) SERIAL_EOL();
  2378. }
  2379. }
  2380. #define CONFIG_ECHO_START() do{ if (!forReplay) SERIAL_ECHO_START(); }while(0)
  2381. #define CONFIG_ECHO_MSG(STR) do{ CONFIG_ECHO_START(); SERIAL_ECHOLNPGM(STR); }while(0)
  2382. #define CONFIG_ECHO_HEADING(STR) config_heading(forReplay, PSTR(STR))
  2383. #if HAS_TRINAMIC_CONFIG
  2384. inline void say_M906(const bool forReplay) { CONFIG_ECHO_START(); SERIAL_ECHOPGM(" M906"); }
  2385. #if HAS_STEALTHCHOP
  2386. void say_M569(const bool forReplay, const char * const etc=nullptr, const bool newLine = false) {
  2387. CONFIG_ECHO_START();
  2388. SERIAL_ECHOPGM(" M569 S1");
  2389. if (etc) {
  2390. SERIAL_CHAR(' ');
  2391. serialprintPGM(etc);
  2392. }
  2393. if (newLine) SERIAL_EOL();
  2394. }
  2395. #endif
  2396. #if ENABLED(HYBRID_THRESHOLD)
  2397. inline void say_M913(const bool forReplay) { CONFIG_ECHO_START(); SERIAL_ECHOPGM(" M913"); }
  2398. #endif
  2399. #if USE_SENSORLESS
  2400. inline void say_M914() { SERIAL_ECHOPGM(" M914"); }
  2401. #endif
  2402. #endif
  2403. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2404. inline void say_M603(const bool forReplay) { CONFIG_ECHO_START(); SERIAL_ECHOPGM(" M603 "); }
  2405. #endif
  2406. inline void say_units(const bool colon) {
  2407. serialprintPGM(
  2408. #if ENABLED(INCH_MODE_SUPPORT)
  2409. parser.linear_unit_factor != 1.0 ? PSTR(" (in)") :
  2410. #endif
  2411. PSTR(" (mm)")
  2412. );
  2413. if (colon) SERIAL_ECHOLNPGM(":");
  2414. }
  2415. void report_M92(const bool echo=true, const int8_t e=-1);
  2416. /**
  2417. * M503 - Report current settings in RAM
  2418. *
  2419. * Unless specifically disabled, M503 is available even without EEPROM
  2420. */
  2421. void MarlinSettings::report(const bool forReplay) {
  2422. /**
  2423. * Announce current units, in case inches are being displayed
  2424. */
  2425. CONFIG_ECHO_START();
  2426. #if ENABLED(INCH_MODE_SUPPORT)
  2427. SERIAL_ECHOPGM(" G2");
  2428. SERIAL_CHAR(parser.linear_unit_factor == 1.0 ? '1' : '0');
  2429. SERIAL_ECHOPGM(" ;");
  2430. say_units(false);
  2431. #else
  2432. SERIAL_ECHOPGM(" G21 ; Units in mm");
  2433. say_units(false);
  2434. #endif
  2435. SERIAL_EOL();
  2436. #if HAS_LCD_MENU
  2437. // Temperature units - for Ultipanel temperature options
  2438. CONFIG_ECHO_START();
  2439. #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
  2440. SERIAL_ECHOPGM(" M149 ");
  2441. SERIAL_CHAR(parser.temp_units_code());
  2442. SERIAL_ECHOPGM(" ; Units in ");
  2443. serialprintPGM(parser.temp_units_name());
  2444. #else
  2445. SERIAL_ECHOLNPGM(" M149 C ; Units in Celsius");
  2446. #endif
  2447. #endif
  2448. SERIAL_EOL();
  2449. #if EXTRUDERS && DISABLED(NO_VOLUMETRICS)
  2450. /**
  2451. * Volumetric extrusion M200
  2452. */
  2453. if (!forReplay) {
  2454. config_heading(forReplay, PSTR("Filament settings:"), false);
  2455. if (parser.volumetric_enabled)
  2456. SERIAL_EOL();
  2457. else
  2458. SERIAL_ECHOLNPGM(" Disabled");
  2459. }
  2460. #if EXTRUDERS == 1
  2461. CONFIG_ECHO_START();
  2462. SERIAL_ECHOLNPAIR(" M200 S", int(parser.volumetric_enabled)
  2463. , " D", LINEAR_UNIT(planner.filament_size[0])
  2464. #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
  2465. , " L", LINEAR_UNIT(planner.volumetric_extruder_limit[0])
  2466. #endif
  2467. );
  2468. #else
  2469. LOOP_L_N(i, EXTRUDERS) {
  2470. CONFIG_ECHO_START();
  2471. SERIAL_ECHOLNPAIR(" M200 T", int(i)
  2472. , " D", LINEAR_UNIT(planner.filament_size[i])
  2473. #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
  2474. , " L", LINEAR_UNIT(planner.volumetric_extruder_limit[i])
  2475. #endif
  2476. );
  2477. }
  2478. CONFIG_ECHO_START();
  2479. SERIAL_ECHOLNPAIR(" M200 S", int(parser.volumetric_enabled));
  2480. #endif
  2481. #endif // EXTRUDERS && !NO_VOLUMETRICS
  2482. CONFIG_ECHO_HEADING("Steps per unit:");
  2483. report_M92(!forReplay);
  2484. CONFIG_ECHO_HEADING("Maximum feedrates (units/s):");
  2485. CONFIG_ECHO_START();
  2486. SERIAL_ECHOLNPAIR_P(
  2487. PSTR(" M203 X"), LINEAR_UNIT(planner.settings.max_feedrate_mm_s[X_AXIS])
  2488. , SP_Y_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[Y_AXIS])
  2489. , SP_Z_STR, LINEAR_UNIT(planner.settings.max_feedrate_mm_s[Z_AXIS])
  2490. #if DISABLED(DISTINCT_E_FACTORS)
  2491. , SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_feedrate_mm_s[E_AXIS])
  2492. #endif
  2493. );
  2494. #if ENABLED(DISTINCT_E_FACTORS)
  2495. LOOP_L_N(i, E_STEPPERS) {
  2496. CONFIG_ECHO_START();
  2497. SERIAL_ECHOLNPAIR_P(
  2498. PSTR(" M203 T"), (int)i
  2499. , SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_feedrate_mm_s[E_AXIS_N(i)])
  2500. );
  2501. }
  2502. #endif
  2503. CONFIG_ECHO_HEADING("Maximum Acceleration (units/s2):");
  2504. CONFIG_ECHO_START();
  2505. SERIAL_ECHOLNPAIR_P(
  2506. PSTR(" M201 X"), LINEAR_UNIT(planner.settings.max_acceleration_mm_per_s2[X_AXIS])
  2507. , SP_Y_STR, LINEAR_UNIT(planner.settings.max_acceleration_mm_per_s2[Y_AXIS])
  2508. , SP_Z_STR, LINEAR_UNIT(planner.settings.max_acceleration_mm_per_s2[Z_AXIS])
  2509. #if DISABLED(DISTINCT_E_FACTORS)
  2510. , SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_acceleration_mm_per_s2[E_AXIS])
  2511. #endif
  2512. );
  2513. #if ENABLED(DISTINCT_E_FACTORS)
  2514. LOOP_L_N(i, E_STEPPERS) {
  2515. CONFIG_ECHO_START();
  2516. SERIAL_ECHOLNPAIR_P(
  2517. PSTR(" M201 T"), (int)i
  2518. , SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(i)])
  2519. );
  2520. }
  2521. #endif
  2522. CONFIG_ECHO_HEADING("Acceleration (units/s2): P<print_accel> R<retract_accel> T<travel_accel>");
  2523. CONFIG_ECHO_START();
  2524. SERIAL_ECHOLNPAIR_P(
  2525. PSTR(" M204 P"), LINEAR_UNIT(planner.settings.acceleration)
  2526. , PSTR(" R"), LINEAR_UNIT(planner.settings.retract_acceleration)
  2527. , SP_T_STR, LINEAR_UNIT(planner.settings.travel_acceleration)
  2528. );
  2529. CONFIG_ECHO_HEADING(
  2530. "Advanced: B<min_segment_time_us> S<min_feedrate> T<min_travel_feedrate>"
  2531. #if HAS_JUNCTION_DEVIATION
  2532. " J<junc_dev>"
  2533. #endif
  2534. #if HAS_CLASSIC_JERK
  2535. " X<max_x_jerk> Y<max_y_jerk> Z<max_z_jerk>"
  2536. TERN_(HAS_CLASSIC_E_JERK, " E<max_e_jerk>")
  2537. #endif
  2538. );
  2539. CONFIG_ECHO_START();
  2540. SERIAL_ECHOLNPAIR_P(
  2541. PSTR(" M205 B"), LINEAR_UNIT(planner.settings.min_segment_time_us)
  2542. , PSTR(" S"), LINEAR_UNIT(planner.settings.min_feedrate_mm_s)
  2543. , SP_T_STR, LINEAR_UNIT(planner.settings.min_travel_feedrate_mm_s)
  2544. #if HAS_JUNCTION_DEVIATION
  2545. , PSTR(" J"), LINEAR_UNIT(planner.junction_deviation_mm)
  2546. #endif
  2547. #if HAS_CLASSIC_JERK
  2548. , SP_X_STR, LINEAR_UNIT(planner.max_jerk.x)
  2549. , SP_Y_STR, LINEAR_UNIT(planner.max_jerk.y)
  2550. , SP_Z_STR, LINEAR_UNIT(planner.max_jerk.z)
  2551. #if HAS_CLASSIC_E_JERK
  2552. , SP_E_STR, LINEAR_UNIT(planner.max_jerk.e)
  2553. #endif
  2554. #endif
  2555. );
  2556. #if HAS_M206_COMMAND
  2557. CONFIG_ECHO_HEADING("Home offset:");
  2558. CONFIG_ECHO_START();
  2559. SERIAL_ECHOLNPAIR_P(
  2560. #if IS_CARTESIAN
  2561. PSTR(" M206 X"), LINEAR_UNIT(home_offset.x)
  2562. , SP_Y_STR, LINEAR_UNIT(home_offset.y)
  2563. , SP_Z_STR
  2564. #else
  2565. PSTR(" M206 Z")
  2566. #endif
  2567. , LINEAR_UNIT(home_offset.z)
  2568. );
  2569. #endif
  2570. #if HAS_HOTEND_OFFSET
  2571. CONFIG_ECHO_HEADING("Hotend offsets:");
  2572. CONFIG_ECHO_START();
  2573. LOOP_S_L_N(e, 1, HOTENDS) {
  2574. SERIAL_ECHOPAIR_P(
  2575. PSTR(" M218 T"), (int)e,
  2576. SP_X_STR, LINEAR_UNIT(hotend_offset[e].x),
  2577. SP_Y_STR, LINEAR_UNIT(hotend_offset[e].y)
  2578. );
  2579. SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(hotend_offset[e].z), 3);
  2580. }
  2581. #endif
  2582. /**
  2583. * Bed Leveling
  2584. */
  2585. #if HAS_LEVELING
  2586. #if ENABLED(MESH_BED_LEVELING)
  2587. CONFIG_ECHO_HEADING("Mesh Bed Leveling:");
  2588. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  2589. config_heading(forReplay, PSTR(""), false);
  2590. if (!forReplay) {
  2591. ubl.echo_name();
  2592. SERIAL_CHAR(':');
  2593. SERIAL_EOL();
  2594. }
  2595. #elif HAS_ABL_OR_UBL
  2596. CONFIG_ECHO_HEADING("Auto Bed Leveling:");
  2597. #endif
  2598. CONFIG_ECHO_START();
  2599. SERIAL_ECHOLNPAIR_P(
  2600. PSTR(" M420 S"), planner.leveling_active ? 1 : 0
  2601. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  2602. , SP_Z_STR, LINEAR_UNIT(planner.z_fade_height)
  2603. #endif
  2604. );
  2605. #if ENABLED(MESH_BED_LEVELING)
  2606. if (leveling_is_valid()) {
  2607. LOOP_L_N(py, GRID_MAX_POINTS_Y) {
  2608. LOOP_L_N(px, GRID_MAX_POINTS_X) {
  2609. CONFIG_ECHO_START();
  2610. SERIAL_ECHOPAIR_P(PSTR(" G29 S3 I"), (int)px, PSTR(" J"), (int)py);
  2611. SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(mbl.z_values[px][py]), 5);
  2612. }
  2613. }
  2614. CONFIG_ECHO_START();
  2615. SERIAL_ECHOLNPAIR_F_P(PSTR(" G29 S4 Z"), LINEAR_UNIT(mbl.z_offset), 5);
  2616. }
  2617. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  2618. if (!forReplay) {
  2619. SERIAL_EOL();
  2620. ubl.report_state();
  2621. SERIAL_EOL();
  2622. config_heading(false, PSTR("Active Mesh Slot: "), false);
  2623. SERIAL_ECHOLN(ubl.storage_slot);
  2624. config_heading(false, PSTR("EEPROM can hold "), false);
  2625. SERIAL_ECHO(calc_num_meshes());
  2626. SERIAL_ECHOLNPGM(" meshes.\n");
  2627. }
  2628. //ubl.report_current_mesh(); // This is too verbose for large meshes. A better (more terse)
  2629. // solution needs to be found.
  2630. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  2631. if (leveling_is_valid()) {
  2632. LOOP_L_N(py, GRID_MAX_POINTS_Y) {
  2633. LOOP_L_N(px, GRID_MAX_POINTS_X) {
  2634. CONFIG_ECHO_START();
  2635. SERIAL_ECHOPAIR(" G29 W I", (int)px, " J", (int)py);
  2636. SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(z_values[px][py]), 5);
  2637. }
  2638. }
  2639. }
  2640. #endif
  2641. #endif // HAS_LEVELING
  2642. #if ENABLED(EDITABLE_SERVO_ANGLES)
  2643. CONFIG_ECHO_HEADING("Servo Angles:");
  2644. LOOP_L_N(i, NUM_SERVOS) {
  2645. switch (i) {
  2646. #if ENABLED(SWITCHING_EXTRUDER)
  2647. case SWITCHING_EXTRUDER_SERVO_NR:
  2648. #if EXTRUDERS > 3
  2649. case SWITCHING_EXTRUDER_E23_SERVO_NR:
  2650. #endif
  2651. #elif ENABLED(SWITCHING_NOZZLE)
  2652. case SWITCHING_NOZZLE_SERVO_NR:
  2653. #elif ENABLED(BLTOUCH) || (HAS_Z_SERVO_PROBE && defined(Z_SERVO_ANGLES))
  2654. case Z_PROBE_SERVO_NR:
  2655. #endif
  2656. CONFIG_ECHO_START();
  2657. SERIAL_ECHOLNPAIR(" M281 P", int(i), " L", servo_angles[i][0], " U", servo_angles[i][1]);
  2658. default: break;
  2659. }
  2660. }
  2661. #endif // EDITABLE_SERVO_ANGLES
  2662. #if HAS_SCARA_OFFSET
  2663. CONFIG_ECHO_HEADING("SCARA settings: S<seg-per-sec> P<theta-psi-offset> T<theta-offset>");
  2664. CONFIG_ECHO_START();
  2665. SERIAL_ECHOLNPAIR_P(
  2666. PSTR(" M665 S"), delta_segments_per_second
  2667. , SP_P_STR, scara_home_offset.a
  2668. , SP_T_STR, scara_home_offset.b
  2669. , SP_Z_STR, LINEAR_UNIT(scara_home_offset.z)
  2670. );
  2671. #elif ENABLED(DELTA)
  2672. CONFIG_ECHO_HEADING("Endstop adjustment:");
  2673. CONFIG_ECHO_START();
  2674. SERIAL_ECHOLNPAIR_P(
  2675. PSTR(" M666 X"), LINEAR_UNIT(delta_endstop_adj.a)
  2676. , SP_Y_STR, LINEAR_UNIT(delta_endstop_adj.b)
  2677. , SP_Z_STR, LINEAR_UNIT(delta_endstop_adj.c)
  2678. );
  2679. CONFIG_ECHO_HEADING("Delta settings: L<diagonal_rod> R<radius> H<height> S<segments_per_s> XYZ<tower angle corrections>");
  2680. CONFIG_ECHO_START();
  2681. SERIAL_ECHOLNPAIR_P(
  2682. PSTR(" M665 L"), LINEAR_UNIT(delta_diagonal_rod)
  2683. , PSTR(" R"), LINEAR_UNIT(delta_radius)
  2684. , PSTR(" H"), LINEAR_UNIT(delta_height)
  2685. , PSTR(" S"), delta_segments_per_second
  2686. , SP_X_STR, LINEAR_UNIT(delta_tower_angle_trim.a)
  2687. , SP_Y_STR, LINEAR_UNIT(delta_tower_angle_trim.b)
  2688. , SP_Z_STR, LINEAR_UNIT(delta_tower_angle_trim.c)
  2689. );
  2690. #elif HAS_EXTRA_ENDSTOPS
  2691. CONFIG_ECHO_HEADING("Endstop adjustment:");
  2692. CONFIG_ECHO_START();
  2693. SERIAL_ECHOPGM(" M666");
  2694. #if ENABLED(X_DUAL_ENDSTOPS)
  2695. SERIAL_ECHOLNPAIR_P(SP_X_STR, LINEAR_UNIT(endstops.x2_endstop_adj));
  2696. #endif
  2697. #if ENABLED(Y_DUAL_ENDSTOPS)
  2698. SERIAL_ECHOLNPAIR_P(SP_Y_STR, LINEAR_UNIT(endstops.y2_endstop_adj));
  2699. #endif
  2700. #if ENABLED(Z_MULTI_ENDSTOPS)
  2701. #if NUM_Z_STEPPER_DRIVERS >= 3
  2702. SERIAL_ECHOPAIR(" S2 Z", LINEAR_UNIT(endstops.z3_endstop_adj));
  2703. CONFIG_ECHO_START();
  2704. SERIAL_ECHOPAIR(" M666 S3 Z", LINEAR_UNIT(endstops.z3_endstop_adj));
  2705. #if NUM_Z_STEPPER_DRIVERS >= 4
  2706. CONFIG_ECHO_START();
  2707. SERIAL_ECHOPAIR(" M666 S4 Z", LINEAR_UNIT(endstops.z4_endstop_adj));
  2708. #endif
  2709. #else
  2710. SERIAL_ECHOLNPAIR_P(SP_Z_STR, LINEAR_UNIT(endstops.z2_endstop_adj));
  2711. #endif
  2712. #endif
  2713. #endif // [XYZ]_DUAL_ENDSTOPS
  2714. #if HAS_HOTEND && HAS_LCD_MENU
  2715. CONFIG_ECHO_HEADING("Material heatup parameters:");
  2716. LOOP_L_N(i, COUNT(ui.preheat_hotend_temp)) {
  2717. CONFIG_ECHO_START();
  2718. SERIAL_ECHOLNPAIR(
  2719. " M145 S", (int)i
  2720. , " H", TEMP_UNIT(ui.preheat_hotend_temp[i])
  2721. , " B", TEMP_UNIT(ui.preheat_bed_temp[i])
  2722. , " F", int(ui.preheat_fan_speed[i])
  2723. );
  2724. }
  2725. #endif
  2726. #if HAS_PID_HEATING
  2727. CONFIG_ECHO_HEADING("PID settings:");
  2728. #if ENABLED(PIDTEMP)
  2729. HOTEND_LOOP() {
  2730. CONFIG_ECHO_START();
  2731. SERIAL_ECHOPAIR_P(
  2732. #if BOTH(HAS_MULTI_HOTEND, PID_PARAMS_PER_HOTEND)
  2733. PSTR(" M301 E"), e,
  2734. SP_P_STR
  2735. #else
  2736. PSTR(" M301 P")
  2737. #endif
  2738. , PID_PARAM(Kp, e)
  2739. , PSTR(" I"), unscalePID_i(PID_PARAM(Ki, e))
  2740. , PSTR(" D"), unscalePID_d(PID_PARAM(Kd, e))
  2741. );
  2742. #if ENABLED(PID_EXTRUSION_SCALING)
  2743. SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, e));
  2744. if (e == 0) SERIAL_ECHOPAIR(" L", thermalManager.lpq_len);
  2745. #endif
  2746. #if ENABLED(PID_FAN_SCALING)
  2747. SERIAL_ECHOPAIR(" F", PID_PARAM(Kf, e));
  2748. #endif
  2749. SERIAL_EOL();
  2750. }
  2751. #endif // PIDTEMP
  2752. #if ENABLED(PIDTEMPBED)
  2753. CONFIG_ECHO_START();
  2754. SERIAL_ECHOLNPAIR(
  2755. " M304 P", thermalManager.temp_bed.pid.Kp
  2756. , " I", unscalePID_i(thermalManager.temp_bed.pid.Ki)
  2757. , " D", unscalePID_d(thermalManager.temp_bed.pid.Kd)
  2758. );
  2759. #endif
  2760. #endif // PIDTEMP || PIDTEMPBED
  2761. #if HAS_USER_THERMISTORS
  2762. CONFIG_ECHO_HEADING("User thermistors:");
  2763. LOOP_L_N(i, USER_THERMISTORS)
  2764. thermalManager.log_user_thermistor(i, true);
  2765. #endif
  2766. #if HAS_LCD_CONTRAST
  2767. CONFIG_ECHO_HEADING("LCD Contrast:");
  2768. CONFIG_ECHO_START();
  2769. SERIAL_ECHOLNPAIR(" M250 C", ui.contrast);
  2770. #endif
  2771. TERN_(CONTROLLER_FAN_EDITABLE, M710_report(forReplay));
  2772. #if ENABLED(POWER_LOSS_RECOVERY)
  2773. CONFIG_ECHO_HEADING("Power-Loss Recovery:");
  2774. CONFIG_ECHO_START();
  2775. SERIAL_ECHOLNPAIR(" M413 S", int(recovery.enabled));
  2776. #endif
  2777. #if ENABLED(FWRETRACT)
  2778. CONFIG_ECHO_HEADING("Retract: S<length> F<units/m> Z<lift>");
  2779. CONFIG_ECHO_START();
  2780. SERIAL_ECHOLNPAIR_P(
  2781. PSTR(" M207 S"), LINEAR_UNIT(fwretract.settings.retract_length)
  2782. , PSTR(" W"), LINEAR_UNIT(fwretract.settings.swap_retract_length)
  2783. , PSTR(" F"), LINEAR_UNIT(MMS_TO_MMM(fwretract.settings.retract_feedrate_mm_s))
  2784. , SP_Z_STR, LINEAR_UNIT(fwretract.settings.retract_zraise)
  2785. );
  2786. CONFIG_ECHO_HEADING("Recover: S<length> F<units/m>");
  2787. CONFIG_ECHO_START();
  2788. SERIAL_ECHOLNPAIR(
  2789. " M208 S", LINEAR_UNIT(fwretract.settings.retract_recover_extra)
  2790. , " W", LINEAR_UNIT(fwretract.settings.swap_retract_recover_extra)
  2791. , " F", LINEAR_UNIT(MMS_TO_MMM(fwretract.settings.retract_recover_feedrate_mm_s))
  2792. );
  2793. #if ENABLED(FWRETRACT_AUTORETRACT)
  2794. CONFIG_ECHO_HEADING("Auto-Retract: S=0 to disable, 1 to interpret E-only moves as retract/recover");
  2795. CONFIG_ECHO_START();
  2796. SERIAL_ECHOLNPAIR(" M209 S", fwretract.autoretract_enabled ? 1 : 0);
  2797. #endif // FWRETRACT_AUTORETRACT
  2798. #endif // FWRETRACT
  2799. /**
  2800. * Probe Offset
  2801. */
  2802. #if HAS_BED_PROBE
  2803. config_heading(forReplay, PSTR("Z-Probe Offset"), false);
  2804. if (!forReplay) say_units(true);
  2805. CONFIG_ECHO_START();
  2806. SERIAL_ECHOLNPAIR_P(
  2807. #if HAS_PROBE_XY_OFFSET
  2808. PSTR(" M851 X"), LINEAR_UNIT(probe.offset_xy.x),
  2809. SP_Y_STR, LINEAR_UNIT(probe.offset_xy.y),
  2810. SP_Z_STR
  2811. #else
  2812. PSTR(" M851 X0 Y0 Z")
  2813. #endif
  2814. , LINEAR_UNIT(probe.offset.z)
  2815. );
  2816. #endif
  2817. /**
  2818. * Bed Skew Correction
  2819. */
  2820. #if ENABLED(SKEW_CORRECTION_GCODE)
  2821. CONFIG_ECHO_HEADING("Skew Factor: ");
  2822. CONFIG_ECHO_START();
  2823. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  2824. SERIAL_ECHOPAIR_F(" M852 I", LINEAR_UNIT(planner.skew_factor.xy), 6);
  2825. SERIAL_ECHOPAIR_F(" J", LINEAR_UNIT(planner.skew_factor.xz), 6);
  2826. SERIAL_ECHOLNPAIR_F(" K", LINEAR_UNIT(planner.skew_factor.yz), 6);
  2827. #else
  2828. SERIAL_ECHOLNPAIR_F(" M852 S", LINEAR_UNIT(planner.skew_factor.xy), 6);
  2829. #endif
  2830. #endif
  2831. #if HAS_TRINAMIC_CONFIG
  2832. /**
  2833. * TMC stepper driver current
  2834. */
  2835. CONFIG_ECHO_HEADING("Stepper driver current:");
  2836. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
  2837. say_M906(forReplay);
  2838. #if AXIS_IS_TMC(X)
  2839. SERIAL_ECHOPAIR_P(SP_X_STR, stepperX.getMilliamps());
  2840. #endif
  2841. #if AXIS_IS_TMC(Y)
  2842. SERIAL_ECHOPAIR_P(SP_Y_STR, stepperY.getMilliamps());
  2843. #endif
  2844. #if AXIS_IS_TMC(Z)
  2845. SERIAL_ECHOPAIR_P(SP_Z_STR, stepperZ.getMilliamps());
  2846. #endif
  2847. SERIAL_EOL();
  2848. #endif
  2849. #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
  2850. say_M906(forReplay);
  2851. SERIAL_ECHOPGM(" I1");
  2852. #if AXIS_IS_TMC(X2)
  2853. SERIAL_ECHOPAIR_P(SP_X_STR, stepperX2.getMilliamps());
  2854. #endif
  2855. #if AXIS_IS_TMC(Y2)
  2856. SERIAL_ECHOPAIR_P(SP_Y_STR, stepperY2.getMilliamps());
  2857. #endif
  2858. #if AXIS_IS_TMC(Z2)
  2859. SERIAL_ECHOPAIR_P(SP_Z_STR, stepperZ2.getMilliamps());
  2860. #endif
  2861. SERIAL_EOL();
  2862. #endif
  2863. #if AXIS_IS_TMC(Z3)
  2864. say_M906(forReplay);
  2865. SERIAL_ECHOLNPAIR(" I2 Z", stepperZ3.getMilliamps());
  2866. #endif
  2867. #if AXIS_IS_TMC(Z4)
  2868. say_M906(forReplay);
  2869. SERIAL_ECHOLNPAIR(" I3 Z", stepperZ4.getMilliamps());
  2870. #endif
  2871. #if AXIS_IS_TMC(E0)
  2872. say_M906(forReplay);
  2873. SERIAL_ECHOLNPAIR(" T0 E", stepperE0.getMilliamps());
  2874. #endif
  2875. #if AXIS_IS_TMC(E1)
  2876. say_M906(forReplay);
  2877. SERIAL_ECHOLNPAIR(" T1 E", stepperE1.getMilliamps());
  2878. #endif
  2879. #if AXIS_IS_TMC(E2)
  2880. say_M906(forReplay);
  2881. SERIAL_ECHOLNPAIR(" T2 E", stepperE2.getMilliamps());
  2882. #endif
  2883. #if AXIS_IS_TMC(E3)
  2884. say_M906(forReplay);
  2885. SERIAL_ECHOLNPAIR(" T3 E", stepperE3.getMilliamps());
  2886. #endif
  2887. #if AXIS_IS_TMC(E4)
  2888. say_M906(forReplay);
  2889. SERIAL_ECHOLNPAIR(" T4 E", stepperE4.getMilliamps());
  2890. #endif
  2891. #if AXIS_IS_TMC(E5)
  2892. say_M906(forReplay);
  2893. SERIAL_ECHOLNPAIR(" T5 E", stepperE5.getMilliamps());
  2894. #endif
  2895. #if AXIS_IS_TMC(E6)
  2896. say_M906(forReplay);
  2897. SERIAL_ECHOLNPAIR(" T6 E", stepperE6.getMilliamps());
  2898. #endif
  2899. #if AXIS_IS_TMC(E7)
  2900. say_M906(forReplay);
  2901. SERIAL_ECHOLNPAIR(" T7 E", stepperE7.getMilliamps());
  2902. #endif
  2903. SERIAL_EOL();
  2904. /**
  2905. * TMC Hybrid Threshold
  2906. */
  2907. #if ENABLED(HYBRID_THRESHOLD)
  2908. CONFIG_ECHO_HEADING("Hybrid Threshold:");
  2909. #if AXIS_HAS_STEALTHCHOP(X) || AXIS_HAS_STEALTHCHOP(Y) || AXIS_HAS_STEALTHCHOP(Z)
  2910. say_M913(forReplay);
  2911. #if AXIS_HAS_STEALTHCHOP(X)
  2912. SERIAL_ECHOPAIR_P(SP_X_STR, stepperX.get_pwm_thrs());
  2913. #endif
  2914. #if AXIS_HAS_STEALTHCHOP(Y)
  2915. SERIAL_ECHOPAIR_P(SP_Y_STR, stepperY.get_pwm_thrs());
  2916. #endif
  2917. #if AXIS_HAS_STEALTHCHOP(Z)
  2918. SERIAL_ECHOPAIR_P(SP_Z_STR, stepperZ.get_pwm_thrs());
  2919. #endif
  2920. SERIAL_EOL();
  2921. #endif
  2922. #if AXIS_HAS_STEALTHCHOP(X2) || AXIS_HAS_STEALTHCHOP(Y2) || AXIS_HAS_STEALTHCHOP(Z2)
  2923. say_M913(forReplay);
  2924. SERIAL_ECHOPGM(" I1");
  2925. #if AXIS_HAS_STEALTHCHOP(X2)
  2926. SERIAL_ECHOPAIR_P(SP_X_STR, stepperX2.get_pwm_thrs());
  2927. #endif
  2928. #if AXIS_HAS_STEALTHCHOP(Y2)
  2929. SERIAL_ECHOPAIR_P(SP_Y_STR, stepperY2.get_pwm_thrs());
  2930. #endif
  2931. #if AXIS_HAS_STEALTHCHOP(Z2)
  2932. SERIAL_ECHOPAIR_P(SP_Z_STR, stepperZ2.get_pwm_thrs());
  2933. #endif
  2934. SERIAL_EOL();
  2935. #endif
  2936. #if AXIS_HAS_STEALTHCHOP(Z3)
  2937. say_M913(forReplay);
  2938. SERIAL_ECHOLNPAIR(" I2 Z", stepperZ3.get_pwm_thrs());
  2939. #endif
  2940. #if AXIS_HAS_STEALTHCHOP(Z4)
  2941. say_M913(forReplay);
  2942. SERIAL_ECHOLNPAIR(" I3 Z", stepperZ4.get_pwm_thrs());
  2943. #endif
  2944. #if AXIS_HAS_STEALTHCHOP(E0)
  2945. say_M913(forReplay);
  2946. SERIAL_ECHOLNPAIR(" T0 E", stepperE0.get_pwm_thrs());
  2947. #endif
  2948. #if AXIS_HAS_STEALTHCHOP(E1)
  2949. say_M913(forReplay);
  2950. SERIAL_ECHOLNPAIR(" T1 E", stepperE1.get_pwm_thrs());
  2951. #endif
  2952. #if AXIS_HAS_STEALTHCHOP(E2)
  2953. say_M913(forReplay);
  2954. SERIAL_ECHOLNPAIR(" T2 E", stepperE2.get_pwm_thrs());
  2955. #endif
  2956. #if AXIS_HAS_STEALTHCHOP(E3)
  2957. say_M913(forReplay);
  2958. SERIAL_ECHOLNPAIR(" T3 E", stepperE3.get_pwm_thrs());
  2959. #endif
  2960. #if AXIS_HAS_STEALTHCHOP(E4)
  2961. say_M913(forReplay);
  2962. SERIAL_ECHOLNPAIR(" T4 E", stepperE4.get_pwm_thrs());
  2963. #endif
  2964. #if AXIS_HAS_STEALTHCHOP(E5)
  2965. say_M913(forReplay);
  2966. SERIAL_ECHOLNPAIR(" T5 E", stepperE5.get_pwm_thrs());
  2967. #endif
  2968. #if AXIS_HAS_STEALTHCHOP(E6)
  2969. say_M913(forReplay);
  2970. SERIAL_ECHOLNPAIR(" T6 E", stepperE6.get_pwm_thrs());
  2971. #endif
  2972. #if AXIS_HAS_STEALTHCHOP(E7)
  2973. say_M913(forReplay);
  2974. SERIAL_ECHOLNPAIR(" T7 E", stepperE7.get_pwm_thrs());
  2975. #endif
  2976. SERIAL_EOL();
  2977. #endif // HYBRID_THRESHOLD
  2978. /**
  2979. * TMC Sensorless homing thresholds
  2980. */
  2981. #if USE_SENSORLESS
  2982. CONFIG_ECHO_HEADING("StallGuard threshold:");
  2983. #if X_SENSORLESS || Y_SENSORLESS || Z_SENSORLESS
  2984. CONFIG_ECHO_START();
  2985. say_M914();
  2986. #if X_SENSORLESS
  2987. SERIAL_ECHOPAIR_P(SP_X_STR, stepperX.homing_threshold());
  2988. #endif
  2989. #if Y_SENSORLESS
  2990. SERIAL_ECHOPAIR_P(SP_Y_STR, stepperY.homing_threshold());
  2991. #endif
  2992. #if Z_SENSORLESS
  2993. SERIAL_ECHOPAIR_P(SP_Z_STR, stepperZ.homing_threshold());
  2994. #endif
  2995. SERIAL_EOL();
  2996. #endif
  2997. #if X2_SENSORLESS || Y2_SENSORLESS || Z2_SENSORLESS
  2998. CONFIG_ECHO_START();
  2999. say_M914();
  3000. SERIAL_ECHOPGM(" I1");
  3001. #if X2_SENSORLESS
  3002. SERIAL_ECHOPAIR_P(SP_X_STR, stepperX2.homing_threshold());
  3003. #endif
  3004. #if Y2_SENSORLESS
  3005. SERIAL_ECHOPAIR_P(SP_Y_STR, stepperY2.homing_threshold());
  3006. #endif
  3007. #if Z2_SENSORLESS
  3008. SERIAL_ECHOPAIR_P(SP_Z_STR, stepperZ2.homing_threshold());
  3009. #endif
  3010. SERIAL_EOL();
  3011. #endif
  3012. #if Z3_SENSORLESS
  3013. CONFIG_ECHO_START();
  3014. say_M914();
  3015. SERIAL_ECHOLNPAIR(" I2 Z", stepperZ3.homing_threshold());
  3016. #endif
  3017. #if Z4_SENSORLESS
  3018. CONFIG_ECHO_START();
  3019. say_M914();
  3020. SERIAL_ECHOLNPAIR(" I3 Z", stepperZ4.homing_threshold());
  3021. #endif
  3022. #endif // USE_SENSORLESS
  3023. /**
  3024. * TMC stepping mode
  3025. */
  3026. #if HAS_STEALTHCHOP
  3027. CONFIG_ECHO_HEADING("Driver stepping mode:");
  3028. #if AXIS_HAS_STEALTHCHOP(X)
  3029. const bool chop_x = stepperX.get_stealthChop_status();
  3030. #else
  3031. constexpr bool chop_x = false;
  3032. #endif
  3033. #if AXIS_HAS_STEALTHCHOP(Y)
  3034. const bool chop_y = stepperY.get_stealthChop_status();
  3035. #else
  3036. constexpr bool chop_y = false;
  3037. #endif
  3038. #if AXIS_HAS_STEALTHCHOP(Z)
  3039. const bool chop_z = stepperZ.get_stealthChop_status();
  3040. #else
  3041. constexpr bool chop_z = false;
  3042. #endif
  3043. if (chop_x || chop_y || chop_z) {
  3044. say_M569(forReplay);
  3045. if (chop_x) SERIAL_ECHOPGM_P(SP_X_STR);
  3046. if (chop_y) SERIAL_ECHOPGM_P(SP_Y_STR);
  3047. if (chop_z) SERIAL_ECHOPGM_P(SP_Z_STR);
  3048. SERIAL_EOL();
  3049. }
  3050. #if AXIS_HAS_STEALTHCHOP(X2)
  3051. const bool chop_x2 = stepperX2.get_stealthChop_status();
  3052. #else
  3053. constexpr bool chop_x2 = false;
  3054. #endif
  3055. #if AXIS_HAS_STEALTHCHOP(Y2)
  3056. const bool chop_y2 = stepperY2.get_stealthChop_status();
  3057. #else
  3058. constexpr bool chop_y2 = false;
  3059. #endif
  3060. #if AXIS_HAS_STEALTHCHOP(Z2)
  3061. const bool chop_z2 = stepperZ2.get_stealthChop_status();
  3062. #else
  3063. constexpr bool chop_z2 = false;
  3064. #endif
  3065. if (chop_x2 || chop_y2 || chop_z2) {
  3066. say_M569(forReplay, PSTR("I1"));
  3067. if (chop_x2) SERIAL_ECHOPGM_P(SP_X_STR);
  3068. if (chop_y2) SERIAL_ECHOPGM_P(SP_Y_STR);
  3069. if (chop_z2) SERIAL_ECHOPGM_P(SP_Z_STR);
  3070. SERIAL_EOL();
  3071. }
  3072. #if AXIS_HAS_STEALTHCHOP(Z3)
  3073. if (stepperZ3.get_stealthChop_status()) { say_M569(forReplay, PSTR("I2 Z"), true); }
  3074. #endif
  3075. #if AXIS_HAS_STEALTHCHOP(Z4)
  3076. if (stepperZ4.get_stealthChop_status()) { say_M569(forReplay, PSTR("I3 Z"), true); }
  3077. #endif
  3078. #if AXIS_HAS_STEALTHCHOP(E0)
  3079. if (stepperE0.get_stealthChop_status()) { say_M569(forReplay, PSTR("T0 E"), true); }
  3080. #endif
  3081. #if AXIS_HAS_STEALTHCHOP(E1)
  3082. if (stepperE1.get_stealthChop_status()) { say_M569(forReplay, PSTR("T1 E"), true); }
  3083. #endif
  3084. #if AXIS_HAS_STEALTHCHOP(E2)
  3085. if (stepperE2.get_stealthChop_status()) { say_M569(forReplay, PSTR("T2 E"), true); }
  3086. #endif
  3087. #if AXIS_HAS_STEALTHCHOP(E3)
  3088. if (stepperE3.get_stealthChop_status()) { say_M569(forReplay, PSTR("T3 E"), true); }
  3089. #endif
  3090. #if AXIS_HAS_STEALTHCHOP(E4)
  3091. if (stepperE4.get_stealthChop_status()) { say_M569(forReplay, PSTR("T4 E"), true); }
  3092. #endif
  3093. #if AXIS_HAS_STEALTHCHOP(E5)
  3094. if (stepperE5.get_stealthChop_status()) { say_M569(forReplay, PSTR("T5 E"), true); }
  3095. #endif
  3096. #if AXIS_HAS_STEALTHCHOP(E6)
  3097. if (stepperE6.get_stealthChop_status()) { say_M569(forReplay, PSTR("T6 E"), true); }
  3098. #endif
  3099. #if AXIS_HAS_STEALTHCHOP(E7)
  3100. if (stepperE7.get_stealthChop_status()) { say_M569(forReplay, PSTR("T7 E"), true); }
  3101. #endif
  3102. #endif // HAS_STEALTHCHOP
  3103. #endif // HAS_TRINAMIC_CONFIG
  3104. /**
  3105. * Linear Advance
  3106. */
  3107. #if ENABLED(LIN_ADVANCE)
  3108. CONFIG_ECHO_HEADING("Linear Advance:");
  3109. #if EXTRUDERS < 2
  3110. CONFIG_ECHO_START();
  3111. SERIAL_ECHOLNPAIR(" M900 K", planner.extruder_advance_K[0]);
  3112. #else
  3113. LOOP_L_N(i, EXTRUDERS) {
  3114. CONFIG_ECHO_START();
  3115. SERIAL_ECHOLNPAIR(" M900 T", int(i), " K", planner.extruder_advance_K[i]);
  3116. }
  3117. #endif
  3118. #endif
  3119. #if HAS_MOTOR_CURRENT_PWM
  3120. CONFIG_ECHO_HEADING("Stepper motor currents:");
  3121. CONFIG_ECHO_START();
  3122. SERIAL_ECHOLNPAIR_P(
  3123. PSTR(" M907 X"), stepper.motor_current_setting[0]
  3124. , SP_Z_STR, stepper.motor_current_setting[1]
  3125. , SP_E_STR, stepper.motor_current_setting[2]
  3126. );
  3127. #endif
  3128. /**
  3129. * Advanced Pause filament load & unload lengths
  3130. */
  3131. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  3132. CONFIG_ECHO_HEADING("Filament load/unload lengths:");
  3133. #if EXTRUDERS == 1
  3134. say_M603(forReplay);
  3135. SERIAL_ECHOLNPAIR("L", LINEAR_UNIT(fc_settings[0].load_length), " U", LINEAR_UNIT(fc_settings[0].unload_length));
  3136. #else
  3137. #define _ECHO_603(N) do{ say_M603(forReplay); SERIAL_ECHOLNPAIR("T" STRINGIFY(N) " L", LINEAR_UNIT(fc_settings[N].load_length), " U", LINEAR_UNIT(fc_settings[N].unload_length)); }while(0);
  3138. REPEAT(EXTRUDERS, _ECHO_603)
  3139. #endif
  3140. #endif
  3141. #if EXTRUDERS > 1
  3142. CONFIG_ECHO_HEADING("Tool-changing:");
  3143. CONFIG_ECHO_START();
  3144. M217_report(true);
  3145. #endif
  3146. #if ENABLED(BACKLASH_GCODE)
  3147. CONFIG_ECHO_HEADING("Backlash compensation:");
  3148. CONFIG_ECHO_START();
  3149. SERIAL_ECHOLNPAIR_P(
  3150. PSTR(" M425 F"), backlash.get_correction()
  3151. , SP_X_STR, LINEAR_UNIT(backlash.distance_mm.x)
  3152. , SP_Y_STR, LINEAR_UNIT(backlash.distance_mm.y)
  3153. , SP_Z_STR, LINEAR_UNIT(backlash.distance_mm.z)
  3154. #ifdef BACKLASH_SMOOTHING_MM
  3155. , PSTR(" S"), LINEAR_UNIT(backlash.smoothing_mm)
  3156. #endif
  3157. );
  3158. #endif
  3159. #if HAS_FILAMENT_SENSOR
  3160. CONFIG_ECHO_HEADING("Filament runout sensor:");
  3161. CONFIG_ECHO_START();
  3162. SERIAL_ECHOLNPAIR(
  3163. " M412 S", int(runout.enabled)
  3164. #if HAS_FILAMENT_RUNOUT_DISTANCE
  3165. , " D", LINEAR_UNIT(runout.runout_distance())
  3166. #endif
  3167. );
  3168. #endif
  3169. }
  3170. #endif // !DISABLE_M503
  3171. #pragma pack(pop)