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

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