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

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