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

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