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

configuration_store.cpp 105KB

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