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

configuration_store.cpp 106KB

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