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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 "V58"
  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. #if ADD_PORT_ARG
  45. #define PORTARG_SOLO const int8_t port
  46. #define PORTARG_AFTER ,const int8_t port
  47. #define PORTVAR_SOLO port
  48. #else
  49. #define PORTARG_SOLO
  50. #define PORTARG_AFTER
  51. #define PORTVAR_SOLO
  52. #endif
  53. #include "endstops.h"
  54. #include "planner.h"
  55. #include "stepper.h"
  56. #include "temperature.h"
  57. #include "../lcd/ultralcd.h"
  58. #include "../core/language.h"
  59. #include "../libs/vector_3.h"
  60. #include "../gcode/gcode.h"
  61. #include "../Marlin.h"
  62. #if HAS_LEVELING
  63. #include "../feature/bedlevel/bedlevel.h"
  64. #endif
  65. #if HAS_SERVOS
  66. #include "servo.h"
  67. #endif
  68. #if HAS_BED_PROBE
  69. #include "../module/probe.h"
  70. #endif
  71. #if HAS_TRINAMIC
  72. #include "stepper_indirection.h"
  73. #include "../feature/tmc_util.h"
  74. #define TMC_GET_PWMTHRS(A,Q) _tmc_thrs(stepper##Q.microsteps(), stepper##Q.TPWMTHRS(), planner.axis_steps_per_mm[_AXIS(A)])
  75. #endif
  76. typedef struct { uint16_t X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5; } tmc_stepper_current_t;
  77. typedef struct { uint32_t X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5; } tmc_hybrid_threshold_t;
  78. typedef struct { int16_t X, Y, Z; } tmc_sgt_t;
  79. #if ENABLED(FWRETRACT)
  80. #include "../feature/fwretract.h"
  81. #endif
  82. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  83. #include "../feature/pause.h"
  84. #endif
  85. #if ENABLED(PID_EXTRUSION_SCALING)
  86. #define LPQ_LEN thermalManager.lpq_len
  87. #endif
  88. #pragma pack(push, 1) // No padding between variables
  89. typedef struct PID { float Kp, Ki, Kd; } PID;
  90. typedef struct PIDC { float Kp, Ki, Kd, Kc; } PIDC;
  91. /**
  92. * Current EEPROM Layout
  93. *
  94. * Keep this data structure up to date so
  95. * EEPROM size is known at compile time!
  96. */
  97. typedef struct SettingsDataStruct {
  98. char version[4]; // Vnn\0
  99. uint16_t crc; // Data Checksum
  100. //
  101. // DISTINCT_E_FACTORS
  102. //
  103. uint8_t esteppers; // XYZE_N - XYZ
  104. uint32_t planner_max_acceleration_mm_per_s2[XYZE_N], // M201 XYZE planner.max_acceleration_mm_per_s2[XYZE_N]
  105. planner_min_segment_time_us; // M205 B planner.min_segment_time_us
  106. float planner_axis_steps_per_mm[XYZE_N], // M92 XYZE planner.axis_steps_per_mm[XYZE_N]
  107. planner_max_feedrate_mm_s[XYZE_N], // M203 XYZE planner.max_feedrate_mm_s[XYZE_N]
  108. planner_acceleration, // M204 P planner.acceleration
  109. planner_retract_acceleration, // M204 R planner.retract_acceleration
  110. planner_travel_acceleration, // M204 T planner.travel_acceleration
  111. planner_min_feedrate_mm_s, // M205 S planner.min_feedrate_mm_s
  112. planner_min_travel_feedrate_mm_s, // M205 T planner.min_travel_feedrate_mm_s
  113. planner_max_jerk[XYZE], // M205 XYZE planner.max_jerk[XYZE]
  114. planner_junction_deviation_mm; // M205 J planner.junction_deviation_mm
  115. float home_offset[XYZ]; // M206 XYZ
  116. #if HAS_HOTEND_OFFSET
  117. float hotend_offset[XYZ][HOTENDS - 1]; // M218 XYZ
  118. #endif
  119. //
  120. // ENABLE_LEVELING_FADE_HEIGHT
  121. //
  122. float planner_z_fade_height; // M420 Zn planner.z_fade_height
  123. //
  124. // MESH_BED_LEVELING
  125. //
  126. float mbl_z_offset; // mbl.z_offset
  127. uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
  128. #if ENABLED(MESH_BED_LEVELING)
  129. float mbl_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; // mbl.z_values
  130. #else
  131. float mbl_z_values[3][3];
  132. #endif
  133. //
  134. // HAS_BED_PROBE
  135. //
  136. float zprobe_zoffset;
  137. //
  138. // ABL_PLANAR
  139. //
  140. matrix_3x3 planner_bed_level_matrix; // planner.bed_level_matrix
  141. //
  142. // AUTO_BED_LEVELING_BILINEAR
  143. //
  144. uint8_t grid_max_x, grid_max_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
  145. int bilinear_grid_spacing[2],
  146. bilinear_start[2]; // G29 L F
  147. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  148. float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; // G29
  149. #else
  150. float z_values[3][3];
  151. #endif
  152. //
  153. // AUTO_BED_LEVELING_UBL
  154. //
  155. bool planner_leveling_active; // M420 S planner.leveling_active
  156. int8_t ubl_storage_slot; // ubl.storage_slot
  157. //
  158. // SERVO_ANGLES
  159. //
  160. uint16_t servo_angles[NUM_SERVO_PLUGS][2]; // M281 P L U
  161. //
  162. // DELTA / [XYZ]_DUAL_ENDSTOPS
  163. //
  164. #if ENABLED(DELTA)
  165. float delta_height, // M666 H
  166. delta_endstop_adj[ABC], // M666 XYZ
  167. delta_radius, // M665 R
  168. delta_diagonal_rod, // M665 L
  169. delta_segments_per_second, // M665 S
  170. delta_calibration_radius, // M665 B
  171. delta_tower_angle_trim[ABC]; // M665 XYZ
  172. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
  173. float x2_endstop_adj, // M666 X
  174. y2_endstop_adj, // M666 Y
  175. z2_endstop_adj; // M666 Z
  176. #if ENABLED(Z_TRIPLE_ENDSTOPS)
  177. float z3_endstop_adj; // M666 Z
  178. #endif
  179. #endif
  180. //
  181. // ULTIPANEL
  182. //
  183. int16_t lcd_preheat_hotend_temp[2], // M145 S0 H
  184. lcd_preheat_bed_temp[2], // M145 S0 B
  185. lcd_preheat_fan_speed[2]; // M145 S0 F
  186. //
  187. // PIDTEMP
  188. //
  189. PIDC hotendPID[HOTENDS]; // M301 En PIDC / M303 En U
  190. int16_t lpq_len; // M301 L
  191. //
  192. // PIDTEMPBED
  193. //
  194. PID bedPID; // M304 PID / M303 E-1 U
  195. //
  196. // HAS_LCD_CONTRAST
  197. //
  198. int16_t lcd_contrast; // M250 C
  199. //
  200. // FWRETRACT
  201. //
  202. bool autoretract_enabled; // M209 S
  203. float retract_length, // M207 S
  204. retract_feedrate_mm_s, // M207 F
  205. retract_zlift, // M207 Z
  206. retract_recover_length, // M208 S
  207. retract_recover_feedrate_mm_s, // M208 F
  208. swap_retract_length, // M207 W
  209. swap_retract_recover_length, // M208 W
  210. swap_retract_recover_feedrate_mm_s; // M208 R
  211. //
  212. // !NO_VOLUMETRIC
  213. //
  214. bool parser_volumetric_enabled; // M200 D parser.volumetric_enabled
  215. float planner_filament_size[EXTRUDERS]; // M200 T D planner.filament_size[]
  216. //
  217. // HAS_TRINAMIC
  218. //
  219. #define TMC_AXES (MAX_EXTRUDERS + 7)
  220. tmc_stepper_current_t tmc_stepper_current; // M906 X Y Z X2 Y2 Z2 Z3 E0 E1 E2 E3 E4 E5
  221. tmc_hybrid_threshold_t tmc_hybrid_threshold; // M913 X Y Z X2 Y2 Z2 Z3 E0 E1 E2 E3 E4 E5
  222. tmc_sgt_t tmc_sgt; // M914 X Y Z
  223. //
  224. // LIN_ADVANCE
  225. //
  226. float planner_extruder_advance_K[EXTRUDERS]; // M900 K planner.extruder_advance_K
  227. //
  228. // HAS_MOTOR_CURRENT_PWM
  229. //
  230. uint32_t motor_current_setting[XYZ]; // M907 X Z E
  231. //
  232. // CNC_COORDINATE_SYSTEMS
  233. //
  234. float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ]; // G54-G59.3
  235. //
  236. // SKEW_CORRECTION
  237. //
  238. float planner_xy_skew_factor, // M852 I planner.xy_skew_factor
  239. planner_xz_skew_factor, // M852 J planner.xz_skew_factor
  240. planner_yz_skew_factor; // M852 K planner.yz_skew_factor
  241. //
  242. // ADVANCED_PAUSE_FEATURE
  243. //
  244. float filament_change_unload_length[EXTRUDERS], // M603 T U
  245. filament_change_load_length[EXTRUDERS]; // M603 T L
  246. } SettingsData;
  247. #pragma pack(pop)
  248. MarlinSettings settings;
  249. uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); }
  250. /**
  251. * Post-process after Retrieve or Reset
  252. */
  253. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  254. float new_z_fade_height;
  255. #endif
  256. void MarlinSettings::postprocess() {
  257. const float oldpos[XYZE] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS] };
  258. // steps per s2 needs to be updated to agree with units per s2
  259. planner.reset_acceleration_rates();
  260. // Make sure delta kinematics are updated before refreshing the
  261. // planner position so the stepper counts will be set correctly.
  262. #if ENABLED(DELTA)
  263. recalc_delta_settings();
  264. #endif
  265. #if ENABLED(PIDTEMP)
  266. thermalManager.updatePID();
  267. #endif
  268. #if DISABLED(NO_VOLUMETRICS)
  269. planner.calculate_volumetric_multipliers();
  270. #else
  271. for (uint8_t i = COUNT(planner.e_factor); i--;)
  272. planner.refresh_e_factor(i);
  273. #endif
  274. #if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
  275. // Software endstops depend on home_offset
  276. LOOP_XYZ(i) update_software_endstops((AxisEnum)i);
  277. #endif
  278. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  279. set_z_fade_height(new_z_fade_height, false); // false = no report
  280. #endif
  281. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  282. refresh_bed_level();
  283. #endif
  284. #if HAS_MOTOR_CURRENT_PWM
  285. stepper.refresh_motor_power();
  286. #endif
  287. #if ENABLED(FWRETRACT)
  288. fwretract.refresh_autoretract();
  289. #endif
  290. #if ENABLED(JUNCTION_DEVIATION) && ENABLED(LIN_ADVANCE)
  291. planner.recalculate_max_e_jerk();
  292. #endif
  293. // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
  294. // and init stepper.count[], planner.position[] with current_position
  295. planner.refresh_positioning();
  296. // Various factors can change the current position
  297. if (memcmp(oldpos, current_position, sizeof(oldpos)))
  298. report_current_position();
  299. }
  300. #if ENABLED(EEPROM_SETTINGS)
  301. #include "../HAL/shared/persistent_store_api.h"
  302. #define DUMMY_PID_VALUE 3000.0f
  303. #define EEPROM_START() int eeprom_index = EEPROM_OFFSET; persistentStore.access_start()
  304. #define EEPROM_FINISH() persistentStore.access_finish()
  305. #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
  306. #define EEPROM_WRITE(VAR) persistentStore.write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
  307. #define EEPROM_READ(VAR) persistentStore.read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, !validating)
  308. #define EEPROM_READ_ALWAYS(VAR) persistentStore.read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
  309. #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START_P(port); SERIAL_ERRORLNPGM_P(port, ERR); eeprom_error = true; }while(0)
  310. #if ENABLED(DEBUG_EEPROM_READWRITE)
  311. #define _FIELD_TEST(FIELD) \
  312. EEPROM_ASSERT( \
  313. eeprom_error || eeprom_index == offsetof(SettingsData, FIELD) + EEPROM_OFFSET, \
  314. "Field " STRINGIFY(FIELD) " mismatch." \
  315. )
  316. #else
  317. #define _FIELD_TEST(FIELD) NOOP
  318. #endif
  319. const char version[4] = EEPROM_VERSION;
  320. bool MarlinSettings::eeprom_error, MarlinSettings::validating;
  321. bool MarlinSettings::size_error(const uint16_t size PORTARG_AFTER) {
  322. if (size != datasize()) {
  323. #if ENABLED(EEPROM_CHITCHAT)
  324. SERIAL_ERROR_START_P(port);
  325. SERIAL_ERRORLNPGM_P(port, "EEPROM datasize error.");
  326. #endif
  327. return true;
  328. }
  329. return false;
  330. }
  331. /**
  332. * M500 - Store Configuration
  333. */
  334. bool MarlinSettings::save(PORTARG_SOLO) {
  335. float dummy = 0;
  336. char ver[4] = "ERR";
  337. uint16_t working_crc = 0;
  338. EEPROM_START();
  339. eeprom_error = false;
  340. #if ENABLED(FLASH_EEPROM_EMULATION)
  341. EEPROM_SKIP(ver); // Flash doesn't allow rewriting without erase
  342. #else
  343. EEPROM_WRITE(ver); // invalidate data first
  344. #endif
  345. EEPROM_SKIP(working_crc); // Skip the checksum slot
  346. working_crc = 0; // clear before first "real data"
  347. _FIELD_TEST(esteppers);
  348. const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
  349. EEPROM_WRITE(esteppers);
  350. EEPROM_WRITE(planner.max_acceleration_mm_per_s2);
  351. EEPROM_WRITE(planner.min_segment_time_us);
  352. EEPROM_WRITE(planner.axis_steps_per_mm);
  353. EEPROM_WRITE(planner.max_feedrate_mm_s);
  354. EEPROM_WRITE(planner.acceleration);
  355. EEPROM_WRITE(planner.retract_acceleration);
  356. EEPROM_WRITE(planner.travel_acceleration);
  357. EEPROM_WRITE(planner.min_feedrate_mm_s);
  358. EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
  359. #if HAS_CLASSIC_JERK
  360. EEPROM_WRITE(planner.max_jerk);
  361. #if ENABLED(JUNCTION_DEVIATION) && ENABLED(LIN_ADVANCE)
  362. dummy = float(DEFAULT_EJERK);
  363. EEPROM_WRITE(dummy);
  364. #endif
  365. #else
  366. const float planner_max_jerk[XYZE] = { float(DEFAULT_XJERK), float(DEFAULT_YJERK), float(DEFAULT_ZJERK), float(DEFAULT_EJERK) };
  367. EEPROM_WRITE(planner_max_jerk);
  368. #endif
  369. #if ENABLED(JUNCTION_DEVIATION)
  370. EEPROM_WRITE(planner.junction_deviation_mm);
  371. #else
  372. dummy = 0.02f;
  373. EEPROM_WRITE(dummy);
  374. #endif
  375. _FIELD_TEST(home_offset);
  376. #if !HAS_HOME_OFFSET
  377. const float home_offset[XYZ] = { 0 };
  378. #endif
  379. EEPROM_WRITE(home_offset);
  380. #if HAS_HOTEND_OFFSET
  381. // Skip hotend 0 which must be 0
  382. for (uint8_t e = 1; e < HOTENDS; e++)
  383. LOOP_XYZ(i) EEPROM_WRITE(hotend_offset[i][e]);
  384. #endif
  385. //
  386. // Global Leveling
  387. //
  388. const float zfh = (
  389. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  390. planner.z_fade_height
  391. #else
  392. 10.0
  393. #endif
  394. );
  395. EEPROM_WRITE(zfh);
  396. //
  397. // Mesh Bed Leveling
  398. //
  399. #if ENABLED(MESH_BED_LEVELING)
  400. // Compile time test that sizeof(mbl.z_values) is as expected
  401. static_assert(
  402. sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]),
  403. "MBL Z array is the wrong size."
  404. );
  405. const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
  406. EEPROM_WRITE(mbl.z_offset);
  407. EEPROM_WRITE(mesh_num_x);
  408. EEPROM_WRITE(mesh_num_y);
  409. EEPROM_WRITE(mbl.z_values);
  410. #else // For disabled MBL write a default mesh
  411. dummy = 0;
  412. const uint8_t mesh_num_x = 3, mesh_num_y = 3;
  413. EEPROM_WRITE(dummy); // z_offset
  414. EEPROM_WRITE(mesh_num_x);
  415. EEPROM_WRITE(mesh_num_y);
  416. for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummy);
  417. #endif // MESH_BED_LEVELING
  418. _FIELD_TEST(zprobe_zoffset);
  419. #if !HAS_BED_PROBE
  420. const float zprobe_zoffset = 0;
  421. #endif
  422. EEPROM_WRITE(zprobe_zoffset);
  423. //
  424. // Planar Bed Leveling matrix
  425. //
  426. #if ABL_PLANAR
  427. EEPROM_WRITE(planner.bed_level_matrix);
  428. #else
  429. dummy = 0;
  430. for (uint8_t q = 9; q--;) EEPROM_WRITE(dummy);
  431. #endif
  432. //
  433. // Bilinear Auto Bed Leveling
  434. //
  435. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  436. // Compile time test that sizeof(z_values) is as expected
  437. static_assert(
  438. sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]),
  439. "Bilinear Z array is the wrong size."
  440. );
  441. const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y;
  442. EEPROM_WRITE(grid_max_x); // 1 byte
  443. EEPROM_WRITE(grid_max_y); // 1 byte
  444. EEPROM_WRITE(bilinear_grid_spacing); // 2 ints
  445. EEPROM_WRITE(bilinear_start); // 2 ints
  446. EEPROM_WRITE(z_values); // 9-256 floats
  447. #else
  448. // For disabled Bilinear Grid write an empty 3x3 grid
  449. const uint8_t grid_max_x = 3, grid_max_y = 3;
  450. const int bilinear_start[2] = { 0 }, bilinear_grid_spacing[2] = { 0 };
  451. dummy = 0;
  452. EEPROM_WRITE(grid_max_x);
  453. EEPROM_WRITE(grid_max_y);
  454. EEPROM_WRITE(bilinear_grid_spacing);
  455. EEPROM_WRITE(bilinear_start);
  456. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
  457. #endif // AUTO_BED_LEVELING_BILINEAR
  458. _FIELD_TEST(planner_leveling_active);
  459. #if ENABLED(AUTO_BED_LEVELING_UBL)
  460. EEPROM_WRITE(planner.leveling_active);
  461. EEPROM_WRITE(ubl.storage_slot);
  462. #else
  463. const bool ubl_active = false;
  464. const int8_t storage_slot = -1;
  465. EEPROM_WRITE(ubl_active);
  466. EEPROM_WRITE(storage_slot);
  467. #endif // AUTO_BED_LEVELING_UBL
  468. #if !HAS_SERVOS || DISABLED(EDITABLE_SERVO_ANGLES)
  469. #if ENABLED(SWITCHING_EXTRUDER)
  470. constexpr uint16_t sesa[][2] = SWITCHING_EXTRUDER_SERVO_ANGLES;
  471. #endif
  472. constexpr uint16_t servo_angles[NUM_SERVO_PLUGS][2] = {
  473. #if ENABLED(SWITCHING_EXTRUDER)
  474. [SWITCHING_EXTRUDER_SERVO_NR] = { sesa[0][0], sesa[0][1] }
  475. #if EXTRUDERS > 3
  476. , [SWITCHING_EXTRUDER_E23_SERVO_NR] = { sesa[1][0], sesa[1][1] }
  477. #endif
  478. #elif ENABLED(SWITCHING_NOZZLE)
  479. [SWITCHING_NOZZLE_SERVO_NR] = SWITCHING_NOZZLE_SERVO_ANGLES
  480. #elif defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
  481. [Z_PROBE_SERVO_NR] = Z_SERVO_ANGLES
  482. #endif
  483. };
  484. #endif
  485. EEPROM_WRITE(servo_angles);
  486. // 11 floats for DELTA / [XYZ]_DUAL_ENDSTOPS
  487. #if ENABLED(DELTA)
  488. _FIELD_TEST(delta_height);
  489. EEPROM_WRITE(delta_height); // 1 float
  490. EEPROM_WRITE(delta_endstop_adj); // 3 floats
  491. EEPROM_WRITE(delta_radius); // 1 float
  492. EEPROM_WRITE(delta_diagonal_rod); // 1 float
  493. EEPROM_WRITE(delta_segments_per_second); // 1 float
  494. EEPROM_WRITE(delta_calibration_radius); // 1 float
  495. EEPROM_WRITE(delta_tower_angle_trim); // 3 floats
  496. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
  497. _FIELD_TEST(x2_endstop_adj);
  498. // Write dual endstops in X, Y, Z order. Unused = 0.0
  499. dummy = 0;
  500. #if ENABLED(X_DUAL_ENDSTOPS)
  501. EEPROM_WRITE(endstops.x2_endstop_adj); // 1 float
  502. #else
  503. EEPROM_WRITE(dummy);
  504. #endif
  505. #if ENABLED(Y_DUAL_ENDSTOPS)
  506. EEPROM_WRITE(endstops.y2_endstop_adj); // 1 float
  507. #else
  508. EEPROM_WRITE(dummy);
  509. #endif
  510. #if Z_MULTI_ENDSTOPS
  511. EEPROM_WRITE(endstops.z2_endstop_adj); // 1 float
  512. #else
  513. EEPROM_WRITE(dummy);
  514. #endif
  515. #if ENABLED(Z_TRIPLE_ENDSTOPS)
  516. EEPROM_WRITE(endstops.z3_endstop_adj); // 1 float
  517. #else
  518. EEPROM_WRITE(dummy);
  519. #endif
  520. #endif
  521. _FIELD_TEST(lcd_preheat_hotend_temp);
  522. #if DISABLED(ULTIPANEL)
  523. constexpr int16_t lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
  524. lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
  525. lcd_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED };
  526. #endif
  527. EEPROM_WRITE(lcd_preheat_hotend_temp);
  528. EEPROM_WRITE(lcd_preheat_bed_temp);
  529. EEPROM_WRITE(lcd_preheat_fan_speed);
  530. for (uint8_t e = 0; e < HOTENDS; e++) {
  531. #if ENABLED(PIDTEMP)
  532. EEPROM_WRITE(PID_PARAM(Kp, e));
  533. EEPROM_WRITE(PID_PARAM(Ki, e));
  534. EEPROM_WRITE(PID_PARAM(Kd, e));
  535. #if ENABLED(PID_EXTRUSION_SCALING)
  536. EEPROM_WRITE(PID_PARAM(Kc, e));
  537. #else
  538. dummy = 1.0f; // 1.0 = default kc
  539. EEPROM_WRITE(dummy);
  540. #endif
  541. #else
  542. dummy = DUMMY_PID_VALUE; // When read, will not change the existing value
  543. EEPROM_WRITE(dummy); // Kp
  544. dummy = 0;
  545. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy); // Ki, Kd, Kc
  546. #endif
  547. } // Hotends Loop
  548. _FIELD_TEST(lpq_len);
  549. #if DISABLED(PID_EXTRUSION_SCALING)
  550. const int16_t LPQ_LEN = 20;
  551. #endif
  552. EEPROM_WRITE(LPQ_LEN);
  553. #if DISABLED(PIDTEMPBED)
  554. dummy = DUMMY_PID_VALUE;
  555. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
  556. #else
  557. EEPROM_WRITE(thermalManager.bedKp);
  558. EEPROM_WRITE(thermalManager.bedKi);
  559. EEPROM_WRITE(thermalManager.bedKd);
  560. #endif
  561. _FIELD_TEST(lcd_contrast);
  562. #if !HAS_LCD_CONTRAST
  563. const int16_t lcd_contrast = 32;
  564. #endif
  565. EEPROM_WRITE(lcd_contrast);
  566. const bool autoretract_enabled =
  567. #if DISABLED(FWRETRACT_AUTORETRACT)
  568. false
  569. #else
  570. fwretract.autoretract_enabled
  571. #endif
  572. ;
  573. EEPROM_WRITE(autoretract_enabled);
  574. #if DISABLED(FWRETRACT)
  575. const float autoretract_defaults[] = { 3, 45, 0, 0, 0, 13, 0, 8 };
  576. EEPROM_WRITE(autoretract_defaults);
  577. #else
  578. EEPROM_WRITE(fwretract.retract_length);
  579. EEPROM_WRITE(fwretract.retract_feedrate_mm_s);
  580. EEPROM_WRITE(fwretract.retract_zlift);
  581. EEPROM_WRITE(fwretract.retract_recover_length);
  582. EEPROM_WRITE(fwretract.retract_recover_feedrate_mm_s);
  583. EEPROM_WRITE(fwretract.swap_retract_length);
  584. EEPROM_WRITE(fwretract.swap_retract_recover_length);
  585. EEPROM_WRITE(fwretract.swap_retract_recover_feedrate_mm_s);
  586. #endif
  587. //
  588. // Volumetric & Filament Size
  589. //
  590. _FIELD_TEST(parser_volumetric_enabled);
  591. #if DISABLED(NO_VOLUMETRICS)
  592. EEPROM_WRITE(parser.volumetric_enabled);
  593. // Save filament sizes
  594. for (uint8_t q = 0; q < COUNT(planner.filament_size); q++)
  595. EEPROM_WRITE(planner.filament_size[q]);
  596. #else
  597. const bool volumetric_enabled = false;
  598. dummy = DEFAULT_NOMINAL_FILAMENT_DIA;
  599. EEPROM_WRITE(volumetric_enabled);
  600. for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummy);
  601. #endif
  602. //
  603. // Save TMC Configuration, and placeholder values
  604. //
  605. _FIELD_TEST(tmc_stepper_current);
  606. tmc_stepper_current_t tmc_stepper_current = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  607. #if HAS_TRINAMIC
  608. #if AXIS_IS_TMC(X)
  609. tmc_stepper_current.X = stepperX.getMilliamps();
  610. #endif
  611. #if AXIS_IS_TMC(Y)
  612. tmc_stepper_current.Y = stepperY.getMilliamps();
  613. #endif
  614. #if AXIS_IS_TMC(Z)
  615. tmc_stepper_current.Z = stepperZ.getMilliamps();
  616. #endif
  617. #if AXIS_IS_TMC(X2)
  618. tmc_stepper_current.X2 = stepperX2.getMilliamps();
  619. #endif
  620. #if AXIS_IS_TMC(Y2)
  621. tmc_stepper_current.Y2 = stepperY2.getMilliamps();
  622. #endif
  623. #if AXIS_IS_TMC(Z2)
  624. tmc_stepper_current.Z2 = stepperZ2.getMilliamps();
  625. #endif
  626. #if AXIS_IS_TMC(Z3)
  627. tmc_stepper_current.Z3 = stepperZ3.getMilliamps();
  628. #endif
  629. #if MAX_EXTRUDERS
  630. #if AXIS_IS_TMC(E0)
  631. tmc_stepper_current.E0 = stepperE0.getMilliamps();
  632. #endif
  633. #if MAX_EXTRUDERS > 1
  634. #if AXIS_IS_TMC(E1)
  635. tmc_stepper_current.E1 = stepperE1.getMilliamps();
  636. #endif
  637. #if MAX_EXTRUDERS > 2
  638. #if AXIS_IS_TMC(E2)
  639. tmc_stepper_current.E2 = stepperE2.getMilliamps();
  640. #endif
  641. #if MAX_EXTRUDERS > 3
  642. #if AXIS_IS_TMC(E3)
  643. tmc_stepper_current.E3 = stepperE3.getMilliamps();
  644. #endif
  645. #if MAX_EXTRUDERS > 4
  646. #if AXIS_IS_TMC(E4)
  647. tmc_stepper_current.E4 = stepperE4.getMilliamps();
  648. #endif
  649. #if MAX_EXTRUDERS > 5
  650. #if AXIS_IS_TMC(E5)
  651. tmc_stepper_current.E5 = stepperE5.getMilliamps();
  652. #endif
  653. #endif // MAX_EXTRUDERS > 5
  654. #endif // MAX_EXTRUDERS > 4
  655. #endif // MAX_EXTRUDERS > 3
  656. #endif // MAX_EXTRUDERS > 2
  657. #endif // MAX_EXTRUDERS > 1
  658. #endif // MAX_EXTRUDERS
  659. #endif
  660. EEPROM_WRITE(tmc_stepper_current);
  661. //
  662. // Save TMC Hybrid Threshold, and placeholder values
  663. //
  664. _FIELD_TEST(tmc_hybrid_threshold);
  665. #if ENABLED(HYBRID_THRESHOLD)
  666. tmc_hybrid_threshold_t tmc_hybrid_threshold = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  667. #if AXIS_HAS_STEALTHCHOP(X)
  668. tmc_hybrid_threshold.X = TMC_GET_PWMTHRS(X, X);
  669. #endif
  670. #if AXIS_HAS_STEALTHCHOP(Y)
  671. tmc_hybrid_threshold.Y = TMC_GET_PWMTHRS(Y, Y);
  672. #endif
  673. #if AXIS_HAS_STEALTHCHOP(Z)
  674. tmc_hybrid_threshold.Z = TMC_GET_PWMTHRS(Z, Z);
  675. #endif
  676. #if AXIS_HAS_STEALTHCHOP(X2)
  677. tmc_hybrid_threshold.X2 = TMC_GET_PWMTHRS(X, X2);
  678. #endif
  679. #if AXIS_HAS_STEALTHCHOP(Y2)
  680. tmc_hybrid_threshold.Y2 = TMC_GET_PWMTHRS(Y, Y2);
  681. #endif
  682. #if AXIS_HAS_STEALTHCHOP(Z2)
  683. tmc_hybrid_threshold.Z2 = TMC_GET_PWMTHRS(Z, Z2);
  684. #endif
  685. #if AXIS_HAS_STEALTHCHOP(Z3)
  686. tmc_hybrid_threshold.Z3 = TMC_GET_PWMTHRS(Z, Z3);
  687. #endif
  688. #if MAX_EXTRUDERS
  689. #if AXIS_HAS_STEALTHCHOP(E0)
  690. tmc_hybrid_threshold.E0 = TMC_GET_PWMTHRS(E, E0);
  691. #endif
  692. #if MAX_EXTRUDERS > 1
  693. #if AXIS_HAS_STEALTHCHOP(E1)
  694. tmc_hybrid_threshold.E1 = TMC_GET_PWMTHRS(E, E1);
  695. #endif
  696. #if MAX_EXTRUDERS > 2
  697. #if AXIS_HAS_STEALTHCHOP(E2)
  698. tmc_hybrid_threshold.E2 = TMC_GET_PWMTHRS(E, E2);
  699. #endif
  700. #if MAX_EXTRUDERS > 3
  701. #if AXIS_HAS_STEALTHCHOP(E3)
  702. tmc_hybrid_threshold.E3 = TMC_GET_PWMTHRS(E, E3);
  703. #endif
  704. #if MAX_EXTRUDERS > 4
  705. #if AXIS_HAS_STEALTHCHOP(E4)
  706. tmc_hybrid_threshold.E4 = TMC_GET_PWMTHRS(E, E4);
  707. #endif
  708. #if MAX_EXTRUDERS > 5
  709. #if AXIS_HAS_STEALTHCHOP(E5)
  710. tmc_hybrid_threshold.E5 = TMC_GET_PWMTHRS(E, E5);
  711. #endif
  712. #endif // MAX_EXTRUDERS > 5
  713. #endif // MAX_EXTRUDERS > 4
  714. #endif // MAX_EXTRUDERS > 3
  715. #endif // MAX_EXTRUDERS > 2
  716. #endif // MAX_EXTRUDERS > 1
  717. #endif // MAX_EXTRUDERS
  718. #else
  719. const tmc_hybrid_threshold_t tmc_hybrid_threshold = {
  720. .X = 100, .Y = 100, .Z = 3,
  721. .X2 = 100, .Y2 = 100, .Z2 = 3, .Z3 = 3,
  722. .E0 = 30, .E1 = 30, .E2 = 30,
  723. .E3 = 30, .E4 = 30, .E5 = 30
  724. };
  725. #endif
  726. EEPROM_WRITE(tmc_hybrid_threshold);
  727. //
  728. // TMC StallGuard threshold
  729. //
  730. tmc_sgt_t tmc_sgt = { 0, 0, 0 };
  731. #if USE_SENSORLESS
  732. #if X_SENSORLESS
  733. tmc_sgt.X = stepperX.sgt();
  734. #endif
  735. #if Y_SENSORLESS
  736. tmc_sgt.Y = stepperY.sgt();
  737. #endif
  738. #if Z_SENSORLESS
  739. tmc_sgt.Z = stepperZ.sgt();
  740. #endif
  741. #endif
  742. EEPROM_WRITE(tmc_sgt);
  743. //
  744. // Linear Advance
  745. //
  746. _FIELD_TEST(planner_extruder_advance_K);
  747. #if ENABLED(LIN_ADVANCE)
  748. LOOP_L_N(i, EXTRUDERS) EEPROM_WRITE(planner.extruder_advance_K[i]);
  749. #else
  750. dummy = 0;
  751. LOOP_L_N(i, EXTRUDERS) EEPROM_WRITE(dummy);
  752. #endif
  753. _FIELD_TEST(motor_current_setting);
  754. #if HAS_MOTOR_CURRENT_PWM
  755. for (uint8_t q = XYZ; q--;) EEPROM_WRITE(stepper.motor_current_setting[q]);
  756. #else
  757. const uint32_t dummyui32[XYZ] = { 0 };
  758. EEPROM_WRITE(dummyui32);
  759. #endif
  760. //
  761. // CNC Coordinate Systems
  762. //
  763. _FIELD_TEST(coordinate_system);
  764. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  765. EEPROM_WRITE(gcode.coordinate_system); // 27 floats
  766. #else
  767. dummy = 0;
  768. for (uint8_t q = MAX_COORDINATE_SYSTEMS * XYZ; q--;) EEPROM_WRITE(dummy);
  769. #endif
  770. //
  771. // Skew correction factors
  772. //
  773. _FIELD_TEST(planner_xy_skew_factor);
  774. #if ENABLED(SKEW_CORRECTION)
  775. EEPROM_WRITE(planner.xy_skew_factor);
  776. EEPROM_WRITE(planner.xz_skew_factor);
  777. EEPROM_WRITE(planner.yz_skew_factor);
  778. #else
  779. dummy = 0;
  780. for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
  781. #endif
  782. //
  783. // Advanced Pause filament load & unload lengths
  784. //
  785. _FIELD_TEST(filament_change_unload_length);
  786. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  787. for (uint8_t q = 0; q < COUNT(filament_change_unload_length); q++) {
  788. EEPROM_WRITE(filament_change_unload_length[q]);
  789. EEPROM_WRITE(filament_change_load_length[q]);
  790. }
  791. #else
  792. dummy = 0;
  793. for (uint8_t q = EXTRUDERS * 2; q--;) EEPROM_WRITE(dummy);
  794. #endif
  795. //
  796. // Validate CRC and Data Size
  797. //
  798. if (!eeprom_error) {
  799. const uint16_t eeprom_size = eeprom_index - (EEPROM_OFFSET),
  800. final_crc = working_crc;
  801. // Write the EEPROM header
  802. eeprom_index = EEPROM_OFFSET;
  803. EEPROM_WRITE(version);
  804. EEPROM_WRITE(final_crc);
  805. // Report storage size
  806. #if ENABLED(EEPROM_CHITCHAT)
  807. SERIAL_ECHO_START_P(port);
  808. SERIAL_ECHOPAIR_P(port, "Settings Stored (", eeprom_size);
  809. SERIAL_ECHOPAIR_P(port, " bytes; crc ", (uint32_t)final_crc);
  810. SERIAL_ECHOLNPGM_P(port, ")");
  811. #endif
  812. eeprom_error |= size_error(eeprom_size);
  813. }
  814. EEPROM_FINISH();
  815. //
  816. // UBL Mesh
  817. //
  818. #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
  819. if (ubl.storage_slot >= 0)
  820. store_mesh(ubl.storage_slot);
  821. #endif
  822. return !eeprom_error;
  823. }
  824. /**
  825. * M501 - Retrieve Configuration
  826. */
  827. bool MarlinSettings::_load(PORTARG_SOLO) {
  828. uint16_t working_crc = 0;
  829. EEPROM_START();
  830. char stored_ver[4];
  831. EEPROM_READ_ALWAYS(stored_ver);
  832. uint16_t stored_crc;
  833. EEPROM_READ_ALWAYS(stored_crc);
  834. // Version has to match or defaults are used
  835. if (strncmp(version, stored_ver, 3) != 0) {
  836. if (stored_ver[3] != '\0') {
  837. stored_ver[0] = '?';
  838. stored_ver[1] = '\0';
  839. }
  840. #if ENABLED(EEPROM_CHITCHAT)
  841. SERIAL_ECHO_START_P(port);
  842. SERIAL_ECHOPGM_P(port, "EEPROM version mismatch ");
  843. SERIAL_ECHOPAIR_P(port, "(EEPROM=", stored_ver);
  844. SERIAL_ECHOLNPGM_P(port, " Marlin=" EEPROM_VERSION ")");
  845. #endif
  846. eeprom_error = true;
  847. }
  848. else {
  849. float dummy = 0;
  850. #if DISABLED(AUTO_BED_LEVELING_UBL) || DISABLED(FWRETRACT) || DISABLED(FWRETRACT_AUTORETRACT) || ENABLED(NO_VOLUMETRICS)
  851. bool dummyb;
  852. #endif
  853. working_crc = 0; // Init to 0. Accumulated by EEPROM_READ
  854. _FIELD_TEST(esteppers);
  855. // Number of esteppers may change
  856. uint8_t esteppers;
  857. EEPROM_READ_ALWAYS(esteppers);
  858. //
  859. // Planner Motion
  860. //
  861. // Get only the number of E stepper parameters previously stored
  862. // Any steppers added later are set to their defaults
  863. const uint32_t def1[] = DEFAULT_MAX_ACCELERATION;
  864. const float def2[] = DEFAULT_AXIS_STEPS_PER_UNIT, def3[] = DEFAULT_MAX_FEEDRATE;
  865. uint32_t tmp1[XYZ + esteppers];
  866. EEPROM_READ(tmp1); // max_acceleration_mm_per_s2
  867. EEPROM_READ(planner.min_segment_time_us);
  868. float tmp2[XYZ + esteppers], tmp3[XYZ + esteppers];
  869. EEPROM_READ(tmp2); // axis_steps_per_mm
  870. EEPROM_READ(tmp3); // max_feedrate_mm_s
  871. if (!validating) LOOP_XYZE_N(i) {
  872. planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
  873. planner.axis_steps_per_mm[i] = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
  874. planner.max_feedrate_mm_s[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
  875. }
  876. EEPROM_READ(planner.acceleration);
  877. EEPROM_READ(planner.retract_acceleration);
  878. EEPROM_READ(planner.travel_acceleration);
  879. EEPROM_READ(planner.min_feedrate_mm_s);
  880. EEPROM_READ(planner.min_travel_feedrate_mm_s);
  881. #if HAS_CLASSIC_JERK
  882. EEPROM_READ(planner.max_jerk);
  883. #if ENABLED(JUNCTION_DEVIATION) && ENABLED(LIN_ADVANCE)
  884. EEPROM_READ(dummy);
  885. #endif
  886. #else
  887. for (uint8_t q = 4; q--;) EEPROM_READ(dummy);
  888. #endif
  889. #if ENABLED(JUNCTION_DEVIATION)
  890. EEPROM_READ(planner.junction_deviation_mm);
  891. #else
  892. EEPROM_READ(dummy);
  893. #endif
  894. //
  895. // Home Offset (M206)
  896. //
  897. _FIELD_TEST(home_offset);
  898. #if !HAS_HOME_OFFSET
  899. float home_offset[XYZ];
  900. #endif
  901. EEPROM_READ(home_offset);
  902. //
  903. // Hotend Offsets, if any
  904. //
  905. #if HAS_HOTEND_OFFSET
  906. // Skip hotend 0 which must be 0
  907. for (uint8_t e = 1; e < HOTENDS; e++)
  908. LOOP_XYZ(i) EEPROM_READ(hotend_offset[i][e]);
  909. #endif
  910. //
  911. // Global Leveling
  912. //
  913. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  914. EEPROM_READ(new_z_fade_height);
  915. #else
  916. EEPROM_READ(dummy);
  917. #endif
  918. //
  919. // Mesh (Manual) Bed Leveling
  920. //
  921. uint8_t mesh_num_x, mesh_num_y;
  922. EEPROM_READ(dummy);
  923. EEPROM_READ_ALWAYS(mesh_num_x);
  924. EEPROM_READ_ALWAYS(mesh_num_y);
  925. #if ENABLED(MESH_BED_LEVELING)
  926. if (!validating) mbl.z_offset = dummy;
  927. if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
  928. // EEPROM data fits the current mesh
  929. EEPROM_READ(mbl.z_values);
  930. }
  931. else {
  932. // EEPROM data is stale
  933. if (!validating) mbl.reset();
  934. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
  935. }
  936. #else
  937. // MBL is disabled - skip the stored data
  938. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
  939. #endif // MESH_BED_LEVELING
  940. _FIELD_TEST(zprobe_zoffset);
  941. #if !HAS_BED_PROBE
  942. float zprobe_zoffset;
  943. #endif
  944. EEPROM_READ(zprobe_zoffset);
  945. //
  946. // Planar Bed Leveling matrix
  947. //
  948. #if ABL_PLANAR
  949. EEPROM_READ(planner.bed_level_matrix);
  950. #else
  951. for (uint8_t q = 9; q--;) EEPROM_READ(dummy);
  952. #endif
  953. //
  954. // Bilinear Auto Bed Leveling
  955. //
  956. uint8_t grid_max_x, grid_max_y;
  957. EEPROM_READ_ALWAYS(grid_max_x); // 1 byte
  958. EEPROM_READ_ALWAYS(grid_max_y); // 1 byte
  959. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  960. if (grid_max_x == GRID_MAX_POINTS_X && grid_max_y == GRID_MAX_POINTS_Y) {
  961. if (!validating) set_bed_leveling_enabled(false);
  962. EEPROM_READ(bilinear_grid_spacing); // 2 ints
  963. EEPROM_READ(bilinear_start); // 2 ints
  964. EEPROM_READ(z_values); // 9 to 256 floats
  965. }
  966. else // EEPROM data is stale
  967. #endif // AUTO_BED_LEVELING_BILINEAR
  968. {
  969. // Skip past disabled (or stale) Bilinear Grid data
  970. int bgs[2], bs[2];
  971. EEPROM_READ(bgs);
  972. EEPROM_READ(bs);
  973. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummy);
  974. }
  975. //
  976. // Unified Bed Leveling active state
  977. //
  978. _FIELD_TEST(planner_leveling_active);
  979. #if ENABLED(AUTO_BED_LEVELING_UBL)
  980. EEPROM_READ(planner.leveling_active);
  981. EEPROM_READ(ubl.storage_slot);
  982. #else
  983. uint8_t dummyui8;
  984. EEPROM_READ(dummyb);
  985. EEPROM_READ(dummyui8);
  986. #endif // AUTO_BED_LEVELING_UBL
  987. //
  988. // SERVO_ANGLES
  989. //
  990. #if !HAS_SERVOS || DISABLED(EDITABLE_SERVO_ANGLES)
  991. uint16_t servo_angles[NUM_SERVO_PLUGS][2];
  992. #endif
  993. EEPROM_READ(servo_angles);
  994. //
  995. // DELTA Geometry or Dual Endstops offsets
  996. //
  997. #if ENABLED(DELTA)
  998. _FIELD_TEST(delta_height);
  999. EEPROM_READ(delta_height); // 1 float
  1000. EEPROM_READ(delta_endstop_adj); // 3 floats
  1001. EEPROM_READ(delta_radius); // 1 float
  1002. EEPROM_READ(delta_diagonal_rod); // 1 float
  1003. EEPROM_READ(delta_segments_per_second); // 1 float
  1004. EEPROM_READ(delta_calibration_radius); // 1 float
  1005. EEPROM_READ(delta_tower_angle_trim); // 3 floats
  1006. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
  1007. _FIELD_TEST(x2_endstop_adj);
  1008. #if ENABLED(X_DUAL_ENDSTOPS)
  1009. EEPROM_READ(endstops.x2_endstop_adj); // 1 float
  1010. #else
  1011. EEPROM_READ(dummy);
  1012. #endif
  1013. #if ENABLED(Y_DUAL_ENDSTOPS)
  1014. EEPROM_READ(endstops.y2_endstop_adj); // 1 float
  1015. #else
  1016. EEPROM_READ(dummy);
  1017. #endif
  1018. #if Z_MULTI_ENDSTOPS
  1019. EEPROM_READ(endstops.z2_endstop_adj); // 1 float
  1020. #else
  1021. EEPROM_READ(dummy);
  1022. #endif
  1023. #if ENABLED(Z_TRIPLE_ENDSTOPS)
  1024. EEPROM_READ(endstops.z3_endstop_adj); // 1 float
  1025. #else
  1026. EEPROM_READ(dummy);
  1027. #endif
  1028. #endif
  1029. //
  1030. // LCD Preheat settings
  1031. //
  1032. _FIELD_TEST(lcd_preheat_hotend_temp);
  1033. #if DISABLED(ULTIPANEL)
  1034. int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  1035. #endif
  1036. EEPROM_READ(lcd_preheat_hotend_temp); // 2 floats
  1037. EEPROM_READ(lcd_preheat_bed_temp); // 2 floats
  1038. EEPROM_READ(lcd_preheat_fan_speed); // 2 floats
  1039. //EEPROM_ASSERT(
  1040. // WITHIN(lcd_preheat_fan_speed, 0, 255),
  1041. // "lcd_preheat_fan_speed out of range"
  1042. //);
  1043. //
  1044. // Hotend PID
  1045. //
  1046. #if ENABLED(PIDTEMP)
  1047. for (uint8_t e = 0; e < HOTENDS; e++) {
  1048. EEPROM_READ(dummy); // Kp
  1049. if (dummy != DUMMY_PID_VALUE) {
  1050. // do not need to scale PID values as the values in EEPROM are already scaled
  1051. if (!validating) PID_PARAM(Kp, e) = dummy;
  1052. EEPROM_READ(PID_PARAM(Ki, e));
  1053. EEPROM_READ(PID_PARAM(Kd, e));
  1054. #if ENABLED(PID_EXTRUSION_SCALING)
  1055. EEPROM_READ(PID_PARAM(Kc, e));
  1056. #else
  1057. EEPROM_READ(dummy);
  1058. #endif
  1059. }
  1060. else
  1061. for (uint8_t q=3; q--;) EEPROM_READ(dummy); // Ki, Kd, Kc
  1062. }
  1063. #else // !PIDTEMP
  1064. // 4 x 4 = 16 slots for PID parameters
  1065. for (uint8_t q = HOTENDS * 4; q--;) EEPROM_READ(dummy); // Kp, Ki, Kd, Kc
  1066. #endif // !PIDTEMP
  1067. //
  1068. // PID Extrusion Scaling
  1069. //
  1070. _FIELD_TEST(lpq_len);
  1071. #if DISABLED(PID_EXTRUSION_SCALING)
  1072. int16_t LPQ_LEN;
  1073. #endif
  1074. EEPROM_READ(LPQ_LEN);
  1075. //
  1076. // Heated Bed PID
  1077. //
  1078. #if ENABLED(PIDTEMPBED)
  1079. EEPROM_READ(dummy); // bedKp
  1080. if (dummy != DUMMY_PID_VALUE) {
  1081. if (!validating) thermalManager.bedKp = dummy;
  1082. EEPROM_READ(thermalManager.bedKi);
  1083. EEPROM_READ(thermalManager.bedKd);
  1084. }
  1085. #else
  1086. for (uint8_t q=3; q--;) EEPROM_READ(dummy); // bedKp, bedKi, bedKd
  1087. #endif
  1088. //
  1089. // LCD Contrast
  1090. //
  1091. _FIELD_TEST(lcd_contrast);
  1092. #if !HAS_LCD_CONTRAST
  1093. int16_t lcd_contrast;
  1094. #endif
  1095. EEPROM_READ(lcd_contrast);
  1096. //
  1097. // Firmware Retraction
  1098. //
  1099. #if ENABLED(FWRETRACT)
  1100. #if DISABLED(FWRETRACT_AUTORETRACT)
  1101. EEPROM_READ(dummyb);
  1102. #else
  1103. EEPROM_READ(fwretract.autoretract_enabled);
  1104. #endif
  1105. EEPROM_READ(fwretract.retract_length);
  1106. EEPROM_READ(fwretract.retract_feedrate_mm_s);
  1107. EEPROM_READ(fwretract.retract_zlift);
  1108. EEPROM_READ(fwretract.retract_recover_length);
  1109. EEPROM_READ(fwretract.retract_recover_feedrate_mm_s);
  1110. EEPROM_READ(fwretract.swap_retract_length);
  1111. EEPROM_READ(fwretract.swap_retract_recover_length);
  1112. EEPROM_READ(fwretract.swap_retract_recover_feedrate_mm_s);
  1113. #else
  1114. EEPROM_READ(dummyb);
  1115. for (uint8_t q=8; q--;) EEPROM_READ(dummy);
  1116. #endif
  1117. //
  1118. // Volumetric & Filament Size
  1119. //
  1120. _FIELD_TEST(parser_volumetric_enabled);
  1121. #if DISABLED(NO_VOLUMETRICS)
  1122. EEPROM_READ(parser.volumetric_enabled);
  1123. for (uint8_t q = 0; q < COUNT(planner.filament_size); q++) {
  1124. EEPROM_READ(dummy);
  1125. if (!validating) planner.filament_size[q] = dummy;
  1126. }
  1127. #else
  1128. EEPROM_READ(dummyb);
  1129. for (uint8_t q=EXTRUDERS; q--;) EEPROM_READ(dummy);
  1130. #endif
  1131. if (!validating) reset_stepper_drivers();
  1132. //
  1133. // TMC Stepper Settings
  1134. //
  1135. _FIELD_TEST(tmc_stepper_current);
  1136. #if HAS_TRINAMIC
  1137. #define SET_CURR(Q) stepper##Q.rms_current(currents.Q ? currents.Q : Q##_CURRENT)
  1138. tmc_stepper_current_t currents;
  1139. EEPROM_READ(currents);
  1140. if (!validating) {
  1141. #if AXIS_IS_TMC(X)
  1142. SET_CURR(X);
  1143. #endif
  1144. #if AXIS_IS_TMC(Y)
  1145. SET_CURR(Y);
  1146. #endif
  1147. #if AXIS_IS_TMC(Z)
  1148. SET_CURR(Z);
  1149. #endif
  1150. #if AXIS_IS_TMC(X2)
  1151. SET_CURR(X2);
  1152. #endif
  1153. #if AXIS_IS_TMC(Y2)
  1154. SET_CURR(Y2);
  1155. #endif
  1156. #if AXIS_IS_TMC(Z2)
  1157. SET_CURR(Z2);
  1158. #endif
  1159. #if AXIS_IS_TMC(Z3)
  1160. SET_CURR(Z3);
  1161. #endif
  1162. #if AXIS_IS_TMC(E0)
  1163. SET_CURR(E0);
  1164. #endif
  1165. #if AXIS_IS_TMC(E1)
  1166. SET_CURR(E1);
  1167. #endif
  1168. #if AXIS_IS_TMC(E2)
  1169. SET_CURR(E2);
  1170. #endif
  1171. #if AXIS_IS_TMC(E3)
  1172. SET_CURR(E3);
  1173. #endif
  1174. #if AXIS_IS_TMC(E4)
  1175. SET_CURR(E4);
  1176. #endif
  1177. #if AXIS_IS_TMC(E5)
  1178. SET_CURR(E5);
  1179. #endif
  1180. }
  1181. #else
  1182. uint16_t val;
  1183. for (uint8_t q=TMC_AXES; q--;) EEPROM_READ(val);
  1184. #endif
  1185. #if ENABLED(HYBRID_THRESHOLD)
  1186. #define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, tmc_hybrid_threshold.Q, planner.axis_steps_per_mm[_AXIS(A)])
  1187. tmc_hybrid_threshold_t tmc_hybrid_threshold;
  1188. EEPROM_READ(tmc_hybrid_threshold);
  1189. if (!validating) {
  1190. #if AXIS_HAS_STEALTHCHOP(X)
  1191. TMC_SET_PWMTHRS(X, X);
  1192. #endif
  1193. #if AXIS_HAS_STEALTHCHOP(Y)
  1194. TMC_SET_PWMTHRS(Y, Y);
  1195. #endif
  1196. #if AXIS_HAS_STEALTHCHOP(Z)
  1197. TMC_SET_PWMTHRS(Z, Z);
  1198. #endif
  1199. #if AXIS_HAS_STEALTHCHOP(X2)
  1200. TMC_SET_PWMTHRS(X, X2);
  1201. #endif
  1202. #if AXIS_HAS_STEALTHCHOP(Y2)
  1203. TMC_SET_PWMTHRS(Y, Y2);
  1204. #endif
  1205. #if AXIS_HAS_STEALTHCHOP(Z2)
  1206. TMC_SET_PWMTHRS(Z, Z2);
  1207. #endif
  1208. #if AXIS_HAS_STEALTHCHOP(Z3)
  1209. TMC_SET_PWMTHRS(Z, Z3);
  1210. #endif
  1211. #if AXIS_HAS_STEALTHCHOP(E0)
  1212. TMC_SET_PWMTHRS(E, E0);
  1213. #endif
  1214. #if AXIS_HAS_STEALTHCHOP(E1)
  1215. TMC_SET_PWMTHRS(E, E1);
  1216. #endif
  1217. #if AXIS_HAS_STEALTHCHOP(E2)
  1218. TMC_SET_PWMTHRS(E, E2);
  1219. #endif
  1220. #if AXIS_HAS_STEALTHCHOP(E3)
  1221. TMC_SET_PWMTHRS(E, E3);
  1222. #endif
  1223. #if AXIS_HAS_STEALTHCHOP(E4)
  1224. TMC_SET_PWMTHRS(E, E4);
  1225. #endif
  1226. #if AXIS_HAS_STEALTHCHOP(E5)
  1227. TMC_SET_PWMTHRS(E, E5);
  1228. #endif
  1229. }
  1230. #else
  1231. uint32_t thrs_val;
  1232. for (uint8_t q=TMC_AXES; q--;) EEPROM_READ(thrs_val);
  1233. #endif
  1234. /*
  1235. * TMC StallGuard threshold.
  1236. * X and X2 use the same value
  1237. * Y and Y2 use the same value
  1238. * Z, Z2 and Z3 use the same value
  1239. */
  1240. tmc_sgt_t tmc_sgt;
  1241. EEPROM_READ(tmc_sgt);
  1242. #if USE_SENSORLESS
  1243. if (!validating) {
  1244. #ifdef X_STALL_SENSITIVITY
  1245. #if AXIS_HAS_STALLGUARD(X)
  1246. stepperX.sgt(tmc_sgt.X);
  1247. #endif
  1248. #if AXIS_HAS_STALLGUARD(X2)
  1249. stepperX2.sgt(tmc_sgt.X);
  1250. #endif
  1251. #endif
  1252. #ifdef Y_STALL_SENSITIVITY
  1253. #if AXIS_HAS_STALLGUARD(Y)
  1254. stepperY.sgt(tmc_sgt.Y);
  1255. #endif
  1256. #if AXIS_HAS_STALLGUARD(Y2)
  1257. stepperY2.sgt(tmc_sgt.Y);
  1258. #endif
  1259. #endif
  1260. #ifdef Z_STALL_SENSITIVITY
  1261. #if AXIS_HAS_STALLGUARD(Z)
  1262. stepperZ.sgt(tmc_sgt.Z);
  1263. #endif
  1264. #if AXIS_HAS_STALLGUARD(Z2)
  1265. stepperZ2.sgt(tmc_sgt.Z);
  1266. #endif
  1267. #if AXIS_HAS_STALLGUARD(Z3)
  1268. stepperZ3.sgt(tmc_sgt.Z);
  1269. #endif
  1270. #endif
  1271. }
  1272. #endif
  1273. //
  1274. // Linear Advance
  1275. //
  1276. _FIELD_TEST(planner_extruder_advance_K);
  1277. LOOP_L_N(i, EXTRUDERS) {
  1278. #if ENABLED(LIN_ADVANCE)
  1279. EEPROM_READ(planner.extruder_advance_K[i]);
  1280. #else
  1281. EEPROM_READ(dummy);
  1282. #endif
  1283. }
  1284. //
  1285. // Motor Current PWM
  1286. //
  1287. _FIELD_TEST(motor_current_setting);
  1288. #if HAS_MOTOR_CURRENT_PWM
  1289. for (uint8_t q = XYZ; q--;) EEPROM_READ(stepper.motor_current_setting[q]);
  1290. #else
  1291. uint32_t dummyui32[XYZ];
  1292. EEPROM_READ(dummyui32);
  1293. #endif
  1294. //
  1295. // CNC Coordinate System
  1296. //
  1297. _FIELD_TEST(coordinate_system);
  1298. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  1299. if (!validating) (void)gcode.select_coordinate_system(-1); // Go back to machine space
  1300. EEPROM_READ(gcode.coordinate_system); // 27 floats
  1301. #else
  1302. for (uint8_t q = MAX_COORDINATE_SYSTEMS * XYZ; q--;) EEPROM_READ(dummy);
  1303. #endif
  1304. //
  1305. // Skew correction factors
  1306. //
  1307. _FIELD_TEST(planner_xy_skew_factor);
  1308. #if ENABLED(SKEW_CORRECTION_GCODE)
  1309. EEPROM_READ(planner.xy_skew_factor);
  1310. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  1311. EEPROM_READ(planner.xz_skew_factor);
  1312. EEPROM_READ(planner.yz_skew_factor);
  1313. #else
  1314. EEPROM_READ(dummy);
  1315. EEPROM_READ(dummy);
  1316. #endif
  1317. #else
  1318. for (uint8_t q = 3; q--;) EEPROM_READ(dummy);
  1319. #endif
  1320. //
  1321. // Advanced Pause filament load & unload lengths
  1322. //
  1323. _FIELD_TEST(filament_change_unload_length);
  1324. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1325. for (uint8_t q = 0; q < COUNT(filament_change_unload_length); q++) {
  1326. EEPROM_READ(dummy);
  1327. if (!validating && q < COUNT(filament_change_unload_length)) filament_change_unload_length[q] = dummy;
  1328. EEPROM_READ(dummy);
  1329. if (!validating && q < COUNT(filament_change_load_length)) filament_change_load_length[q] = dummy;
  1330. }
  1331. #else
  1332. for (uint8_t q = EXTRUDERS * 2; q--;) EEPROM_READ(dummy);
  1333. #endif
  1334. eeprom_error = size_error(eeprom_index - (EEPROM_OFFSET));
  1335. if (eeprom_error) {
  1336. #if ENABLED(EEPROM_CHITCHAT)
  1337. SERIAL_ECHO_START_P(port);
  1338. SERIAL_ECHOPAIR_P(port, "Index: ", int(eeprom_index - (EEPROM_OFFSET)));
  1339. SERIAL_ECHOLNPAIR_P(port, " Size: ", datasize());
  1340. #endif
  1341. }
  1342. else if (working_crc != stored_crc) {
  1343. eeprom_error = true;
  1344. #if ENABLED(EEPROM_CHITCHAT)
  1345. SERIAL_ERROR_START_P(port);
  1346. SERIAL_ERRORPGM_P(port, "EEPROM CRC mismatch - (stored) ");
  1347. SERIAL_ERROR_P(port, stored_crc);
  1348. SERIAL_ERRORPGM_P(port, " != ");
  1349. SERIAL_ERROR_P(port, working_crc);
  1350. SERIAL_ERRORLNPGM_P(port, " (calculated)!");
  1351. #endif
  1352. }
  1353. else if (!validating) {
  1354. #if ENABLED(EEPROM_CHITCHAT)
  1355. SERIAL_ECHO_START_P(port);
  1356. SERIAL_ECHO_P(port, version);
  1357. SERIAL_ECHOPAIR_P(port, " stored settings retrieved (", eeprom_index - (EEPROM_OFFSET));
  1358. SERIAL_ECHOPAIR_P(port, " bytes; crc ", (uint32_t)working_crc);
  1359. SERIAL_ECHOLNPGM_P(port, ")");
  1360. #endif
  1361. }
  1362. if (!validating && !eeprom_error) postprocess();
  1363. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1364. if (!validating) {
  1365. ubl.report_state();
  1366. if (!ubl.sanity_check()) {
  1367. SERIAL_EOL_P(port);
  1368. #if ENABLED(EEPROM_CHITCHAT)
  1369. ubl.echo_name();
  1370. SERIAL_ECHOLNPGM_P(port, " initialized.\n");
  1371. #endif
  1372. }
  1373. else {
  1374. eeprom_error = true;
  1375. #if ENABLED(EEPROM_CHITCHAT)
  1376. SERIAL_PROTOCOLPGM_P(port, "?Can't enable ");
  1377. ubl.echo_name();
  1378. SERIAL_PROTOCOLLNPGM_P(port, ".");
  1379. #endif
  1380. ubl.reset();
  1381. }
  1382. if (ubl.storage_slot >= 0) {
  1383. load_mesh(ubl.storage_slot);
  1384. #if ENABLED(EEPROM_CHITCHAT)
  1385. SERIAL_ECHOPAIR_P(port, "Mesh ", ubl.storage_slot);
  1386. SERIAL_ECHOLNPGM_P(port, " loaded from storage.");
  1387. #endif
  1388. }
  1389. else {
  1390. ubl.reset();
  1391. #if ENABLED(EEPROM_CHITCHAT)
  1392. SERIAL_ECHOLNPGM_P(port, "UBL System reset()");
  1393. #endif
  1394. }
  1395. }
  1396. #endif
  1397. }
  1398. #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
  1399. if (!validating) report(PORTVAR_SOLO);
  1400. #endif
  1401. EEPROM_FINISH();
  1402. return !eeprom_error;
  1403. }
  1404. bool MarlinSettings::validate(PORTARG_SOLO) {
  1405. validating = true;
  1406. const bool success = _load(PORTVAR_SOLO);
  1407. validating = false;
  1408. return success;
  1409. }
  1410. bool MarlinSettings::load(PORTARG_SOLO) {
  1411. if (validate(PORTVAR_SOLO)) return _load(PORTVAR_SOLO);
  1412. reset();
  1413. return true;
  1414. }
  1415. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1416. #if ENABLED(EEPROM_CHITCHAT)
  1417. void ubl_invalid_slot(const int s) {
  1418. SERIAL_PROTOCOLLNPGM("?Invalid slot.");
  1419. SERIAL_PROTOCOL(s);
  1420. SERIAL_PROTOCOLLNPGM(" mesh slots available.");
  1421. }
  1422. #endif
  1423. const uint16_t MarlinSettings::meshes_end = persistentStore.capacity() - 129; // 128 (+1 because of the change to capacity rather than last valid address)
  1424. // is a placeholder for the size of the MAT; the MAT will always
  1425. // live at the very end of the eeprom
  1426. uint16_t MarlinSettings::meshes_start_index() {
  1427. return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8; // Pad the end of configuration data so it can float up
  1428. // or down a little bit without disrupting the mesh data
  1429. }
  1430. uint16_t MarlinSettings::calc_num_meshes() {
  1431. return (meshes_end - meshes_start_index()) / sizeof(ubl.z_values);
  1432. }
  1433. int MarlinSettings::mesh_slot_offset(const int8_t slot) {
  1434. return meshes_end - (slot + 1) * sizeof(ubl.z_values);
  1435. }
  1436. void MarlinSettings::store_mesh(const int8_t slot) {
  1437. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1438. const int16_t a = calc_num_meshes();
  1439. if (!WITHIN(slot, 0, a - 1)) {
  1440. #if ENABLED(EEPROM_CHITCHAT)
  1441. ubl_invalid_slot(a);
  1442. SERIAL_PROTOCOLPAIR("E2END=", persistentStore.capacity() - 1);
  1443. SERIAL_PROTOCOLPAIR(" meshes_end=", meshes_end);
  1444. SERIAL_PROTOCOLLNPAIR(" slot=", slot);
  1445. SERIAL_EOL();
  1446. #endif
  1447. return;
  1448. }
  1449. int pos = mesh_slot_offset(slot);
  1450. uint16_t crc = 0;
  1451. persistentStore.access_start();
  1452. const bool status = persistentStore.write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc);
  1453. persistentStore.access_finish();
  1454. if (status)
  1455. SERIAL_PROTOCOLPGM("?Unable to save mesh data.\n");
  1456. // Write crc to MAT along with other data, or just tack on to the beginning or end
  1457. #if ENABLED(EEPROM_CHITCHAT)
  1458. if (!status)
  1459. SERIAL_PROTOCOLLNPAIR("Mesh saved in slot ", slot);
  1460. #endif
  1461. #else
  1462. // Other mesh types
  1463. #endif
  1464. }
  1465. void MarlinSettings::load_mesh(const int8_t slot, void * const into/*=NULL*/) {
  1466. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1467. const int16_t a = settings.calc_num_meshes();
  1468. if (!WITHIN(slot, 0, a - 1)) {
  1469. #if ENABLED(EEPROM_CHITCHAT)
  1470. ubl_invalid_slot(a);
  1471. #endif
  1472. return;
  1473. }
  1474. int pos = mesh_slot_offset(slot);
  1475. uint16_t crc = 0;
  1476. uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
  1477. persistentStore.access_start();
  1478. const uint16_t status = persistentStore.read_data(pos, dest, sizeof(ubl.z_values), &crc);
  1479. persistentStore.access_finish();
  1480. if (status)
  1481. SERIAL_PROTOCOLPGM("?Unable to load mesh data.\n");
  1482. #if ENABLED(EEPROM_CHITCHAT)
  1483. else
  1484. SERIAL_PROTOCOLLNPAIR("Mesh loaded from slot ", slot);
  1485. #endif
  1486. EEPROM_FINISH();
  1487. #else
  1488. // Other mesh types
  1489. #endif
  1490. }
  1491. //void MarlinSettings::delete_mesh() { return; }
  1492. //void MarlinSettings::defrag_meshes() { return; }
  1493. #endif // AUTO_BED_LEVELING_UBL
  1494. #else // !EEPROM_SETTINGS
  1495. bool MarlinSettings::save(PORTARG_SOLO) {
  1496. #if ENABLED(EEPROM_CHITCHAT)
  1497. SERIAL_ERROR_START_P(port);
  1498. SERIAL_ERRORLNPGM_P(port, "EEPROM disabled");
  1499. #endif
  1500. return false;
  1501. }
  1502. #endif // !EEPROM_SETTINGS
  1503. /**
  1504. * M502 - Reset Configuration
  1505. */
  1506. void MarlinSettings::reset(PORTARG_SOLO) {
  1507. static const float tmp1[] PROGMEM = DEFAULT_AXIS_STEPS_PER_UNIT, tmp2[] PROGMEM = DEFAULT_MAX_FEEDRATE;
  1508. static const uint32_t tmp3[] PROGMEM = DEFAULT_MAX_ACCELERATION;
  1509. LOOP_XYZE_N(i) {
  1510. planner.axis_steps_per_mm[i] = pgm_read_float(&tmp1[i < COUNT(tmp1) ? i : COUNT(tmp1) - 1]);
  1511. planner.max_feedrate_mm_s[i] = pgm_read_float(&tmp2[i < COUNT(tmp2) ? i : COUNT(tmp2) - 1]);
  1512. planner.max_acceleration_mm_per_s2[i] = pgm_read_dword_near(&tmp3[i < COUNT(tmp3) ? i : COUNT(tmp3) - 1]);
  1513. }
  1514. planner.min_segment_time_us = DEFAULT_MINSEGMENTTIME;
  1515. planner.acceleration = DEFAULT_ACCELERATION;
  1516. planner.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
  1517. planner.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
  1518. planner.min_feedrate_mm_s = DEFAULT_MINIMUMFEEDRATE;
  1519. planner.min_travel_feedrate_mm_s = DEFAULT_MINTRAVELFEEDRATE;
  1520. #if ENABLED(JUNCTION_DEVIATION)
  1521. planner.junction_deviation_mm = float(JUNCTION_DEVIATION_MM);
  1522. #endif
  1523. #if HAS_CLASSIC_JERK
  1524. planner.max_jerk[X_AXIS] = DEFAULT_XJERK;
  1525. planner.max_jerk[Y_AXIS] = DEFAULT_YJERK;
  1526. planner.max_jerk[Z_AXIS] = DEFAULT_ZJERK;
  1527. #if DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE)
  1528. planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
  1529. #endif
  1530. #endif
  1531. #if HAS_HOME_OFFSET
  1532. ZERO(home_offset);
  1533. #endif
  1534. #if HAS_HOTEND_OFFSET
  1535. constexpr float tmp4[XYZ][HOTENDS] = { HOTEND_OFFSET_X, HOTEND_OFFSET_Y, HOTEND_OFFSET_Z };
  1536. static_assert(
  1537. tmp4[X_AXIS][0] == 0 && tmp4[Y_AXIS][0] == 0 && tmp4[Z_AXIS][0] == 0,
  1538. "Offsets for the first hotend must be 0.0."
  1539. );
  1540. LOOP_XYZ(i) HOTEND_LOOP() hotend_offset[i][e] = tmp4[i][e];
  1541. #if ENABLED(DUAL_X_CARRIAGE)
  1542. hotend_offset[X_AXIS][1] = MAX(X2_HOME_POS, X2_MAX_POS);
  1543. #endif
  1544. #endif
  1545. //
  1546. // Global Leveling
  1547. //
  1548. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1549. new_z_fade_height = 0.0;
  1550. #endif
  1551. #if HAS_LEVELING
  1552. reset_bed_level();
  1553. #endif
  1554. #if HAS_BED_PROBE
  1555. zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER;
  1556. #endif
  1557. //
  1558. // Servo Angles
  1559. //
  1560. #if HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES)
  1561. #if ENABLED(SWITCHING_EXTRUDER)
  1562. #if EXTRUDERS > 3
  1563. #define REQ_ANGLES 4
  1564. #else
  1565. #define REQ_ANGLES 2
  1566. #endif
  1567. constexpr uint16_t extruder_angles[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
  1568. static_assert(COUNT(extruder_angles) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
  1569. servo_angles[SWITCHING_EXTRUDER_SERVO_NR][0] = extruder_angles[0];
  1570. servo_angles[SWITCHING_EXTRUDER_SERVO_NR][1] = extruder_angles[1];
  1571. #if EXTRUDERS > 3
  1572. servo_angles[SWITCHING_EXTRUDER_E23_SERVO_NR][0] = extruder_angles[2];
  1573. servo_angles[SWITCHING_EXTRUDER_E23_SERVO_NR][1] = extruder_angles[3];
  1574. #endif
  1575. #elif ENABLED(SWITCHING_NOZZLE)
  1576. constexpr uint16_t nozzle_angles[2] = SWITCHING_NOZZLE_SERVO_ANGLES;
  1577. servo_angles[SWITCHING_NOZZLE_SERVO_NR][0] = nozzle_angles[0];
  1578. servo_angles[SWITCHING_NOZZLE_SERVO_NR][1] = nozzle_angles[1];
  1579. #elif defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
  1580. constexpr uint16_t z_probe_angles[2] = Z_SERVO_ANGLES;
  1581. servo_angles[Z_PROBE_SERVO_NR][0] = z_probe_angles[0];
  1582. servo_angles[Z_PROBE_SERVO_NR][1] = z_probe_angles[1];
  1583. #endif
  1584. #endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
  1585. #if ENABLED(DELTA)
  1586. const float adj[ABC] = DELTA_ENDSTOP_ADJ, dta[ABC] = DELTA_TOWER_ANGLE_TRIM;
  1587. delta_height = DELTA_HEIGHT;
  1588. COPY(delta_endstop_adj, adj);
  1589. delta_radius = DELTA_RADIUS;
  1590. delta_diagonal_rod = DELTA_DIAGONAL_ROD;
  1591. delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
  1592. delta_calibration_radius = DELTA_CALIBRATION_RADIUS;
  1593. COPY(delta_tower_angle_trim, dta);
  1594. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
  1595. #if ENABLED(X_DUAL_ENDSTOPS)
  1596. endstops.x2_endstop_adj = (
  1597. #ifdef X_DUAL_ENDSTOPS_ADJUSTMENT
  1598. X_DUAL_ENDSTOPS_ADJUSTMENT
  1599. #else
  1600. 0
  1601. #endif
  1602. );
  1603. #endif
  1604. #if ENABLED(Y_DUAL_ENDSTOPS)
  1605. endstops.y2_endstop_adj = (
  1606. #ifdef Y_DUAL_ENDSTOPS_ADJUSTMENT
  1607. Y_DUAL_ENDSTOPS_ADJUSTMENT
  1608. #else
  1609. 0
  1610. #endif
  1611. );
  1612. #endif
  1613. #if ENABLED(Z_DUAL_ENDSTOPS)
  1614. endstops.z2_endstop_adj = (
  1615. #ifdef Z_DUAL_ENDSTOPS_ADJUSTMENT
  1616. Z_DUAL_ENDSTOPS_ADJUSTMENT
  1617. #else
  1618. 0
  1619. #endif
  1620. );
  1621. #elif ENABLED(Z_TRIPLE_ENDSTOPS)
  1622. endstops.z2_endstop_adj = (
  1623. #ifdef Z_TRIPLE_ENDSTOPS_ADJUSTMENT2
  1624. Z_TRIPLE_ENDSTOPS_ADJUSTMENT2
  1625. #else
  1626. 0
  1627. #endif
  1628. );
  1629. endstops.z3_endstop_adj = (
  1630. #ifdef Z_TRIPLE_ENDSTOPS_ADJUSTMENT3
  1631. Z_TRIPLE_ENDSTOPS_ADJUSTMENT3
  1632. #else
  1633. 0
  1634. #endif
  1635. );
  1636. #endif
  1637. #endif
  1638. #if ENABLED(ULTIPANEL)
  1639. lcd_preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
  1640. lcd_preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
  1641. lcd_preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
  1642. lcd_preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
  1643. lcd_preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
  1644. lcd_preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
  1645. #endif
  1646. #if ENABLED(PIDTEMP)
  1647. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  1648. HOTEND_LOOP()
  1649. #endif
  1650. {
  1651. PID_PARAM(Kp, e) = float(DEFAULT_Kp);
  1652. PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
  1653. PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
  1654. #if ENABLED(PID_EXTRUSION_SCALING)
  1655. PID_PARAM(Kc, e) = DEFAULT_Kc;
  1656. #endif
  1657. }
  1658. #if ENABLED(PID_EXTRUSION_SCALING)
  1659. thermalManager.lpq_len = 20; // default last-position-queue size
  1660. #endif
  1661. #endif // PIDTEMP
  1662. #if ENABLED(PIDTEMPBED)
  1663. thermalManager.bedKp = DEFAULT_bedKp;
  1664. thermalManager.bedKi = scalePID_i(DEFAULT_bedKi);
  1665. thermalManager.bedKd = scalePID_d(DEFAULT_bedKd);
  1666. #endif
  1667. #if HAS_LCD_CONTRAST
  1668. lcd_contrast = DEFAULT_LCD_CONTRAST;
  1669. #endif
  1670. #if ENABLED(FWRETRACT)
  1671. fwretract.reset();
  1672. #endif
  1673. #if DISABLED(NO_VOLUMETRICS)
  1674. parser.volumetric_enabled =
  1675. #if ENABLED(VOLUMETRIC_DEFAULT_ON)
  1676. true
  1677. #else
  1678. false
  1679. #endif
  1680. ;
  1681. for (uint8_t q = 0; q < COUNT(planner.filament_size); q++)
  1682. planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
  1683. #endif
  1684. endstops.enable_globally(
  1685. #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
  1686. true
  1687. #else
  1688. false
  1689. #endif
  1690. );
  1691. reset_stepper_drivers();
  1692. #if ENABLED(LIN_ADVANCE)
  1693. LOOP_L_N(i, EXTRUDERS) planner.extruder_advance_K[i] = LIN_ADVANCE_K;
  1694. #endif
  1695. #if HAS_MOTOR_CURRENT_PWM
  1696. uint32_t tmp_motor_current_setting[XYZ] = PWM_MOTOR_CURRENT;
  1697. for (uint8_t q = XYZ; q--;)
  1698. stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
  1699. #endif
  1700. #if ENABLED(SKEW_CORRECTION_GCODE)
  1701. planner.xy_skew_factor = XY_SKEW_FACTOR;
  1702. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  1703. planner.xz_skew_factor = XZ_SKEW_FACTOR;
  1704. planner.yz_skew_factor = YZ_SKEW_FACTOR;
  1705. #endif
  1706. #endif
  1707. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1708. for (uint8_t e = 0; e < EXTRUDERS; e++) {
  1709. filament_change_unload_length[e] = FILAMENT_CHANGE_UNLOAD_LENGTH;
  1710. filament_change_load_length[e] = FILAMENT_CHANGE_FAST_LOAD_LENGTH;
  1711. }
  1712. #endif
  1713. postprocess();
  1714. #if ENABLED(EEPROM_CHITCHAT)
  1715. SERIAL_ECHO_START_P(port);
  1716. SERIAL_ECHOLNPGM_P(port, "Hardcoded Default Settings Loaded");
  1717. #endif
  1718. }
  1719. #if DISABLED(DISABLE_M503)
  1720. #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START_P(port); }while(0)
  1721. #if HAS_TRINAMIC
  1722. void say_M906(PORTARG_SOLO) { SERIAL_ECHOPGM_P(port, " M906"); }
  1723. #if ENABLED(HYBRID_THRESHOLD)
  1724. void say_M913(PORTARG_SOLO) { SERIAL_ECHOPGM_P(port, " M913"); }
  1725. #endif
  1726. #if USE_SENSORLESS
  1727. void say_M914(PORTARG_SOLO) { SERIAL_ECHOPGM_P(port, " M914"); }
  1728. #endif
  1729. #endif
  1730. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1731. void say_M603(PORTARG_SOLO) { SERIAL_ECHOPGM_P(port, " M603 "); }
  1732. #endif
  1733. inline void say_units(
  1734. #if NUM_SERIAL > 1
  1735. const int8_t port,
  1736. #endif
  1737. const bool colon
  1738. ) {
  1739. serialprintPGM_P(port,
  1740. #if ENABLED(INCH_MODE_SUPPORT)
  1741. parser.linear_unit_factor != 1.0 ? PSTR(" (in)") :
  1742. #endif
  1743. PSTR(" (mm)")
  1744. );
  1745. if (colon) SERIAL_ECHOLNPGM_P(port, ":");
  1746. }
  1747. #if NUM_SERIAL > 1
  1748. #define SAY_UNITS_P(PORT, COLON) say_units(PORT, COLON)
  1749. #else
  1750. #define SAY_UNITS_P(PORT, COLON) say_units(COLON)
  1751. #endif
  1752. /**
  1753. * M503 - Report current settings in RAM
  1754. *
  1755. * Unless specifically disabled, M503 is available even without EEPROM
  1756. */
  1757. void MarlinSettings::report(const bool forReplay
  1758. #if NUM_SERIAL > 1
  1759. , const int8_t port/*=-1*/
  1760. #endif
  1761. ) {
  1762. /**
  1763. * Announce current units, in case inches are being displayed
  1764. */
  1765. CONFIG_ECHO_START;
  1766. #if ENABLED(INCH_MODE_SUPPORT)
  1767. #define LINEAR_UNIT(N) (float(N) / parser.linear_unit_factor)
  1768. #define VOLUMETRIC_UNIT(N) (float(N) / (parser.volumetric_enabled ? parser.volumetric_unit_factor : parser.linear_unit_factor))
  1769. SERIAL_ECHOPGM_P(port, " G2");
  1770. SERIAL_CHAR_P(port, parser.linear_unit_factor == 1.0 ? '1' : '0');
  1771. SERIAL_ECHOPGM_P(port, " ;");
  1772. SAY_UNITS_P(port, false);
  1773. #else
  1774. #define LINEAR_UNIT(N) (N)
  1775. #define VOLUMETRIC_UNIT(N) (N)
  1776. SERIAL_ECHOPGM_P(port, " G21 ; Units in mm");
  1777. SAY_UNITS_P(port, false);
  1778. #endif
  1779. SERIAL_EOL_P(port);
  1780. #if ENABLED(ULTIPANEL)
  1781. // Temperature units - for Ultipanel temperature options
  1782. CONFIG_ECHO_START;
  1783. #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
  1784. #define TEMP_UNIT(N) parser.to_temp_units(N)
  1785. SERIAL_ECHOPGM_P(port, " M149 ");
  1786. SERIAL_CHAR_P(port, parser.temp_units_code());
  1787. SERIAL_ECHOPGM_P(port, " ; Units in ");
  1788. serialprintPGM_P(port, parser.temp_units_name());
  1789. #else
  1790. #define TEMP_UNIT(N) (N)
  1791. SERIAL_ECHOLNPGM_P(port, " M149 C ; Units in Celsius");
  1792. #endif
  1793. #endif
  1794. SERIAL_EOL_P(port);
  1795. #if DISABLED(NO_VOLUMETRICS)
  1796. /**
  1797. * Volumetric extrusion M200
  1798. */
  1799. if (!forReplay) {
  1800. CONFIG_ECHO_START;
  1801. SERIAL_ECHOPGM_P(port, "Filament settings:");
  1802. if (parser.volumetric_enabled)
  1803. SERIAL_EOL_P(port);
  1804. else
  1805. SERIAL_ECHOLNPGM_P(port, " Disabled");
  1806. }
  1807. CONFIG_ECHO_START;
  1808. SERIAL_ECHOPAIR_P(port, " M200 D", LINEAR_UNIT(planner.filament_size[0]));
  1809. SERIAL_EOL_P(port);
  1810. #if EXTRUDERS > 1
  1811. CONFIG_ECHO_START;
  1812. SERIAL_ECHOPAIR_P(port, " M200 T1 D", LINEAR_UNIT(planner.filament_size[1]));
  1813. SERIAL_EOL_P(port);
  1814. #if EXTRUDERS > 2
  1815. CONFIG_ECHO_START;
  1816. SERIAL_ECHOPAIR_P(port, " M200 T2 D", LINEAR_UNIT(planner.filament_size[2]));
  1817. SERIAL_EOL_P(port);
  1818. #if EXTRUDERS > 3
  1819. CONFIG_ECHO_START;
  1820. SERIAL_ECHOPAIR_P(port, " M200 T3 D", LINEAR_UNIT(planner.filament_size[3]));
  1821. SERIAL_EOL_P(port);
  1822. #if EXTRUDERS > 4
  1823. CONFIG_ECHO_START;
  1824. SERIAL_ECHOPAIR_P(port, " M200 T4 D", LINEAR_UNIT(planner.filament_size[4]));
  1825. SERIAL_EOL_P(port);
  1826. #if EXTRUDERS > 5
  1827. CONFIG_ECHO_START;
  1828. SERIAL_ECHOPAIR_P(port, " M200 T5 D", LINEAR_UNIT(planner.filament_size[5]));
  1829. SERIAL_EOL_P(port);
  1830. #endif // EXTRUDERS > 5
  1831. #endif // EXTRUDERS > 4
  1832. #endif // EXTRUDERS > 3
  1833. #endif // EXTRUDERS > 2
  1834. #endif // EXTRUDERS > 1
  1835. if (!parser.volumetric_enabled) {
  1836. CONFIG_ECHO_START;
  1837. SERIAL_ECHOLNPGM_P(port, " M200 D0");
  1838. }
  1839. #endif // !NO_VOLUMETRICS
  1840. if (!forReplay) {
  1841. CONFIG_ECHO_START;
  1842. SERIAL_ECHOLNPGM_P(port, "Steps per unit:");
  1843. }
  1844. CONFIG_ECHO_START;
  1845. SERIAL_ECHOPAIR_P(port, " M92 X", LINEAR_UNIT(planner.axis_steps_per_mm[X_AXIS]));
  1846. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(planner.axis_steps_per_mm[Y_AXIS]));
  1847. SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(planner.axis_steps_per_mm[Z_AXIS]));
  1848. #if DISABLED(DISTINCT_E_FACTORS)
  1849. SERIAL_ECHOPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.axis_steps_per_mm[E_AXIS]));
  1850. #endif
  1851. SERIAL_EOL_P(port);
  1852. #if ENABLED(DISTINCT_E_FACTORS)
  1853. CONFIG_ECHO_START;
  1854. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1855. SERIAL_ECHOPAIR_P(port, " M92 T", (int)i);
  1856. SERIAL_ECHOLNPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.axis_steps_per_mm[E_AXIS + i]));
  1857. }
  1858. #endif
  1859. if (!forReplay) {
  1860. CONFIG_ECHO_START;
  1861. SERIAL_ECHOLNPGM_P(port, "Maximum feedrates (units/s):");
  1862. }
  1863. CONFIG_ECHO_START;
  1864. SERIAL_ECHOPAIR_P(port, " M203 X", LINEAR_UNIT(planner.max_feedrate_mm_s[X_AXIS]));
  1865. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(planner.max_feedrate_mm_s[Y_AXIS]));
  1866. SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(planner.max_feedrate_mm_s[Z_AXIS]));
  1867. #if DISABLED(DISTINCT_E_FACTORS)
  1868. SERIAL_ECHOPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.max_feedrate_mm_s[E_AXIS]));
  1869. #endif
  1870. SERIAL_EOL_P(port);
  1871. #if ENABLED(DISTINCT_E_FACTORS)
  1872. CONFIG_ECHO_START;
  1873. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1874. SERIAL_ECHOPAIR_P(port, " M203 T", (int)i);
  1875. SERIAL_ECHOLNPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.max_feedrate_mm_s[E_AXIS + i]));
  1876. }
  1877. #endif
  1878. if (!forReplay) {
  1879. CONFIG_ECHO_START;
  1880. SERIAL_ECHOLNPGM_P(port, "Maximum Acceleration (units/s2):");
  1881. }
  1882. CONFIG_ECHO_START;
  1883. SERIAL_ECHOPAIR_P(port, " M201 X", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[X_AXIS]));
  1884. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[Y_AXIS]));
  1885. SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(planner.max_acceleration_mm_per_s2[Z_AXIS]));
  1886. #if DISABLED(DISTINCT_E_FACTORS)
  1887. SERIAL_ECHOPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.max_acceleration_mm_per_s2[E_AXIS]));
  1888. #endif
  1889. SERIAL_EOL_P(port);
  1890. #if ENABLED(DISTINCT_E_FACTORS)
  1891. CONFIG_ECHO_START;
  1892. for (uint8_t i = 0; i < E_STEPPERS; i++) {
  1893. SERIAL_ECHOPAIR_P(port, " M201 T", (int)i);
  1894. SERIAL_ECHOLNPAIR_P(port, " E", VOLUMETRIC_UNIT(planner.max_acceleration_mm_per_s2[E_AXIS + i]));
  1895. }
  1896. #endif
  1897. if (!forReplay) {
  1898. CONFIG_ECHO_START;
  1899. SERIAL_ECHOLNPGM_P(port, "Acceleration (units/s2): P<print_accel> R<retract_accel> T<travel_accel>");
  1900. }
  1901. CONFIG_ECHO_START;
  1902. SERIAL_ECHOPAIR_P(port, " M204 P", LINEAR_UNIT(planner.acceleration));
  1903. SERIAL_ECHOPAIR_P(port, " R", LINEAR_UNIT(planner.retract_acceleration));
  1904. SERIAL_ECHOLNPAIR_P(port, " T", LINEAR_UNIT(planner.travel_acceleration));
  1905. if (!forReplay) {
  1906. CONFIG_ECHO_START;
  1907. SERIAL_ECHOPGM_P(port, "Advanced: B<min_segment_time_us> S<min_feedrate> T<min_travel_feedrate>");
  1908. #if ENABLED(JUNCTION_DEVIATION)
  1909. SERIAL_ECHOPGM_P(port, " J<junc_dev>");
  1910. #endif
  1911. #if HAS_CLASSIC_JERK
  1912. SERIAL_ECHOPGM_P(port, " X<max_x_jerk> Y<max_y_jerk> Z<max_z_jerk>");
  1913. #if DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE)
  1914. SERIAL_ECHOPGM_P(port, " E<max_e_jerk>");
  1915. #endif
  1916. #endif
  1917. SERIAL_EOL_P(port);
  1918. }
  1919. CONFIG_ECHO_START;
  1920. SERIAL_ECHOPAIR_P(port, " M205 B", LINEAR_UNIT(planner.min_segment_time_us));
  1921. SERIAL_ECHOPAIR_P(port, " S", LINEAR_UNIT(planner.min_feedrate_mm_s));
  1922. SERIAL_ECHOPAIR_P(port, " T", LINEAR_UNIT(planner.min_travel_feedrate_mm_s));
  1923. #if ENABLED(JUNCTION_DEVIATION)
  1924. SERIAL_ECHOPAIR_P(port, " J", LINEAR_UNIT(planner.junction_deviation_mm));
  1925. #endif
  1926. #if HAS_CLASSIC_JERK
  1927. SERIAL_ECHOPAIR_P(port, " X", LINEAR_UNIT(planner.max_jerk[X_AXIS]));
  1928. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(planner.max_jerk[Y_AXIS]));
  1929. SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(planner.max_jerk[Z_AXIS]));
  1930. #if DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE)
  1931. SERIAL_ECHOPAIR_P(port, " E", LINEAR_UNIT(planner.max_jerk[E_AXIS]));
  1932. #endif
  1933. #endif
  1934. SERIAL_EOL_P(port);
  1935. #if HAS_M206_COMMAND
  1936. if (!forReplay) {
  1937. CONFIG_ECHO_START;
  1938. SERIAL_ECHOLNPGM_P(port, "Home offset:");
  1939. }
  1940. CONFIG_ECHO_START;
  1941. SERIAL_ECHOPAIR_P(port, " M206 X", LINEAR_UNIT(home_offset[X_AXIS]));
  1942. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(home_offset[Y_AXIS]));
  1943. SERIAL_ECHOLNPAIR_P(port, " Z", LINEAR_UNIT(home_offset[Z_AXIS]));
  1944. #endif
  1945. #if HAS_HOTEND_OFFSET
  1946. if (!forReplay) {
  1947. CONFIG_ECHO_START;
  1948. SERIAL_ECHOLNPGM_P(port, "Hotend offsets:");
  1949. }
  1950. CONFIG_ECHO_START;
  1951. for (uint8_t e = 1; e < HOTENDS; e++) {
  1952. SERIAL_ECHOPAIR_P(port, " M218 T", (int)e);
  1953. SERIAL_ECHOPAIR_P(port, " X", LINEAR_UNIT(hotend_offset[X_AXIS][e]));
  1954. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(hotend_offset[Y_AXIS][e]));
  1955. SERIAL_ECHO_P(port, " Z");
  1956. SERIAL_ECHO_F_P(port, LINEAR_UNIT(hotend_offset[Z_AXIS][e]), 3);
  1957. SERIAL_EOL_P(port);
  1958. }
  1959. #endif
  1960. /**
  1961. * Bed Leveling
  1962. */
  1963. #if HAS_LEVELING
  1964. #if ENABLED(MESH_BED_LEVELING)
  1965. if (!forReplay) {
  1966. CONFIG_ECHO_START;
  1967. SERIAL_ECHOLNPGM_P(port, "Mesh Bed Leveling:");
  1968. }
  1969. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1970. if (!forReplay) {
  1971. CONFIG_ECHO_START;
  1972. ubl.echo_name();
  1973. SERIAL_ECHOLNPGM_P(port, ":");
  1974. }
  1975. #elif HAS_ABL
  1976. if (!forReplay) {
  1977. CONFIG_ECHO_START;
  1978. SERIAL_ECHOLNPGM_P(port, "Auto Bed Leveling:");
  1979. }
  1980. #endif
  1981. CONFIG_ECHO_START;
  1982. SERIAL_ECHOPAIR_P(port, " M420 S", planner.leveling_active ? 1 : 0);
  1983. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1984. SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(planner.z_fade_height));
  1985. #endif
  1986. SERIAL_EOL_P(port);
  1987. #if ENABLED(MESH_BED_LEVELING)
  1988. if (leveling_is_valid()) {
  1989. for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
  1990. for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
  1991. CONFIG_ECHO_START;
  1992. SERIAL_ECHOPAIR_P(port, " G29 S3 X", (int)px + 1);
  1993. SERIAL_ECHOPAIR_P(port, " Y", (int)py + 1);
  1994. SERIAL_ECHOPGM_P(port, " Z");
  1995. SERIAL_ECHO_F_P(port, LINEAR_UNIT(mbl.z_values[px][py]), 5);
  1996. SERIAL_EOL_P(port);
  1997. }
  1998. }
  1999. }
  2000. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  2001. if (!forReplay) {
  2002. SERIAL_EOL_P(port);
  2003. ubl.report_state();
  2004. SERIAL_ECHOLNPAIR_P(port, "\nActive Mesh Slot: ", ubl.storage_slot);
  2005. SERIAL_ECHOPAIR_P(port, "EEPROM can hold ", calc_num_meshes());
  2006. SERIAL_ECHOLNPGM_P(port, " meshes.\n");
  2007. }
  2008. // ubl.report_current_mesh(PORTVAR_SOLO); // This is too verbose for large mesh's. A better (more terse)
  2009. // solution needs to be found.
  2010. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  2011. if (leveling_is_valid()) {
  2012. for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
  2013. for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
  2014. CONFIG_ECHO_START;
  2015. SERIAL_ECHOPAIR_P(port, " G29 W I", (int)px);
  2016. SERIAL_ECHOPAIR_P(port, " J", (int)py);
  2017. SERIAL_ECHOPGM_P(port, " Z");
  2018. SERIAL_ECHO_F_P(port, LINEAR_UNIT(z_values[px][py]), 5);
  2019. SERIAL_EOL_P(port);
  2020. }
  2021. }
  2022. }
  2023. #endif
  2024. #endif // HAS_LEVELING
  2025. #if HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES)
  2026. if (!forReplay) {
  2027. CONFIG_ECHO_START;
  2028. SERIAL_ECHOLNPGM_P(port, "Servo Angles:");
  2029. }
  2030. for (uint8_t i = 0; i < NUM_SERVOS; i++) {
  2031. switch (i) {
  2032. #if ENABLED(SWITCHING_EXTRUDER)
  2033. case SWITCHING_EXTRUDER_SERVO_NR:
  2034. #if EXTRUDERS > 3
  2035. case SWITCHING_EXTRUDER_E23_SERVO_NR:
  2036. #endif
  2037. #elif ENABLED(SWITCHING_NOZZLE)
  2038. case SWITCHING_NOZZLE_SERVO_NR:
  2039. #elif defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
  2040. case Z_PROBE_SERVO_NR:
  2041. #endif
  2042. CONFIG_ECHO_START;
  2043. SERIAL_ECHOPAIR_P(port, " M281 P", int(i));
  2044. SERIAL_ECHOPAIR_P(port, " L", servo_angles[i][0]);
  2045. SERIAL_ECHOPAIR_P(port, " U", servo_angles[i][1]);
  2046. SERIAL_EOL_P(port);
  2047. default: break;
  2048. }
  2049. }
  2050. #endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
  2051. #if ENABLED(DELTA)
  2052. if (!forReplay) {
  2053. CONFIG_ECHO_START;
  2054. SERIAL_ECHOLNPGM_P(port, "Endstop adjustment:");
  2055. }
  2056. CONFIG_ECHO_START;
  2057. SERIAL_ECHOPAIR_P(port, " M666 X", LINEAR_UNIT(delta_endstop_adj[X_AXIS]));
  2058. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(delta_endstop_adj[Y_AXIS]));
  2059. SERIAL_ECHOLNPAIR_P(port, " Z", LINEAR_UNIT(delta_endstop_adj[Z_AXIS]));
  2060. if (!forReplay) {
  2061. CONFIG_ECHO_START;
  2062. SERIAL_ECHOLNPGM_P(port, "Delta settings: L<diagonal_rod> R<radius> H<height> S<segments_per_s> B<calibration radius> XYZ<tower angle corrections>");
  2063. }
  2064. CONFIG_ECHO_START;
  2065. SERIAL_ECHOPAIR_P(port, " M665 L", LINEAR_UNIT(delta_diagonal_rod));
  2066. SERIAL_ECHOPAIR_P(port, " R", LINEAR_UNIT(delta_radius));
  2067. SERIAL_ECHOPAIR_P(port, " H", LINEAR_UNIT(delta_height));
  2068. SERIAL_ECHOPAIR_P(port, " S", delta_segments_per_second);
  2069. SERIAL_ECHOPAIR_P(port, " B", LINEAR_UNIT(delta_calibration_radius));
  2070. SERIAL_ECHOPAIR_P(port, " X", LINEAR_UNIT(delta_tower_angle_trim[A_AXIS]));
  2071. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(delta_tower_angle_trim[B_AXIS]));
  2072. SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(delta_tower_angle_trim[C_AXIS]));
  2073. SERIAL_EOL_P(port);
  2074. #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  2075. if (!forReplay) {
  2076. CONFIG_ECHO_START;
  2077. SERIAL_ECHOLNPGM_P(port, "Endstop adjustment:");
  2078. }
  2079. CONFIG_ECHO_START;
  2080. SERIAL_ECHOPGM_P(port, " M666");
  2081. #if ENABLED(X_DUAL_ENDSTOPS)
  2082. SERIAL_ECHOPAIR_P(port, " X", LINEAR_UNIT(endstops.x2_endstop_adj));
  2083. #endif
  2084. #if ENABLED(Y_DUAL_ENDSTOPS)
  2085. SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(endstops.y2_endstop_adj));
  2086. #endif
  2087. #if ENABLED(Z_TRIPLE_ENDSTOPS)
  2088. SERIAL_ECHOLNPAIR_P(port, "S1 Z", LINEAR_UNIT(endstops.z2_endstop_adj));
  2089. CONFIG_ECHO_START;
  2090. SERIAL_ECHOPAIR_P(port, " M666 S2 Z", LINEAR_UNIT(endstops.z3_endstop_adj));
  2091. #elif ENABLED(Z_DUAL_ENDSTOPS)
  2092. SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(endstops.z2_endstop_adj));
  2093. #endif
  2094. SERIAL_EOL_P(port);
  2095. #endif // [XYZ]_DUAL_ENDSTOPS
  2096. #if ENABLED(ULTIPANEL)
  2097. if (!forReplay) {
  2098. CONFIG_ECHO_START;
  2099. SERIAL_ECHOLNPGM_P(port, "Material heatup parameters:");
  2100. }
  2101. for (uint8_t i = 0; i < COUNT(lcd_preheat_hotend_temp); i++) {
  2102. CONFIG_ECHO_START;
  2103. SERIAL_ECHOPAIR_P(port, " M145 S", (int)i);
  2104. SERIAL_ECHOPAIR_P(port, " H", TEMP_UNIT(lcd_preheat_hotend_temp[i]));
  2105. SERIAL_ECHOPAIR_P(port, " B", TEMP_UNIT(lcd_preheat_bed_temp[i]));
  2106. SERIAL_ECHOLNPAIR_P(port, " F", lcd_preheat_fan_speed[i]);
  2107. }
  2108. #endif // ULTIPANEL
  2109. #if HAS_PID_HEATING
  2110. if (!forReplay) {
  2111. CONFIG_ECHO_START;
  2112. SERIAL_ECHOLNPGM_P(port, "PID settings:");
  2113. }
  2114. #if ENABLED(PIDTEMP)
  2115. #if HOTENDS > 1
  2116. if (forReplay) {
  2117. HOTEND_LOOP() {
  2118. CONFIG_ECHO_START;
  2119. SERIAL_ECHOPAIR_P(port, " M301 E", e);
  2120. SERIAL_ECHOPAIR_P(port, " P", PID_PARAM(Kp, e));
  2121. SERIAL_ECHOPAIR_P(port, " I", unscalePID_i(PID_PARAM(Ki, e)));
  2122. SERIAL_ECHOPAIR_P(port, " D", unscalePID_d(PID_PARAM(Kd, e)));
  2123. #if ENABLED(PID_EXTRUSION_SCALING)
  2124. SERIAL_ECHOPAIR_P(port, " C", PID_PARAM(Kc, e));
  2125. if (e == 0) SERIAL_ECHOPAIR_P(port, " L", thermalManager.lpq_len);
  2126. #endif
  2127. SERIAL_EOL_P(port);
  2128. }
  2129. }
  2130. else
  2131. #endif // HOTENDS > 1
  2132. // !forReplay || HOTENDS == 1
  2133. {
  2134. CONFIG_ECHO_START;
  2135. SERIAL_ECHOPAIR_P(port, " M301 P", PID_PARAM(Kp, 0)); // for compatibility with hosts, only echo values for E0
  2136. SERIAL_ECHOPAIR_P(port, " I", unscalePID_i(PID_PARAM(Ki, 0)));
  2137. SERIAL_ECHOPAIR_P(port, " D", unscalePID_d(PID_PARAM(Kd, 0)));
  2138. #if ENABLED(PID_EXTRUSION_SCALING)
  2139. SERIAL_ECHOPAIR_P(port, " C", PID_PARAM(Kc, 0));
  2140. SERIAL_ECHOPAIR_P(port, " L", thermalManager.lpq_len);
  2141. #endif
  2142. SERIAL_EOL_P(port);
  2143. }
  2144. #endif // PIDTEMP
  2145. #if ENABLED(PIDTEMPBED)
  2146. CONFIG_ECHO_START;
  2147. SERIAL_ECHOPAIR_P(port, " M304 P", thermalManager.bedKp);
  2148. SERIAL_ECHOPAIR_P(port, " I", unscalePID_i(thermalManager.bedKi));
  2149. SERIAL_ECHOPAIR_P(port, " D", unscalePID_d(thermalManager.bedKd));
  2150. SERIAL_EOL_P(port);
  2151. #endif
  2152. #endif // PIDTEMP || PIDTEMPBED
  2153. #if HAS_LCD_CONTRAST
  2154. if (!forReplay) {
  2155. CONFIG_ECHO_START;
  2156. SERIAL_ECHOLNPGM_P(port, "LCD Contrast:");
  2157. }
  2158. CONFIG_ECHO_START;
  2159. SERIAL_ECHOLNPAIR_P(port, " M250 C", lcd_contrast);
  2160. #endif
  2161. #if ENABLED(FWRETRACT)
  2162. if (!forReplay) {
  2163. CONFIG_ECHO_START;
  2164. SERIAL_ECHOLNPGM_P(port, "Retract: S<length> F<units/m> Z<lift>");
  2165. }
  2166. CONFIG_ECHO_START;
  2167. SERIAL_ECHOPAIR_P(port, " M207 S", LINEAR_UNIT(fwretract.retract_length));
  2168. SERIAL_ECHOPAIR_P(port, " W", LINEAR_UNIT(fwretract.swap_retract_length));
  2169. SERIAL_ECHOPAIR_P(port, " F", MMS_TO_MMM(LINEAR_UNIT(fwretract.retract_feedrate_mm_s)));
  2170. SERIAL_ECHOLNPAIR_P(port, " Z", LINEAR_UNIT(fwretract.retract_zlift));
  2171. if (!forReplay) {
  2172. CONFIG_ECHO_START;
  2173. SERIAL_ECHOLNPGM_P(port, "Recover: S<length> F<units/m>");
  2174. }
  2175. CONFIG_ECHO_START;
  2176. SERIAL_ECHOPAIR_P(port, " M208 S", LINEAR_UNIT(fwretract.retract_recover_length));
  2177. SERIAL_ECHOPAIR_P(port, " W", LINEAR_UNIT(fwretract.swap_retract_recover_length));
  2178. SERIAL_ECHOLNPAIR_P(port, " F", MMS_TO_MMM(LINEAR_UNIT(fwretract.retract_recover_feedrate_mm_s)));
  2179. #if ENABLED(FWRETRACT_AUTORETRACT)
  2180. if (!forReplay) {
  2181. CONFIG_ECHO_START;
  2182. SERIAL_ECHOLNPGM_P(port, "Auto-Retract: S=0 to disable, 1 to interpret E-only moves as retract/recover");
  2183. }
  2184. CONFIG_ECHO_START;
  2185. SERIAL_ECHOLNPAIR_P(port, " M209 S", fwretract.autoretract_enabled ? 1 : 0);
  2186. #endif // FWRETRACT_AUTORETRACT
  2187. #endif // FWRETRACT
  2188. /**
  2189. * Probe Offset
  2190. */
  2191. #if HAS_BED_PROBE
  2192. if (!forReplay) {
  2193. CONFIG_ECHO_START;
  2194. SERIAL_ECHOPGM_P(port, "Z-Probe Offset (mm):");
  2195. SAY_UNITS_P(port, true);
  2196. }
  2197. CONFIG_ECHO_START;
  2198. SERIAL_ECHOLNPAIR_P(port, " M851 Z", LINEAR_UNIT(zprobe_zoffset));
  2199. #endif
  2200. /**
  2201. * Bed Skew Correction
  2202. */
  2203. #if ENABLED(SKEW_CORRECTION_GCODE)
  2204. if (!forReplay) {
  2205. CONFIG_ECHO_START;
  2206. SERIAL_ECHOLNPGM_P(port, "Skew Factor: ");
  2207. }
  2208. CONFIG_ECHO_START;
  2209. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  2210. SERIAL_ECHOPGM_P(port, " M852 I");
  2211. SERIAL_ECHO_F_P(port, LINEAR_UNIT(planner.xy_skew_factor), 6);
  2212. SERIAL_ECHOPGM_P(port, " J");
  2213. SERIAL_ECHO_F_P(port, LINEAR_UNIT(planner.xz_skew_factor), 6);
  2214. SERIAL_ECHOPGM_P(port, " K");
  2215. SERIAL_ECHO_F_P(port, LINEAR_UNIT(planner.yz_skew_factor), 6);
  2216. SERIAL_EOL_P(port);
  2217. #else
  2218. SERIAL_ECHOPGM_P(port, " M852 S");
  2219. SERIAL_ECHO_F_P(port, LINEAR_UNIT(planner.xy_skew_factor), 6);
  2220. SERIAL_EOL_P(port);
  2221. #endif
  2222. #endif
  2223. #if HAS_TRINAMIC
  2224. /**
  2225. * TMC stepper driver current
  2226. */
  2227. if (!forReplay) {
  2228. CONFIG_ECHO_START;
  2229. SERIAL_ECHOLNPGM_P(port, "Stepper driver current:");
  2230. }
  2231. CONFIG_ECHO_START;
  2232. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
  2233. say_M906(PORTVAR_SOLO);
  2234. #endif
  2235. #if AXIS_IS_TMC(X)
  2236. SERIAL_ECHOPAIR_P(port, " X", stepperX.getMilliamps());
  2237. #endif
  2238. #if AXIS_IS_TMC(Y)
  2239. SERIAL_ECHOPAIR_P(port, " Y", stepperY.getMilliamps());
  2240. #endif
  2241. #if AXIS_IS_TMC(Z)
  2242. SERIAL_ECHOPAIR_P(port, " Z", stepperZ.getMilliamps());
  2243. #endif
  2244. #if AXIS_IS_TMC(X) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Z)
  2245. SERIAL_EOL_P(port);
  2246. #endif
  2247. #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
  2248. say_M906(PORTVAR_SOLO);
  2249. SERIAL_ECHOPGM_P(port, " I1");
  2250. #endif
  2251. #if AXIS_IS_TMC(X2)
  2252. SERIAL_ECHOPAIR_P(port, " X", stepperX2.getMilliamps());
  2253. #endif
  2254. #if AXIS_IS_TMC(Y2)
  2255. SERIAL_ECHOPAIR_P(port, " Y", stepperY2.getMilliamps());
  2256. #endif
  2257. #if AXIS_IS_TMC(Z2)
  2258. SERIAL_ECHOPAIR_P(port, " Z", stepperZ2.getMilliamps());
  2259. #endif
  2260. #if AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z2)
  2261. SERIAL_EOL_P(port);
  2262. #endif
  2263. #if AXIS_IS_TMC(Z3)
  2264. say_M906(PORTVAR_SOLO);
  2265. SERIAL_ECHOLNPAIR_P(port, " I2 Z", stepperZ3.getMilliamps());
  2266. #endif
  2267. #if AXIS_IS_TMC(E0)
  2268. say_M906(PORTVAR_SOLO);
  2269. SERIAL_ECHOLNPAIR_P(port, " T0 E", stepperE0.getMilliamps());
  2270. #endif
  2271. #if AXIS_IS_TMC(E1)
  2272. say_M906(PORTVAR_SOLO);
  2273. SERIAL_ECHOLNPAIR_P(port, " T1 E", stepperE1.getMilliamps());
  2274. #endif
  2275. #if AXIS_IS_TMC(E2)
  2276. say_M906(PORTVAR_SOLO);
  2277. SERIAL_ECHOLNPAIR_P(port, " T2 E", stepperE2.getMilliamps());
  2278. #endif
  2279. #if AXIS_IS_TMC(E3)
  2280. say_M906(PORTVAR_SOLO);
  2281. SERIAL_ECHOLNPAIR_P(port, " T3 E", stepperE3.getMilliamps());
  2282. #endif
  2283. #if AXIS_IS_TMC(E4)
  2284. say_M906(PORTVAR_SOLO);
  2285. SERIAL_ECHOLNPAIR_P(port, " T4 E", stepperE4.getMilliamps());
  2286. #endif
  2287. #if AXIS_IS_TMC(E5)
  2288. say_M906(PORTVAR_SOLO);
  2289. SERIAL_ECHOLNPAIR_P(port, " T5 E", stepperE5.getMilliamps());
  2290. #endif
  2291. SERIAL_EOL_P(port);
  2292. /**
  2293. * TMC Hybrid Threshold
  2294. */
  2295. #if ENABLED(HYBRID_THRESHOLD)
  2296. if (!forReplay) {
  2297. CONFIG_ECHO_START;
  2298. SERIAL_ECHOLNPGM_P(port, "Hybrid Threshold:");
  2299. }
  2300. CONFIG_ECHO_START;
  2301. #if AXIS_HAS_STEALTHCHOP(X) || AXIS_HAS_STEALTHCHOP(Y) || AXIS_HAS_STEALTHCHOP(Z)
  2302. say_M913(PORTVAR_SOLO);
  2303. #endif
  2304. #if AXIS_HAS_STEALTHCHOP(X)
  2305. SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X));
  2306. #endif
  2307. #if AXIS_HAS_STEALTHCHOP(Y)
  2308. SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y));
  2309. #endif
  2310. #if AXIS_HAS_STEALTHCHOP(Z)
  2311. SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z));
  2312. #endif
  2313. #if AXIS_HAS_STEALTHCHOP(X) || AXIS_HAS_STEALTHCHOP(Y) || AXIS_HAS_STEALTHCHOP(Z)
  2314. SERIAL_EOL_P(port);
  2315. #endif
  2316. #if AXIS_HAS_STEALTHCHOP(X2) || AXIS_HAS_STEALTHCHOP(Y2) || AXIS_HAS_STEALTHCHOP(Z2)
  2317. say_M913(PORTVAR_SOLO);
  2318. SERIAL_ECHOPGM_P(port, " I1");
  2319. #endif
  2320. #if AXIS_HAS_STEALTHCHOP(X2)
  2321. SERIAL_ECHOPAIR_P(port, " X", TMC_GET_PWMTHRS(X, X2));
  2322. #endif
  2323. #if AXIS_HAS_STEALTHCHOP(Y2)
  2324. SERIAL_ECHOPAIR_P(port, " Y", TMC_GET_PWMTHRS(Y, Y2));
  2325. #endif
  2326. #if AXIS_HAS_STEALTHCHOP(Z2)
  2327. SERIAL_ECHOPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z2));
  2328. #endif
  2329. #if AXIS_HAS_STEALTHCHOP(X2) || AXIS_HAS_STEALTHCHOP(Y2) || AXIS_HAS_STEALTHCHOP(Z2)
  2330. SERIAL_EOL_P(port);
  2331. #endif
  2332. #if AXIS_HAS_STEALTHCHOP(Z3)
  2333. say_M913(PORTVAR_SOLO);
  2334. SERIAL_ECHOPGM_P(port, " I2");
  2335. SERIAL_ECHOLNPAIR_P(port, " Z", TMC_GET_PWMTHRS(Z, Z3));
  2336. #endif
  2337. #if AXIS_HAS_STEALTHCHOP(E0)
  2338. say_M913(PORTVAR_SOLO);
  2339. SERIAL_ECHOLNPAIR_P(port, " T0 E", TMC_GET_PWMTHRS(E, E0));
  2340. #endif
  2341. #if AXIS_HAS_STEALTHCHOP(E1)
  2342. say_M913(PORTVAR_SOLO);
  2343. SERIAL_ECHOLNPAIR_P(port, " T1 E", TMC_GET_PWMTHRS(E, E1));
  2344. #endif
  2345. #if AXIS_HAS_STEALTHCHOP(E2)
  2346. say_M913(PORTVAR_SOLO);
  2347. SERIAL_ECHOLNPAIR_P(port, " T2 E", TMC_GET_PWMTHRS(E, E2));
  2348. #endif
  2349. #if AXIS_HAS_STEALTHCHOP(E3)
  2350. say_M913(PORTVAR_SOLO);
  2351. SERIAL_ECHOLNPAIR_P(port, " T3 E", TMC_GET_PWMTHRS(E, E3));
  2352. #endif
  2353. #if AXIS_HAS_STEALTHCHOP(E4)
  2354. say_M913(PORTVAR_SOLO);
  2355. SERIAL_ECHOLNPAIR_P(port, " T4 E", TMC_GET_PWMTHRS(E, E4));
  2356. #endif
  2357. #if AXIS_HAS_STEALTHCHOP(E5)
  2358. say_M913(PORTVAR_SOLO);
  2359. SERIAL_ECHOLNPAIR_P(port, " T5 E", TMC_GET_PWMTHRS(E, E5));
  2360. #endif
  2361. SERIAL_EOL_P(port);
  2362. #endif // HYBRID_THRESHOLD
  2363. /**
  2364. * TMC Sensorless homing thresholds
  2365. */
  2366. #if USE_SENSORLESS
  2367. if (!forReplay) {
  2368. CONFIG_ECHO_START;
  2369. SERIAL_ECHOLNPGM_P(port, "TMC2130 StallGuard threshold:");
  2370. }
  2371. CONFIG_ECHO_START;
  2372. #if X_SENSORLESS || Y_SENSORLESS || Z_SENSORLESS
  2373. say_M914(PORTVAR_SOLO);
  2374. #if X_SENSORLESS
  2375. SERIAL_ECHOPAIR_P(port, " X", stepperX.sgt());
  2376. #endif
  2377. #if Y_SENSORLESS
  2378. SERIAL_ECHOPAIR_P(port, " Y", stepperY.sgt());
  2379. #endif
  2380. #if Z_SENSORLESS
  2381. SERIAL_ECHOPAIR_P(port, " Z", stepperZ.sgt());
  2382. #endif
  2383. SERIAL_EOL_P(port);
  2384. #endif
  2385. #define HAS_X2_SENSORLESS (defined(X_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(X2))
  2386. #define HAS_Y2_SENSORLESS (defined(Y_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Y2))
  2387. #define HAS_Z2_SENSORLESS (defined(Z_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z2))
  2388. #define HAS_Z3_SENSORLESS (defined(Z_STALL_SENSITIVITY) && AXIS_HAS_STALLGUARD(Z3))
  2389. #if HAS_X2_SENSORLESS || HAS_Y2_SENSORLESS || HAS_Z2_SENSORLESS
  2390. say_M914(PORTVAR_SOLO);
  2391. SERIAL_ECHOPGM_P(port, " I1");
  2392. #if HAS_X2_SENSORLESS
  2393. SERIAL_ECHOPAIR_P(port, " X", stepperX2.sgt());
  2394. #endif
  2395. #if HAS_Y2_SENSORLESS
  2396. SERIAL_ECHOPAIR_P(port, " Y", stepperY2.sgt());
  2397. #endif
  2398. #if HAS_Z2_SENSORLESS
  2399. SERIAL_ECHOPAIR_P(port, " Z", stepperZ2.sgt());
  2400. #endif
  2401. SERIAL_EOL_P(port);
  2402. #endif
  2403. #if HAS_Z3_SENSORLESS
  2404. say_M914(PORTVAR_SOLO);
  2405. SERIAL_ECHOPGM_P(port, " I2");
  2406. SERIAL_ECHOLNPAIR_P(port, " Z", stepperZ3.sgt());
  2407. #endif
  2408. #endif // USE_SENSORLESS
  2409. #endif // HAS_TRINAMIC
  2410. /**
  2411. * Linear Advance
  2412. */
  2413. #if ENABLED(LIN_ADVANCE)
  2414. if (!forReplay) {
  2415. CONFIG_ECHO_START;
  2416. SERIAL_ECHOLNPGM_P(port, "Linear Advance:");
  2417. }
  2418. CONFIG_ECHO_START;
  2419. #if EXTRUDERS < 2
  2420. SERIAL_ECHOLNPAIR_P(port, " M900 K", planner.extruder_advance_K[0]);
  2421. #else
  2422. LOOP_L_N(i, EXTRUDERS) {
  2423. SERIAL_ECHOPAIR_P(port, " M900 T", int(i));
  2424. SERIAL_ECHOLNPAIR_P(port, " K", planner.extruder_advance_K[i]);
  2425. }
  2426. #endif
  2427. #endif
  2428. #if HAS_MOTOR_CURRENT_PWM
  2429. CONFIG_ECHO_START;
  2430. if (!forReplay) {
  2431. SERIAL_ECHOLNPGM_P(port, "Stepper motor currents:");
  2432. CONFIG_ECHO_START;
  2433. }
  2434. SERIAL_ECHOPAIR_P(port, " M907 X", stepper.motor_current_setting[0]);
  2435. SERIAL_ECHOPAIR_P(port, " Z", stepper.motor_current_setting[1]);
  2436. SERIAL_ECHOPAIR_P(port, " E", stepper.motor_current_setting[2]);
  2437. SERIAL_EOL_P(port);
  2438. #endif
  2439. /**
  2440. * Advanced Pause filament load & unload lengths
  2441. */
  2442. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2443. if (!forReplay) {
  2444. CONFIG_ECHO_START;
  2445. SERIAL_ECHOLNPGM_P(port, "Filament load/unload lengths:");
  2446. }
  2447. CONFIG_ECHO_START;
  2448. #if EXTRUDERS == 1
  2449. say_M603(PORTVAR_SOLO);
  2450. SERIAL_ECHOPAIR_P(port, "L", LINEAR_UNIT(filament_change_load_length[0]));
  2451. SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[0]));
  2452. #else
  2453. say_M603(PORTVAR_SOLO);
  2454. SERIAL_ECHOPAIR_P(port, "T0 L", LINEAR_UNIT(filament_change_load_length[0]));
  2455. SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[0]));
  2456. CONFIG_ECHO_START;
  2457. say_M603(PORTVAR_SOLO);
  2458. SERIAL_ECHOPAIR_P(port, "T1 L", LINEAR_UNIT(filament_change_load_length[1]));
  2459. SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[1]));
  2460. #if EXTRUDERS > 2
  2461. CONFIG_ECHO_START;
  2462. say_M603(PORTVAR_SOLO);
  2463. SERIAL_ECHOPAIR_P(port, "T2 L", LINEAR_UNIT(filament_change_load_length[2]));
  2464. SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[2]));
  2465. #if EXTRUDERS > 3
  2466. CONFIG_ECHO_START;
  2467. say_M603(PORTVAR_SOLO);
  2468. SERIAL_ECHOPAIR_P(port, "T3 L", LINEAR_UNIT(filament_change_load_length[3]));
  2469. SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[3]));
  2470. #if EXTRUDERS > 4
  2471. CONFIG_ECHO_START;
  2472. say_M603(PORTVAR_SOLO);
  2473. SERIAL_ECHOPAIR_P(port, "T4 L", LINEAR_UNIT(filament_change_load_length[4]));
  2474. SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[4]));
  2475. #if EXTRUDERS > 5
  2476. CONFIG_ECHO_START;
  2477. say_M603(PORTVAR_SOLO);
  2478. SERIAL_ECHOPAIR_P(port, "T5 L", LINEAR_UNIT(filament_change_load_length[5]));
  2479. SERIAL_ECHOLNPAIR_P(port, " U", LINEAR_UNIT(filament_change_unload_length[5]));
  2480. #endif // EXTRUDERS > 5
  2481. #endif // EXTRUDERS > 4
  2482. #endif // EXTRUDERS > 3
  2483. #endif // EXTRUDERS > 2
  2484. #endif // EXTRUDERS == 1
  2485. #endif // ADVANCED_PAUSE_FEATURE
  2486. }
  2487. #endif // !DISABLE_M503