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

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