-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize and encapsulate Power-Loss Recovery #12440
Optimize and encapsulate Power-Loss Recovery #12440
Conversation
e28d07d
to
1325cc6
Compare
Do not let Z rise to the right height, only on the first layer change ...
Now Z is at current position + RECOVERY_ZRAISE, it's ok but you must add command G1 Z info.current position
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can easily save 7 bytes of SRAM by compacting all those static bools into bitfields!
Thanks! I thought that was already in there, for some reason. |
1325cc6
to
9f70507
Compare
The ones that are convenient to combine save 5 bytes of SRAM but cost 42 bytes of program memory. So, maybe worth it, maybe not. 5 bytes of SRAM isn't much in the big picture. Maybe there are some algorithms that can be optimized for more significant savings. |
99bcc5a
to
ff70b7d
Compare
ff70b7d
to
ee3f10c
Compare
Yes, but on embedded devices, usually SRAM is the most valuable resource: And i also agree with your idea of trying to reduce statics at the expense of local variables. That is also a win The only places where this can´t be done is on the stepper ISR, where we prioritize execution speed and atomic access over SRAM consumption - And on AVR there is even a possibility to improve the stepper, by decreasing the size of the accumulator, when the number of steps is small .. It can yield HUGE savings on execution time on AVR (on ARM there is no advantage at all, quite in fact, reducing accumulator size incurs a penalty in execution time) |
True… but ironically, the 1284 has 16K of SRAM, so it's twice as important to save program memory for the benefit of those devices than it is to save SRAM. |
2a23a7f
to
b66bfd8
Compare
Perhaps we should do an audit to try to figure out what piece of code is taking the most part of FLASH, and optimize it ... I still think the LCD menus should be a finite state machine and the menus themselves should be defined by tables in FLASH |
Making the menus into data structures would be an interesting exercise. One effective optimization I did at one point was to move the scrolling code that was being repeated in every menu handler into a separate function. I also modified the menu item loop to only iterate over the visible items. The commonalities beyond that are harder to discern, as there are some menu items that should only appear under certain conditions, and there's a free mixture of back/cancel/function items, sub-menus for editing, static items, and so on. Probably some more of the logic currently embedded in menu macros can be split out to common functions. My next task —now that power-loss recovery has been optimized to save loads of SRAM— is to reduce the amount of rendering on the graphical status screen by having a first-time render and then a change-only render on subsequent updates. This would allow for a more graphic display of the hotend and bed heating status, among other things. It should also allow a more free arrangement of heater icons, and should save a lot of flash by not requiring a full header for every fan animation frame. Once I get through that work, I will revisit the menu items and see what other optimizations are possible. |
@thinkyhead : What you want to achieve on the
Is impossible if you use u8glib. u8glib ALWAYS requires a full render. |
@ejtagle — Yep, I can confirm there's no facility in |
@thinkyhead ; Right now there is no FLASH usage strategy as far as I can tell. Bitmaps are small, fonts are "small" ... We could compress them and decompress them on the fly, and that could save maybe 50% of the font size or even more (i have played with that idea previously, i did an implementation and i know that it works very well) |
Some time ago we did not switch to u8g2-lib because we couldn't get the same speed as u8g-lib on the ST7920 based displays. Mainly because of the slower transfer rate. Since some days (weeks?) u8g2 seems to support refreshing of dirty rectangles. If the speed winn by that is big enough, we could start another try. |
Dirty rectangles technique is a big win, if the amount of screen area that is actually changing is small compared with the total screen area. |
|
@thinkyhead : Something that should be taken into account is the price of FORCE_INLINE. I do agree that if speed is the utmost important thing, FORCE_INLINE is a win situation.
So, that is something we can also play with. |
Yes, as you can see from 471f403 I've been doing testing along those lines. |
* Synchronize on M204, M205 (MarlinFirmware#12302) * Add parser.seen for multiple parameters * Fix M666, use !seen for report * Synchronize on M204, M205 * Ignore ARM-based Teensy library on ATUSB90-based Teensy (MarlinFirmware#12311) Works around PIO src_filter behavior (see platformio/platformio-core#1905) * Tweak / reduce menu items * IS_DELTA => ENABLED(DELTA) * Clear up HAS_WORKSPACE_OFFSET meaning * Revive SCARA's home offset (unimplemented) * Use first_page flag in place of page.page == 0 * Apply #pragma once, misc cleanup (MarlinFirmware#12322) * Apply #pragma once in headers * Adjust some thermistors formatting * Misc cleanup and formatting * Fix broken LPC176x build (MarlinFirmware#12317) * Fix broken LPC176x build * Add UBL+HD44780 test for LPC1768 * Return to status to show manual deploy/stow messages (MarlinFirmware#12324) * Add servos to pins_FYSTEC_F6_13.h * Remove dead comment * Fix VMAX editing Fix MarlinFirmware#12326 * Use board-specific or platform SPI pins in HAL_STM32 (MarlinFirmware#12323) * Suppress some compile warnings * Fix EEPROM servo angles init, section grouping * Drop 'register' storage specifier * Provide DOGLCD SPI pins for MKS SBASE + VIKI * Update Italian language (MarlinFirmware#12327) * Allow disable of LCD_TIMEOUT_TO_STATUS (when 0) * Clean up some U8G files * Clean up file endings * Turn PlatformIO LDF off for LPC176x builds (MarlinFirmware#12334) * Update, correct sanity-checks for up to 6 extruders (MarlinFirmware#12333) * Extend error messages for E factors sanity-checks * ENABLED(NEWPANEL) => HAS_LCD_MENU * MSG_UBL_EDIT_MESH_MENU => MSG_EDIT_MESH * Add a mesh edit menu for MBL / ABL-Bilinear * Add MESH_EDIT_MENU to example configs * Cleanups for leveling-related code * M420 support in MARLIN_DEV_MODE * Fix endstops enable behavior during probing Fix a bug introduced in MarlinFirmware#9582 * Recommend keeping endstops off * Fix 'M43 T' to use 'L' as last pin - The documentation is correct. The code was wrong. * Provide a default for Z_PROBE_LOW_POINT * Use multiplier edit item for mesh point editing * Update and fix CHDK * Clean up ENCODER_RATE_MULTIPLIER config * G28 O respects HOME_AFTER_DEACTIVATE Addressing MarlinFirmware#11271 * Prevent current step-down going negative Addressing MarlinFirmware#11348 * Fix "circle" * Fix MBL XY parameter error messages Fix MarlinFirmware#11522 * Updated slovak translation (MarlinFirmware#12338) * Update German language (MarlinFirmware#12336) * Hide mesh editing until a valid mesh exists * Restore LPC1768_PIN_INTERRUPT_M, apply to Z3 - In reference to MarlinFirmware#12166 * Clean up bq Zum Mega 3D pins * Remove trailing whitespace * Add Geeetech Rostock 301 config, update GTM32 Pro VB pins (MarlinFirmware#12345) * Update Italian language (MarlinFirmware#12344) * Change Marlin debug flag names to fix conflicts (MarlinFirmware#12340) In reference to MarlinFirmware#11000 * LCD menu code refactoring and cleanup (MarlinFirmware#12308) * Show the appropriate pause message (MarlinFirmware#12348) * Fixed advanced pause messages (MarlinFirmware#12353) * Apply some tool-change cleanup * More advanced pause tweaks (MarlinFirmware#12356) * Followup to LCD_TIMEOUT_TO_STATUS=0 * Make continuous purge screen fit 20x4 * Unify purge message modes * Preserve last-set pause header mode * Update German translation (MarlinFirmware#12355) * Update Slovak translation (MarlinFirmware#12354) * Update Italian language (MarlinFirmware#12352) * Fix const pointer assignment compile error (MarlinFirmware#12350) * Use IS_SD_PRINTING() more * Use card.stopSDPrint() for completeness * Fix Resume from SD Pause In reference to MarlinFirmware#12098 (comment) * Restore GTM32_PRO_VB temp and heater pins Undo MarlinFirmware#12345 * Set CUSTOM_MACHINE_NAME for some configs * Combine more tool-change variables (MarlinFirmware#12137) * Fix up xdiff, ydiff, zdiff in tool change Followup to MarlinFirmware#12137 * Clean trailing whitespace * Apply HAS_LCD_MENU in EEPROM code * Remove obsolete comments * Extend pins errors to include the processor * More comprehensive NO_LCD_MENUS (MarlinFirmware#12367) * No error on T0 with single-extruder and fix MIXING_EXTRUDER virtual tools (MarlinFirmware#12375) * Update Slovak translation (MarlinFirmware#12376) * Update Italian language (MarlinFirmware#12368) * [2.0.x] Macro G-codes (MarlinFirmware#9365) * Fix M91x sanity-check to permit TMC2660 Fix MarlinFirmware#12362 * Solve endstops issues (MarlinFirmware#12382) - Partially reverts MarlinFirmware#11900 and tries to solve MarlinFirmware#12336 * Update German language (MarlinFirmware#12379) * Have 'mfdoc' open the local site when it's ready * Add reference comments to MeshLevelingState * Break out of 'mfpub' if 'gh-pages' checkout fails * Use 'serial_spaces' in 'print_2d_array' * Tweak 'echo_not_entered' used by MBL's G29 * Tevo Little Monster example configuration (MarlinFirmware#12370) * Allow G26 to use the active extruder (MarlinFirmware#12387) * Make lcd_quick_feedback argument optional * Add click_to_cancel option to wait_for_hotend/bed * Have G26 use the active nozzle and wait_for_hotend/bed * Use wait_for_release in UBL G29 * Add 'T' parameter to G26 for an initial tool-change * Update Raptor config * Update HAL and libs formatting * Reduce code size with plain inlines * Apply extra condition to LCD_PROGRESS_BAR * Adjust some comment spacing * Encapsulate common display code in a singleton (MarlinFirmware#12395) * Encapsulate common LCD code in a singleton * Depend more UBL code on UBL_DEVEL_DEBUGGING - Since most users don't need the debugging on at all times, this helps reduce the default build size for UBL by over 2K, a little closer to fitting on 128K boards. * Clean up LCD width/height determination * For now (!) don't synchronize in M204 and M205 See if this has any deleterious effect on motion planning by slicers that inser their own jerk and acceleration controls. The problem I see is that these settings can take effect on blocks already in the planner, and the only way around this would be to shadow these settings in planner blocks and use the shadowed settings in the planner. * Update UBL comments for debug change * Differentiate translated On/Off from Serial ON/OFF * Fix BABYSTEP_ZPROBE_OFFSET (MarlinFirmware#12408) Fix MarlinFirmware#12399 Did not compile without `WATCH_HOTENDS || WATCH_THE_BED`. Add condition to include "../../module/temperature.h". * Clear old _site contents on regeneration * Followup to 50af1d1 * Add M412 to enable/disable filament runout detection (MarlinFirmware#12406) * Clean TLM trailing whitespace * Group status methods, share reset_status with Extensible UI (MarlinFirmware#12414) * Group status methods, share reset_status with Extensible UI * Move common DOGM code to headers * Refine endstops fixes (MarlinFirmware#12413) When endstops/probe are enabled `ENDSTOP_NOISE_THRESHOLD` calls to `update` are required to properly re-sync endstops/probe status. * Fix tool-change for MIXING_EXTRUDER with < 2 virtual tools (MarlinFirmware#12417) Fix MarlinFirmware#12416 Better handling of `ENABLED(MIXING_EXTRUDER) && !MIXING_VIRTUAL_TOOLS > 1` - to not fall through to the general case. Fix compiler warnings for `#elif EXTRUDERS < 2`. * Debug of G2-G3 for UBL (MarlinFirmware#12386) Changes only affect UBL. Everything else is left alone. * Updates to Formbot T-Rex 2+ configuration files (MarlinFirmware#12422) Updates to Formbot T-Rex 2+ configuration files * Endstops fix followup (MarlinFirmware#12423) Followup to MarlinFirmware#12413 * Add required "cardreader.h" include (MarlinFirmware#12419) * Update Portuguese-Brazilian translation (MarlinFirmware#12402) * Fix Formbot Trex-2+ configs Followup to MarlinFirmware#12422 * Clean up pins files * UltiMachine Archim 1 support (MarlinFirmware#12404) * Fix an old sanity check * hasstatus => has_status * Move RRW keypad code to a common method (MarlinFirmware#12429) * Rejigger Filament Runout class (MarlinFirmware#12428) * Miscellaneous LCD code renaming, reordering (MarlinFirmware#12430) * Move special characters to language.h * Apply some naming standards * Clean up menu item draw functions * Rename some Temperature methods * UI => ExtUI * Fix to runout sensor code. (MarlinFirmware#12431) - "old_state" is no longer a class static variable. * Optimize target_extruder, ignore T with mixing (MarlinFirmware#12432) * Optimize target_extruder, ignore T with mixing * Give G-code Tn parity with tool_change * Fix GcodeSuite::T active_extruder reference * Tweak extruder errors * No need for Cap:PAREN_COMMENTS * Support two MAX6675 thermocouples (MarlinFirmware#8686) * Optimize Power-Loss Recovery (MarlinFirmware#12440) * Consolidate, optimize some LCD menu code (MarlinFirmware#12450) * Make CardReader class static (MarlinFirmware#12451) * Make CardReader a static class * Make CardReader flags into bitfields * Use 'target_extruder' in M104 as with M109 (MarlinFirmware#12448) * Enable SD Card on RepRap Display and RADDS (MarlinFirmware#12446) * Enable SD Card on RepRap Display and RADDS Define the necessary pins in `pins_RADDS.h` (copied from the `RADDS_DISPLAY` section) for the use of the SD card slot on RRD. * Fix a compile warning (MarlinFirmware#12452) * Allow float XY probe offsets Responding to MarlinFirmware#12383 XY probe offsets should be integers because adding decimal points makes the code larger. But if decimals are very much wanted, this commit removes the old restriction. * Followup to static CardReader * Change temperature pin order for RemRam V1 (MarlinFirmware#12458) Beta testers suggested to adopt the RAMPS order of temperature probe connectors. This commit fixes the order to the RAMPS order. * Fix compile error with SD_FIRMWARE_UPDATE (MarlinFirmware#12462) * Fix compile error with ZONESTAR_LCD+NO_LCD_MENUS (MarlinFirmware#12466) * Don't start watching heaters when target is 0 (MarlinFirmware#12453) * Various fixes for MarlinUI and ExtUI (MarlinFirmware#12439) * Remove extra include * Fix MAX_MESSAGE_LENGTH * Fix access to the DWT peripheral for STM32 HAL (MarlinFirmware#12434) Access to the DWT peripheral for the `CYCCNT` register needs to happen before `main()`. The code needs to be called after the setup of the system clocks, so the right place is between the `premain()` and `main()` function of the STM32 Arduino core. This patch moves the DWT access code to a new function, which is then placed between `premain()` and `main()`. * Fix "no effect" and "unused variable" compile warnings (MarlinFirmware#12473) * Update M303.cpp (MarlinFirmware#12471) * Fixed displaying of kill MSG_OUTAGE_RECOVERY string. (MarlinFirmware#12470) * GTM32 Pro VB changes from Markku Sinisalo * Combine Travis CI option-setting commands (MarlinFirmware#12474) * Fix LCD compile error, etc. (MarlinFirmware#12472) * Clean up some u8g code (MarlinFirmware#12476) * Get u8g reference for lcdprint * Modify MBL to use IJ instead of XY (MarlinFirmware#12478) * Corrected unused var, default switch, Travis tests (MarlinFirmware#12477) * Fix compilation errors. Followup to MarlinFirmware#12439 (MarlinFirmware#12481) * Fix for MarlinFirmware#12482 (MarlinFirmware#12483) Fix Z-move to uninitialized position in SWITCHING_EXTRUDERS tool_change (no_move=true) * Revert MarlinFirmware#12311 PIO LDF work-around (MarlinFirmware#12484) * Followup to MarlinFirmware#12451 * Apply/unapply const here and there * Shift YZ on graphical display to fit Z+123.45 * Don't show updir with no card present * Expanded options for _Statusscreen.h (MarlinFirmware#12455) See the PR for full details. The updated system will be documented on the website in the near future. * Revert some const changes (for now) * Fix ADC_KEYPAD middle button (MarlinFirmware#12493) * Invert hotend bitmaps, by default * General cleanup of Re-ARM pins * Fix problems with LPC1768 EEPROM flash emulation (MarlinFirmware#12503) * Remove duplicate calls to PrepareSector Some flash memory API calls require that a call to `PrepareSector` is done before use. However this call is already made by the LPC1768 framework so the calls in this code are not required. * Ensure correct alignment of RAM buffer The LPC176X flash API requires that the RAM buffer used for write operations must be word-aligned. This change ensures that this is the case. * Additional pin definitions for Archim 2 (MarlinFirmware#12500) - Added GPIO pins to Archim 2 - Added new 108 pin to `fastio_Due.h` * Use superscript 3 in language_en.h (MarlinFirmware#12504) * Fix a minor compile warning * Revert ADC_KEYPAD direction behavior (MarlinFirmware#12508) * Remove extra declarations in cardreader.cpp (MarlinFirmware#12520) * Fast PWM for controller fan (MarlinFirmware#12485) * Bring superscripts slightly lower in BDF fonts * Clean up font data generation script * Don't show superscript ³ with NOT_EXTENDED_ISO10646_1_5X7 (MarlinFirmware#12513) * Fix backslash in language_test.h * Use wait_for_bed with WAIT_FOR_BED_HEATER Addressing MarlinFirmware#12517 * Allow Serial Overrun Protection to be disabled * Hide some compile warnings * Put status screen options in Configuration_adv.h * Update Italian language (MarlinFirmware#12512) * NUM_ARRAY => COUNT * Update Turkish language (MarlinFirmware#12524) * Correct FANMUX2_PIN (MarlinFirmware#12538) * Update Slovak translation (MarlinFirmware#12523) * Fix wait_for_bed compile error * Add support for FYSETC F6 V1.3 board (MarlinFirmware#12527) * Fix English special symbols (MarlinFirmware#12529) * Adjust Formbot Raptor pins * Add missing boards to Makefile * Add Formbot Raptor2 and Raise3D pins (MarlinFirmware#12532) * Add Formbot Raptor2 board * Add Raise3D Rumba board * Add sample config for Delta with MKS SBASE (MarlinFirmware#10819) * Hide M217 compile warning * Improve runout sensor, fix LIGHTWEIGHT_UI screen size (MarlinFirmware#12544) * Save recovery info on SD pause * Space out multiple edit lines a bit * Fix runout debug output Followup to MarlinFirmware#12544 * Add poll_runout_states, which returns 1 for runouts (MarlinFirmware#12547) * Add heating progress bars (MarlinFirmware#12543) * Followup to heating progress * Fans loop macro * Fix "paused" message and M125 called by M25 (MarlinFirmware#12551) * Fix Skew factors (MarlinFirmware#12555) - Ensure Skew factors are calculated from test square measurements * Fix "No SD Card" indicator * Tweak FR icon. Update font data. * A single SERIAL_ECHO macro type (MarlinFirmware#12557) * Fix angles for disabled EDITABLE_SERVO_ANGLES (MarlinFirmware#12559) * Move stepper enable/disable to stepper_indirection.h (MarlinFirmware#12562) * Tweaks to endstops code * Remove AVR-only MARLIN_DEV_MODE code * Fix pause/resume SD print Followup to MarlinFirmware#12551, addressing MarlinFirmware#12566 * Alternative fan image option (MarlinFirmware#12579) * Alternative fan bitmap * Move bed over by 3px * Print a space after scrolling status * Don't include STM32 Core code when compiling STM32 Generic (MarlinFirmware#12575) * Build and CI fixes and optimizations (MarlinFirmware#12584) -Disable LDF "deep+" mode on AT90USB platforms. Appears not needed any longer (likely due to fix platformio/platformio-core@7322df2). Results in identical binary output and cuts compile time in half -Disable Cartesio config from CircleCI (compile failure) -Disable Geetech I3 Pro X GT2560 from CircleCI (compile failure) -Enable EEPROM on Micromake example config (fix compile failure) -Move FolgerTech/i3-2020 to AVR platform in CircleCI (fix CirculeCI build failure) -Disable various examples failing to build in CircleCI -Enable various examples no longer failing to build in CircleCI * Fix up some delta settings * Update mfpub * Trinamic: Split stealthChop, improve driver monitoring, etc. (MarlinFirmware#12582) * Signal an invalid mesh for M420 enable / load * Tweak config formatting * Link to font docs in ultralcd_DOGM.cpp * Sanity-check for negative steps, feedrate, accel * M425 Backlash Correction (MarlinFirmware#11061) * Add Z_MIN_PROBE_PIN to MKS SBASE pins * Refresh screen on SD Init * Followup to servo angles patch Fix MarlinFirmware#12594 * Simpler AVR + Trinamic + Soft Serial sanity-check (MarlinFirmware#12606) * Fix some serial echos of pin states * Center ABL grid on bed with H parameter. (MarlinFirmware#12610) * Align classic bed icon consistently * Improve some config comments readability (MarlinFirmware#12615) * Fix broken pins file include (MarlinFirmware#12617) * TMC connection test, spreadCycle parameters, improved debugging (MarlinFirmware#12616) * Sanity-check LIGHTWEIGHT_UI, move comment up (MarlinFirmware#12630) * Allow ExtUI to use LCD_SET_PROGRESS_MANUALLY (MarlinFirmware#12628) * Add spreadCycle parameter sets (MarlinFirmware#12645) * [2.0.x] G33 clean up (MarlinFirmware#12648) Remove obsolete workarounds in G33 for the now fixed zprobe_zoffset bug * [2.0.x] Enable PIDTEMPBED in Anet A8 example config (MarlinFirmware#12655) * [2.0.x] Set DEFAULT_NOMINAL_FILAMENT_DIA to 1.75 in Anet A6 config (MarlinFirmware#12664) * [2.0.x] Update Czech translation (MarlinFirmware#12683) * Squelch warning mentioned in MarlinFirmware#11061 (MarlinFirmware#12676) * [2.0.x] Limit PID autotune target to maxtemp-15 (MarlinFirmware#12691) * Limit set hotend temperature to maxtemp. (MarlinFirmware#12690) * Added MKS MINI 12864 support to FYSETC F6 V1.3 (MarlinFirmware#12656) * FYSETC F6 13 - E2_SERIAL_TX_PIN correction (MarlinFirmware#12667) * Followup to MarlinFirmware#12691 (typo) * GTM32 Pro VB FAN-PIN correction (MarlinFirmware#12666) * Add Formbot 350c Thermistor (MarlinFirmware#12661) * Add support for MKS Robin board (MarlinFirmware#12650) Implement initial support for MKS Robin (STM32F103ZET6) board. Custom build script is used to generate encrypted firmware compatible with original MSK Robin bootloader (i.e. safe firmware update from SD card and possibility to go back to original close-source firmware). * Wanhao Duplicator i3 Plus pins create (MarlinFirmware#12701) * Update Formbot T-Rex 3 pins (MarlinFirmware#12662)
The Power-Loss Recovery code as originally adapted was a more-or-less straight port of the version produced for the CR-10 by @Creality3DPrinting. Since that version was intended for the 1284 it could use SRAM with impunity. But this made the feature prohibitive for ATmega2560 and other chips with limited SRAM. This PR significantly reduces the SRAM usage, making the feature more accessible for RAMPS and derivatives.
M1000
to run power-loss-recovery in the command context.M143
to enable/disable power-loss recovery.