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

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