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 108KB

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