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

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