From 8090d365f640eb6c6e6157adefbfe94e37d6227f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 27 Dec 2021 10:47:52 -0500 Subject: [PATCH 001/211] docs: Add stm32g0b1 to benchmarks Signed-off-by: Kevin O'Connor --- docs/Benchmarks.md | 19 +++++++++++++++++++ docs/Features.md | 1 + 2 files changed, 20 insertions(+) diff --git a/docs/Benchmarks.md b/docs/Benchmarks.md index c1f298cd..7149c64a 100644 --- a/docs/Benchmarks.md +++ b/docs/Benchmarks.md @@ -248,6 +248,25 @@ results were obtained by running an STM32F407 binary on an STM32F446 | 1 stepper | 46 | | 3 stepper | 205 | +### STM32G0B1 step rate benchmark + +The following configuration sequence is used on the STM32G0B1: +``` +allocate_oids count=3 +config_stepper oid=0 step_pin=PB13 dir_pin=PB12 invert_step=-1 step_pulse_ticks=0 +config_stepper oid=1 step_pin=PB10 dir_pin=PB2 invert_step=-1 step_pulse_ticks=0 +config_stepper oid=2 step_pin=PB0 dir_pin=PC5 invert_step=-1 step_pulse_ticks=0 +finalize_config crc=0 +``` + +The test was last run on commit `247cd753` with gcc version +`arm-none-eabi-gcc (Fedora 10.2.0-4.fc34) 10.2.0`. + +| stm32f042 | ticks | +| ---------------- | ----- | +| 1 stepper | 58 | +| 3 stepper | 243 | + ### LPC176x step rate benchmark The following configuration sequence is used on the LPC176x: diff --git a/docs/Features.md b/docs/Features.md index 2ba6e23e..2303132c 100644 --- a/docs/Features.md +++ b/docs/Features.md @@ -164,6 +164,7 @@ represent total number of steps per second on the micro-controller. | Arduino Zero (SAMD21) | 686K | 471K | | STM32F042 | 814K | 578K | | Beaglebone PRU | 866K | 708K | +| STM32G0B1 | 1103K | 790K | | "Blue Pill" (STM32F103) | 1180K | 818K | | Arduino Due (SAM3X8E) | 1273K | 981K | | Duet2 Maestro (SAM4S8C) | 1690K | 1385K | From 0db696b0e9f899004a5fde0bc520c93000fc5bb9 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 27 Dec 2021 12:21:33 -0500 Subject: [PATCH 002/211] docs: Fix hybrid_corexy typo in Config_Reference.md Reported by @controlflow. Signed-off-by: Kevin O'Connor --- docs/Config_Reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 784f369a..fbd929b6 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -84,7 +84,7 @@ The printer section controls high level printer settings. [printer] kinematics: # The type of printer in use. This option may be one of: cartesian, -# corexy, corexz, hybrid-corexy, hybrid-corexz, rotary_delta, delta, +# corexy, corexz, hybrid_corexy, hybrid_corexz, rotary_delta, delta, # polar, winch, or none. This # parameter must be specified. max_velocity: From 4d3198d44d76698f1728f48c805a1b8eda2952a7 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Tue, 21 Dec 2021 20:30:33 -0800 Subject: [PATCH 003/211] docs: Clarify the Thickness of Paper Signed-off-by: Yifei Ding --- docs/Bed_Level.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/Bed_Level.md b/docs/Bed_Level.md index 2f02361a..b8da4ba4 100644 --- a/docs/Bed_Level.md +++ b/docs/Bed_Level.md @@ -63,7 +63,7 @@ test". In order to perform the paper test, cut a small rectangular piece of paper using a pair of scissors (eg, 5x3 cm). The paper generally has a -width of around 100 microns (0.100mm). (The exact width of the paper +thickness of around 100 microns (0.100mm). (The exact thickness of the paper isn't crucial.) The first step of the paper test is to inspect the printer's nozzle @@ -74,7 +74,7 @@ or bed. If one always prints on a particular tape or printing surface then one may perform the paper test with that tape/surface in place. However, -note that tape itself has a width and different tapes (or any other +note that tape itself has a thickness and different tapes (or any other printing surface) will impact Z measurements. Be sure to rerun the paper test to measure each type of surface that is in use. @@ -89,11 +89,11 @@ temperature!** When the nozzle is heated, its position (relative to the bed) changes due to thermal expansion. This thermal expansion is typically around a -100 microns, which is about the same width as a typical piece of +100 microns, which is about the same thickness as a typical piece of printer paper. The exact amount of thermal expansion isn't crucial, -just as the exact width of the paper isn't crucial. Start with the +just as the exact thickness of the paper isn't crucial. Start with the assumption that the two are equal (see below for a method of -determining the difference between the two widths). +determining the difference between the two distances). It may seem odd to calibrate the distance at room temperature when the goal is to have a consistent distance when heated. However, if one @@ -180,7 +180,7 @@ command to exit the calibration tool. After successfully performing bed leveling, one may go on to calculate a more precise value for the combined impact of "thermal expansion", -"width of the paper", and "amount of friction felt during the paper +"thickness of the paper", and "amount of friction felt during the paper test". This type of calculation is generally not needed as most users find From aa2ede4a8cd035f21a92e741bc0648bdf88c817c Mon Sep 17 00:00:00 2001 From: BigTreeTech <38851044+bigtreetech@users.noreply.github.com> Date: Tue, 28 Dec 2021 01:28:21 +0800 Subject: [PATCH 004/211] config: Add BigTreeTech SKR Pico V1.0 board (#5022) Signed-off-by: Alan.Ma from BigTreeTech --- config/generic-bigtreetech-skr-pico-v1.0.cfg | 132 +++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 config/generic-bigtreetech-skr-pico-v1.0.cfg diff --git a/config/generic-bigtreetech-skr-pico-v1.0.cfg b/config/generic-bigtreetech-skr-pico-v1.0.cfg new file mode 100644 index 00000000..5130d283 --- /dev/null +++ b/config/generic-bigtreetech-skr-pico-v1.0.cfg @@ -0,0 +1,132 @@ +# This file contains common pin mappings for the BIGTREETECH SKR Pico V1.0 +# To use this config, the firmware should be compiled for the +# RP2040 and USB / UART communication. + +# The "make flash" command does not work on the SKR Pico V1.0. Instead, +# after running "make", copy the generated "out/klipper.uf2" file +# to the mass storage device in RP2040 boot mode + +# See docs/Config_Reference.md for a description of parameters. + +[stepper_x] +step_pin: gpio11 +dir_pin: !gpio10 +enable_pin: !gpio12 +microsteps: 16 +rotation_distance: 40 +endstop_pin: ^gpio4 +position_endstop: 0 +position_max: 235 +homing_speed: 50 + +[tmc2209 stepper_x] +uart_pin: gpio9 +tx_pin: gpio8 +uart_address: 0 +run_current: 0.580 +stealthchop_threshold: 999999 + +[stepper_y] +step_pin: gpio6 +dir_pin: !gpio5 +enable_pin: !gpio7 +microsteps: 16 +rotation_distance: 40 +endstop_pin: ^gpio3 +position_endstop: 0 +position_max: 235 +homing_speed: 50 + +[tmc2209 stepper_y] +uart_pin: gpio9 +tx_pin: gpio8 +uart_address: 2 +run_current: 0.580 +stealthchop_threshold: 999999 + +[stepper_z] +step_pin: gpio19 +dir_pin: gpio28 +enable_pin: !gpio2 +microsteps: 16 +rotation_distance: 8 +endstop_pin: ^gpio25 +position_endstop: 0.0 +position_max: 250 + +[tmc2209 stepper_z] +uart_pin: gpio9 +tx_pin: gpio8 +uart_address: 1 +run_current: 0.580 +stealthchop_threshold: 999999 + +[extruder] +step_pin: gpio14 +dir_pin: !gpio13 +enable_pin: !gpio15 +microsteps: 16 +rotation_distance: 33.500 +nozzle_diameter: 0.400 +filament_diameter: 1.750 +heater_pin: gpio23 +sensor_type: EPCOS 100K B57560G104F +sensor_pin: gpio27 +control: pid +pid_Kp: 21.527 +pid_Ki: 1.063 +pid_Kd: 108.982 +min_temp: 0 +max_temp: 250 + +[tmc2209 extruder] +uart_pin: gpio9 +tx_pin: gpio8 +uart_address: 3 +run_current: 0.650 +stealthchop_threshold: 999999 + +[heater_bed] +heater_pin: gpio21 +sensor_type: ATC Semitec 104GT-2 +sensor_pin: gpio26 +control: pid +pid_Kp: 54.027 +pid_Ki: 0.770 +pid_Kd: 948.182 +min_temp: 0 +max_temp: 130 + +[fan] +pin: gpio17 + +[heater_fan nozzle_cooling_fan] +pin: gpio18 + +[heater_fan controller_fan] +pin: gpio20 + +[mcu] +serial: /dev/serial/by-id/usb-Klipper_Klipper_firmware_12345-if00 + +[printer] +kinematics: cartesian +max_velocity: 300 +max_accel: 3000 +max_z_velocity: 5 +max_z_accel: 100 + +[neopixel board_neopixel] +pin: gpio24 +chain_count: 1 +color_order: GRB +initial_RED: 0.3 +initial_GREEN: 0.3 +initial_BLUE: 0.3 + +#[bltouch] +#sensor_pin: gpio22 +#control_pin: gpio29 + +#[filament_switch_sensor runout_sensor] +#switch_pin: ^gpio16 From 634ae08df6fbd962bd034ac434539c5d02eb5dfa Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 27 Dec 2021 12:32:12 -0500 Subject: [PATCH 005/211] config: Minor updates to generic-bigtreetech-skr-pico-v1.0.cfg Small wording change and add to printer test cases. Signed-off-by: Kevin O'Connor --- config/generic-bigtreetech-skr-pico-v1.0.cfg | 4 ++-- test/klippy/printers.test | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/generic-bigtreetech-skr-pico-v1.0.cfg b/config/generic-bigtreetech-skr-pico-v1.0.cfg index 5130d283..83f89d65 100644 --- a/config/generic-bigtreetech-skr-pico-v1.0.cfg +++ b/config/generic-bigtreetech-skr-pico-v1.0.cfg @@ -1,6 +1,6 @@ # This file contains common pin mappings for the BIGTREETECH SKR Pico V1.0 -# To use this config, the firmware should be compiled for the -# RP2040 and USB / UART communication. +# To use this config, the firmware should be compiled for the RP2040 with +# USB communication. # The "make flash" command does not work on the SKR Pico V1.0. Instead, # after running "make", copy the generated "out/klipper.uf2" file diff --git a/test/klippy/printers.test b/test/klippy/printers.test index 3ac8724f..5d1787d9 100644 --- a/test/klippy/printers.test +++ b/test/klippy/printers.test @@ -194,6 +194,10 @@ CONFIG ../../config/generic-mks-rumba32-v1.0.cfg DICTIONARY stm32g0b1.dict CONFIG ../../config/generic-bigtreetech-skr-mini-e3-v3.0.cfg +# Printers using the rp2040 +DICTIONARY rp2040.dict +CONFIG ../../config/generic-bigtreetech-skr-pico-v1.0.cfg + # Printers using the PRU DICTIONARY pru.dict host=linuxprocess.dict CONFIG ../../config/generic-cramps.cfg From 98af5dffe61476200d1215afbd00b0d809ad0474 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Mon, 27 Dec 2021 09:41:31 -0800 Subject: [PATCH 006/211] docs: Improve filament width sensor documentation (#5058) Add Filament Width Sensor to G-Codes.md Remove Redundant Filament Width Sensor Entries Remove Duplicate Status Reference In Hall Filament Width Sensor Fix Indentation For Filament Width Sensors Signed-off-by: Yifei Ding --- docs/G-Codes.md | 27 ++++++ docs/Hall_Filament_Width_Sensor.md | 118 +++++------------------- docs/Status_Reference.md | 3 +- docs/TSL1401CL_Filament_Width_Sensor.md | 44 +++------ 4 files changed, 68 insertions(+), 124 deletions(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 01e16570..12070f1d 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -841,3 +841,30 @@ Palette prints work by embedding special OCodes (Omega Codes) in the GCode file: - `O1`...`O32`: These codes are read from the GCode stream and processed by this module and passed to the Palette 2 device. + +### Filament Width Sensor Commands + +The following command is available when the +[tsl1401cl filament width sensor config section](Config_Reference.md#tsl1401cl_filament_width_sensor) +or [hall filament width sensor config section](Config_Reference.md#hall_filament_width_sensor) +is enabled (also see [TSLl401CL Filament Width Sensor](TSL1401CL_Filament_Width_Sensor.md) +and [Hall Filament Width Sensor](Hall_Filament_Width_Sensor.md)): + +- `QUERY_FILAMENT_WIDTH` - Return the current measured filament width +- `RESET_FILAMENT_WIDTH_SENSOR` - Clear all sensor readings. Helpful after + filament change +- `DISABLE_FILAMENT_WIDTH_SENSOR` - Turn off the filament width sensor and + stop using it for flow control +- `ENABLE_FILAMENT_WIDTH_SENSOR` - Turn on the filament width sensor and + start using it for flow control + +### Hall Filament Width Sensor Commands + +The following command is available when the +[hall filament width sensor config section](Config_Reference.md#hall_filament_width_sensor) +is enabled: + +- `QUERY_RAW_FILAMENT_WIDTH` - Return the current ADC channel readings and + RAW sensor value for calibration points +- `ENABLE_FILAMENT_WIDTH_LOG` - Turn on diameter logging +- `DISABLE_FILAMENT_WIDTH_LOG` - Turn off diameter logging diff --git a/docs/Hall_Filament_Width_Sensor.md b/docs/Hall_Filament_Width_Sensor.md index 02336e32..2b859a66 100644 --- a/docs/Hall_Filament_Width_Sensor.md +++ b/docs/Hall_Filament_Width_Sensor.md @@ -1,100 +1,26 @@ # Hall filament width sensor -This document describes Filament Width Sensor host module. Hardware used for developing this host module is based on Two Hall liniar sensors (ss49e for example). Sensors in the body are located opposite sides. Principle of operation : two hall sensors work in differential mode, temperature drift same for sensor. Special temperature compensation not needed. You can find designs at [Thingiverse](https://www.thingiverse.com/thing:4138933) +This document describes Filament Width Sensor host module. Hardware used for +developing this host module is based on two Hall linear sensors (ss49e for +example). Sensors in the body are located opposite sides. Principle of operation: +two hall sensors work in differential mode, temperature drift same for sensor. +Special temperature compensation not needed. + +You can find designs at [Thingiverse](https://www.thingiverse.com/thing:4138933), +an assembly video is also available on [Youtube](https://www.youtube.com/watch?v=TDO9tME8vp4) + +To use Hall filament width sensor, read +[Config Reference](Config_Reference.md#hall_filament_width_sensor) and +[G-Code documentation](G-Codes.md#Hall_Filament_Width_Sensor_Commands). -[Hall based filament width sensor assembly video](https://www.youtube.com/watch?v=TDO9tME8vp4) ## How does it work? -Sensor generates two analog output based on calculated filament width. Sum of output voltage always equals to detected filament width . Host module monitors voltage changes and adjusts extrusion multiplier. I use aux2 connector on ramps-like board analog11 and analog12 pins. You can use different pins and differenr boards - -## Configuration - -``` -[hall_filament_width_sensor] - -adc1: analog11 -adc2: analog12 -# adc1 and adc2 channels select own pins Analog input pins on 3d printer board -# Sensor power supply can be 3.3v or 5v - -Cal_dia1: 1.50 # Reference diameter point 1 (mm) -Cal_dia2: 2.00 # Reference diameter point 2 (mm) - -# The measurement principle provides for two-point calibration -# In calibration process you must use rods of known diameter -# I use drill rods as the base diameter. -# nominal filament diameter must be between Cal_dia1 and Cal_dia2 -# Your size may differ from the indicated ones, for example 2.05 - -Raw_dia1:10630 # Raw sensor value for reference point 1 -Raw_dia2:8300 # Raw sensor value for reference point 2 - -# Raw value of sensor in units -# can be readed by command QUERY_RAW_FILAMENT_WIDTH - -default_nominal_filament_diameter: 1.75 # This parameter is in millimeters (mm) - -max_difference: 0.15 -# Maximum allowed filament diameter difference in millimeters (mm) -# If difference between nominal filament diameter and sensor output is more -# than +- max_difference, extrusion multiplier set back to %100 - -measurement_delay: 70 -# The distance from sensor to the melting chamber/hot-end in millimeters (mm). -# The filament between the sensor and the hot-end will be treated as the default_nominal_filament_diameter. -# Host module works with FIFO logic. It keeps each sensor value and position in -# an array and POP them back in correct position. - -#enable:False -# Sensor enabled or disabled after power on. Disabled by default - -# measurement_interval:10 -# Sensor readings done with 10 mm intervals by default. If necessary you are free to change this setting - -#logging: False -# Out diameter to terminal and klipper.log -# can be turn on|of by command - -#Virtual filament_switch_sensor suppurt. Create sensor named hall_filament_width_sensor. -# -#min_diameter:1.0 -#Minimal diameter for trigger virtual filament_switch_sensor. -#use_current_dia_while_delay: False -# Use the current diameter instead of the nominal diamenter while the measurement delay has not run through. -# -#Values from filament_switch_sensor. See the "filament_switch_sensor" section for information on these parameters. -# -#pause_on_runout: True -#runout_gcode: -#insert_gcode: -#event_delay: 3.0 -#pause_delay: 0.5 -``` - -## G-Code Commands - -**QUERY_FILAMENT_WIDTH** - Return the current measured filament width as result - -**RESET_FILAMENT_WIDTH_SENSOR** - Clear all sensor readings. Can be used after filament change. - -**DISABLE_FILAMENT_WIDTH_SENSOR** - Turn off the filament width sensor and stop using it to do flow control - -**ENABLE_FILAMENT_WIDTH_SENSOR** - Turn on the filament width sensor and start using it to do flow control - -**QUERY_RAW_FILAMENT_WIDTH** Return the current ADC channel values and RAW sensor value for calibration points - -**ENABLE_FILAMENT_WIDTH_LOG** - Turn on diameter logging - -**DISABLE_FILAMENT_WIDTH_LOG** - Turn off diameter logging - -## Menu variables - -**hall_filament_width_sensor.Diameter** current measured filament width in mm - -**hall_filament_width_sensor.Raw** current raw measured filament width in units - -**hall_filament_width_sensor.is_active** Sensor on or off +Sensor generates two analog output based on calculated filament width. Sum of +output voltage always equals to detected filament width. Host module monitors +voltage changes and adjusts extrusion multiplier. I use aux2 connector on +ramps-like board analog11 and analog12 pins. You can use different pins and +differenr boards. ## Template for menu variables @@ -114,7 +40,8 @@ index: 1 ## Calibration procedure -To get raw sensor value you can use menu item or **QUERY_RAW_FILAMENT_WIDTH** command in terminal +To get raw sensor value you can use menu item or **QUERY_RAW_FILAMENT_WIDTH** +command in terminal. 1. Insert first calibration rod (1.5 mm size) get first raw sensor value @@ -126,12 +53,15 @@ To get raw sensor value you can use menu item or **QUERY_RAW_FILAMENT_WIDTH** co By default, the sensor is disabled at power-on. -To enable the sensor, issue **ENABLE_FILAMENT_WIDTH_SENSOR** command or set the `enable` parameter to `true.` +To enable the sensor, issue **ENABLE_FILAMENT_WIDTH_SENSOR** command or +set the `enable` parameter to `true.` ## Logging By default, diameter logging is disabled at power-on. -Issue **ENABLE_FILAMENT_WIDTH_LOG** command to start logging and issue **DISABLE_FILAMENT_WIDTH_LOG** command to stop logging. To enable logging at power-on, set the `logging` parameter to `true`. +Issue **ENABLE_FILAMENT_WIDTH_LOG** command to start logging and issue +**DISABLE_FILAMENT_WIDTH_LOG** command to stop logging. To enable logging +at power-on, set the `logging` parameter to `true`. Filament diameter is logged on every measurement interval (10 mm by default). diff --git a/docs/Status_Reference.md b/docs/Status_Reference.md index 1d726f13..4fed169b 100644 --- a/docs/Status_Reference.md +++ b/docs/Status_Reference.md @@ -138,7 +138,8 @@ The following information is available in the [hall_filament_width_sensor](Config_Reference.md#hall_filament_width_sensor) object: - `is_active`: Returns True if the sensor is currently active. -- `Diameter`, `Raw`: The last read values from the sensor. +- `Diameter`: The last reading from the sensor in mm. +- `Raw`: The last raw ADC reading from the sensor. ## heater diff --git a/docs/TSL1401CL_Filament_Width_Sensor.md b/docs/TSL1401CL_Filament_Width_Sensor.md index b9cc0b73..a0dccb92 100644 --- a/docs/TSL1401CL_Filament_Width_Sensor.md +++ b/docs/TSL1401CL_Filament_Width_Sensor.md @@ -1,36 +1,22 @@ # TSL1401CL filament width sensor -This document describes Filament Width Sensor host module. Hardware used for developing this host module is based on TSL1401CL linear sensor array but it can work with any sensor array that has analog output. You can find designs at [thingiverse.com](https://www.thingiverse.com/search?q=filament%20width%20sensor) +This document describes Filament Width Sensor host module. Hardware used +for developing this host module is based on TSL1401CL linear sensor array +but it can work with any sensor array that has analog output. You can find +designs at [Thingiverse](https://www.thingiverse.com/search?q=filament%20width%20sensor). + +To use a sensor array as a filament width sensor, read +[Config Reference](Config_Reference.md#tsl1401cl_filament_width_sensor) and +[G-Code documentation](G-Codes.md#Filament_Width_Sensor_Commands). ## How does it work? -Sensor generates analog output based on calculated filament width. Output voltage always equals to detected filament width (Ex. 1.65v, 1.70v, 3.0v). Host module monitors voltage changes and adjusts extrusion multiplier. +Sensor generates analog output based on calculated filament width. Output +voltage always equals to detected filament width (Ex. 1.65v, 1.70v, 3.0v). +Host module monitors voltage changes and adjusts extrusion multiplier. -## Configuration +## Note: - [tsl1401cl_filament_width_sensor] - pin: analog5 - # Analog input pin for sensor output on Ramps board - - default_nominal_filament_diameter: 1.75 - # This parameter is in millimeters (mm) - - max_difference: 0.2 - # Maximum allowed filament diameter difference in millimeters (mm) - # If difference between nominal filament diameter and sensor output is more - # than +- max_difference, extrusion multiplier set back to %100 - - measurement_delay 100 - # The distance from sensor to the melting chamber/hot-end in millimeters (mm). - # The filament between the sensor and the hot-end will be treated as the default_nominal_filament_diameter. - # Host module works with FIFO logic. It keeps each sensor value and position in - # an array and POP them back in correct position. - -Sensor readings done with 10 mm intervals by default. If necessary you are free to change this setting by editing ***MEASUREMENT_INTERVAL_MM*** parameter in **filament_width_sensor.py** file. - -## Commands - -**QUERY_FILAMENT_WIDTH** - Return the current measured filament width as result -**RESET_FILAMENT_WIDTH_SENSOR** – Clear all sensor readings. Can be used after filament change. -**DISABLE_FILAMENT_WIDTH_SENSOR** – Turn off the filament width sensor and stop using it to do flow control -**ENABLE_FILAMENT_WIDTH_SENSOR** - Turn on the filament width sensor and start using it to do flow control +Sensor readings done with 10 mm intervals by default. If necessary you are +free to change this setting by editing ***MEASUREMENT_INTERVAL_MM*** parameter +in **filament_width_sensor.py** file. From 9bdd61758e61d4652ae09515425c3316c6cfe905 Mon Sep 17 00:00:00 2001 From: adelyser <12093019+adelyser@users.noreply.github.com> Date: Wed, 29 Dec 2021 16:01:28 -0700 Subject: [PATCH 007/211] stm32: Fix the GPIO register for stm32h7 (#5077) Signed-off-by: Aaron DeLyser --- src/stm32/stm32h7.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stm32/stm32h7.c b/src/stm32/stm32h7.c index 4edab5f0..0e4094c1 100644 --- a/src/stm32/stm32h7.c +++ b/src/stm32/stm32h7.c @@ -100,9 +100,9 @@ get_pclock_frequency(uint32_t periph_base) void gpio_clock_enable(GPIO_TypeDef *regs) { - uint32_t pos = ((uint32_t)regs - D3_APB1PERIPH_BASE) / 0x400; - RCC->APB4ENR |= (1<APB4ENR; + uint32_t pos = ((uint32_t)regs - D3_AHB1PERIPH_BASE) / 0x400; + RCC->AHB4ENR |= (1<AHB4ENR; } #if !CONFIG_STM32_CLOCK_REF_INTERNAL From 8b6753d68f681b0ed7e76b5e05b2bc7da6d5aa1d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 24 Dec 2021 12:23:56 -0500 Subject: [PATCH 008/211] stm32: Unify enable_pclock() code Unify the handling of the enable_pclock() and is_enabled_pclock() code across all stm32 chips. All chips will now perform a peripheral reset on enable_pclock() (this is a change for stm32f0 and stm32h7). The enable_pclock() code will now also disable irqs during the enable. Signed-off-by: Kevin O'Connor --- src/stm32/Makefile | 2 +- src/stm32/clockline.c | 32 +++++++++++++++ src/stm32/internal.h | 18 +++++--- src/stm32/stm32f0.c | 49 +++++++--------------- src/stm32/stm32f1.c | 45 +++++--------------- src/stm32/stm32f4.c | 54 +++++++----------------- src/stm32/stm32g0.c | 76 ++++++++-------------------------- src/stm32/stm32h7.c | 95 ++++++++++++------------------------------- 8 files changed, 129 insertions(+), 242 deletions(-) create mode 100644 src/stm32/clockline.c diff --git a/src/stm32/Makefile b/src/stm32/Makefile index 5f2ad8ec..793630a9 100644 --- a/src/stm32/Makefile +++ b/src/stm32/Makefile @@ -27,7 +27,7 @@ CFLAGS_klipper.elf += -T $(OUT)src/generic/armcm_link.ld $(OUT)klipper.elf: $(OUT)src/generic/armcm_link.ld # Add source files -src-y += stm32/watchdog.c stm32/gpio.c generic/crc16_ccitt.c +src-y += stm32/watchdog.c stm32/gpio.c stm32/clockline.c generic/crc16_ccitt.c src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c src-$(CONFIG_MACH_STM32F0) += ../lib/stm32f0/system_stm32f0xx.c src-$(CONFIG_MACH_STM32F0) += generic/timer_irq.c stm32/stm32f0_timer.c diff --git a/src/stm32/clockline.c b/src/stm32/clockline.c new file mode 100644 index 00000000..970ce9da --- /dev/null +++ b/src/stm32/clockline.c @@ -0,0 +1,32 @@ +// Code to enable clock lines on stm32 +// +// Copyright (C) 2021 Kevin O'Connor +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include "board/irq.h" // irq_save +#include "internal.h" // struct cline + +// Enable a peripheral clock +void +enable_pclock(uint32_t periph_base) +{ + struct cline cl = lookup_clock_line(periph_base); + irqstatus_t flag = irq_save(); + *cl.en |= cl.bit; + *cl.en; // Pause 2 cycles to ensure peripheral is enabled + if (cl.rst) { + // Reset peripheral + *cl.rst = cl.bit; + *cl.rst = 0; + } + irq_restore(flag); +} + +// Check if a peripheral clock has been enabled +int +is_enabled_pclock(uint32_t periph_base) +{ + struct cline cl = lookup_clock_line(periph_base); + return *cl.en & cl.bit; +} diff --git a/src/stm32/internal.h b/src/stm32/internal.h index 6101e0f2..f0535ab9 100644 --- a/src/stm32/internal.h +++ b/src/stm32/internal.h @@ -18,22 +18,28 @@ #include "stm32h7xx.h" #endif +// gpio.c extern GPIO_TypeDef * const digital_regs[]; - #define GPIO(PORT, NUM) (((PORT)-'A') * 16 + (NUM)) #define GPIO2PORT(PIN) ((PIN) / 16) #define GPIO2BIT(PIN) (1<<((PIN) % 16)) +// gpioperiph.c #define GPIO_INPUT 0 #define GPIO_OUTPUT 1 #define GPIO_OPEN_DRAIN 0x100 #define GPIO_FUNCTION(fn) (2 | ((fn) << 4)) #define GPIO_ANALOG 3 - -void enable_pclock(uint32_t periph_base); -int is_enabled_pclock(uint32_t periph_base); -uint32_t get_pclock_frequency(uint32_t periph_base); -void gpio_clock_enable(GPIO_TypeDef *regs); void gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup); +// clockline.c +void enable_pclock(uint32_t periph_base); +int is_enabled_pclock(uint32_t periph_base); + +// stm32??.c +struct cline { volatile uint32_t *en, *rst; uint32_t bit; }; +struct cline lookup_clock_line(uint32_t periph_base); +uint32_t get_pclock_frequency(uint32_t periph_base); +void gpio_clock_enable(GPIO_TypeDef *regs); + #endif // internal.h diff --git a/src/stm32/stm32f0.c b/src/stm32/stm32f0.c index 9fd84bc4..6b13d737 100644 --- a/src/stm32/stm32f0.c +++ b/src/stm32/stm32f0.c @@ -18,38 +18,19 @@ #define FREQ_PERIPH 48000000 -// Enable a peripheral clock -void -enable_pclock(uint32_t periph_base) +// Map a peripheral address to its enable bits +struct cline +lookup_clock_line(uint32_t periph_base) { - if (periph_base < SYSCFG_BASE) { - uint32_t pos = (periph_base - APBPERIPH_BASE) / 0x400; - RCC->APB1ENR |= 1 << pos; - RCC->APB1ENR; - } else if (periph_base < AHBPERIPH_BASE) { - uint32_t pos = (periph_base - SYSCFG_BASE) / 0x400; - RCC->APB2ENR |= 1 << pos; - RCC->APB2ENR; + if (periph_base >= AHB2PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - AHB2PERIPH_BASE) / 0x400 + 17); + return (struct cline){.en=&RCC->AHBENR, .rst=&RCC->AHBRSTR, .bit=bit}; + } else if (periph_base >= SYSCFG_BASE) { + uint32_t bit = 1 << ((periph_base - SYSCFG_BASE) / 0x400); + return (struct cline){.en=&RCC->APB2ENR, .rst=&RCC->APB2RSTR, .bit=bit}; } else { - uint32_t pos = (periph_base - AHB2PERIPH_BASE) / 0x400; - RCC->AHBENR |= 1 << (pos + 17); - RCC->AHBENR; - } -} - -// Check if a peripheral clock has been enabled -int -is_enabled_pclock(uint32_t periph_base) -{ - if (periph_base < SYSCFG_BASE) { - uint32_t pos = (periph_base - APBPERIPH_BASE) / 0x400; - return RCC->APB1ENR & (1 << pos); - } else if (periph_base < AHBPERIPH_BASE) { - uint32_t pos = (periph_base - SYSCFG_BASE) / 0x400; - return RCC->APB2ENR & (1 << pos); - } else { - uint32_t pos = (periph_base - AHB2PERIPH_BASE) / 0x400; - return RCC->AHBENR & (1 << (pos + 17)); + uint32_t bit = 1 << ((periph_base - APBPERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->APB1ENR, .rst=&RCC->APB1RSTR, .bit=bit}; } } @@ -202,7 +183,6 @@ enable_ram_vectortable(void) __builtin_memcpy(&_ram_vectortable_start, &_text_vectortable_start, count); barrier(); - enable_pclock(SYSCFG_BASE); SYSCFG->CFGR1 |= 3 << SYSCFG_CFGR1_MEM_MODE_Pos; } @@ -212,6 +192,8 @@ armcm_main(void) { check_usb_dfu_bootloader(); SystemInit(); + + enable_pclock(SYSCFG_BASE); if (CONFIG_ARMCM_RAM_VECTORTABLE) enable_ram_vectortable(); @@ -230,11 +212,8 @@ armcm_main(void) // Support pin remapping USB/CAN pins on low pinout stm32f042 #ifdef SYSCFG_CFGR1_PA11_PA12_RMP - if (CONFIG_STM32_USB_PA11_PA12_REMAP - || CONFIG_STM32_CANBUS_PA11_PA12_REMAP) { - enable_pclock(SYSCFG_BASE); + if (CONFIG_STM32_USB_PA11_PA12_REMAP || CONFIG_STM32_CANBUS_PA11_PA12_REMAP) SYSCFG->CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP; - } #endif sched_main(); diff --git a/src/stm32/stm32f1.c b/src/stm32/stm32f1.c index 9508a291..5680cfba 100644 --- a/src/stm32/stm32f1.c +++ b/src/stm32/stm32f1.c @@ -18,42 +18,19 @@ #define FREQ_PERIPH (CONFIG_CLOCK_FREQ / 2) -// Enable a peripheral clock -void -enable_pclock(uint32_t periph_base) +// Map a peripheral address to its enable bits +struct cline +lookup_clock_line(uint32_t periph_base) { - if (periph_base < APB2PERIPH_BASE) { - uint32_t pos = (periph_base - APB1PERIPH_BASE) / 0x400; - RCC->APB1ENR |= (1<APB1ENR; - RCC->APB1RSTR |= (1<APB1RSTR &= ~(1<APB2ENR |= (1<APB2ENR; - RCC->APB2RSTR |= (1<APB2RSTR &= ~(1<= AHBPERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - AHBPERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->AHBENR, .bit=bit}; + } else if (periph_base >= APB2PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - APB2PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->APB2ENR, .rst=&RCC->APB2RSTR, .bit=bit}; } else { - uint32_t pos = (periph_base - AHBPERIPH_BASE) / 0x400; - RCC->AHBENR |= (1<AHBENR; - } -} - -// Check if a peripheral clock has been enabled -int -is_enabled_pclock(uint32_t periph_base) -{ - if (periph_base < APB2PERIPH_BASE) { - uint32_t pos = (periph_base - APB1PERIPH_BASE) / 0x400; - return RCC->APB1ENR & (1<APB2ENR & (1<AHBENR & (1<APB1ENR, .rst=&RCC->APB1RSTR, .bit=bit}; } } diff --git a/src/stm32/stm32f4.c b/src/stm32/stm32f4.c index a8320238..149cd171 100644 --- a/src/stm32/stm32f4.c +++ b/src/stm32/stm32f4.c @@ -21,49 +21,25 @@ #define FREQ_PERIPH (CONFIG_CLOCK_FREQ / FREQ_PERIPH_DIV) #define FREQ_USB 48000000 -// Enable a peripheral clock -void -enable_pclock(uint32_t periph_base) +// Map a peripheral address to its enable bits +struct cline +lookup_clock_line(uint32_t periph_base) { - if (periph_base < APB2PERIPH_BASE) { - uint32_t pos = (periph_base - APB1PERIPH_BASE) / 0x400; - RCC->APB1ENR |= (1<APB1ENR; - RCC->APB1RSTR |= (1<APB1RSTR &= ~(1<APB2ENR |= (1<APB2ENR; - // Skip ADC peripheral reset as they share a bit - if (pos < 8 || pos > 10) { - RCC->APB2RSTR |= (1<APB2RSTR &= ~(1<AHB1ENR |= (1<AHB1ENR; + if (periph_base >= AHB1PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - AHB1PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->AHB1ENR, .rst=&RCC->AHB1RSTR, .bit=bit}; + } else if (periph_base >= APB2PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - APB2PERIPH_BASE) / 0x400); + if (bit & 0x700) + // Skip ADC peripheral reset as they share a bit + return (struct cline){.en=&RCC->APB2ENR, .bit=bit}; + return (struct cline){.en=&RCC->APB2ENR, .rst=&RCC->APB2RSTR, .bit=bit}; + } else { + uint32_t bit = 1 << ((periph_base - APB1PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->APB1ENR, .rst=&RCC->APB1RSTR, .bit=bit}; } } -// Check if a peripheral clock has been enabled -int -is_enabled_pclock(uint32_t periph_base) -{ - if (periph_base < APB2PERIPH_BASE) { - uint32_t pos = (periph_base - APB1PERIPH_BASE) / 0x400; - return RCC->APB1ENR & (1<APB2ENR & (1<AHB1ENR & (1<= IOPORT_BASE) { + uint32_t bit = 1 << ((periph_base - IOPORT_BASE) / 0x400); + return (struct cline){.en=&RCC->IOPENR, .rst=&RCC->IOPRSTR, .bit=bit}; + } else if (periph_base >= AHBPERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - AHBPERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->AHBENR, .rst=&RCC->AHBRSTR, .bit=bit}; + } if (periph_base == USB_BASE) - return 13; + return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<13}; if (periph_base == CRS_BASE) - return 16; + return (struct cline){.en=&RCC->APBENR1,.rst=&RCC->APBRSTR1,.bit=1<<16}; if (periph_base == SPI1_BASE) - return 32 + 12; + return (struct cline){.en=&RCC->APBENR2,.rst=&RCC->APBRSTR2,.bit=1<<12}; if (periph_base == USART1_BASE) - return 32 + 14; + return (struct cline){.en=&RCC->APBENR2,.rst=&RCC->APBRSTR2,.bit=1<<14}; if (periph_base == ADC1_BASE) - return 32 + 20; - return (periph_base - APBPERIPH_BASE) / 0x400; -} - -// Enable a peripheral clock -void -enable_pclock(uint32_t periph_base) -{ - if (periph_base >= IOPORT_BASE) { - uint32_t pos = (periph_base - IOPORT_BASE) / 0x400; - RCC->IOPENR |= 1 << pos; - RCC->IOPENR; - RCC->IOPRSTR |= (1<IOPRSTR &= ~(1<= AHBPERIPH_BASE) { - uint32_t pos = (periph_base - AHBPERIPH_BASE) / 0x400; - RCC->AHBENR |= 1 << pos; - RCC->AHBENR; - RCC->AHBRSTR |= (1<AHBRSTR &= ~(1<APBENR1 |= 1 << pos; - RCC->APBENR1; - RCC->APBRSTR1 |= (1 << pos); - RCC->APBRSTR1 &= ~(1 << pos); - } else { - RCC->APBENR2 |= 1 << (pos - 32); - RCC->APBENR2; - RCC->APBRSTR2 |= (1 << (pos - 32)); - RCC->APBRSTR2 &= ~(1 << (pos - 32)); - } - } -} - -// Check if a peripheral clock has been enabled -int -is_enabled_pclock(uint32_t periph_base) -{ - if (periph_base >= IOPORT_BASE) { - uint32_t pos = (periph_base - IOPORT_BASE) / 0x400; - return RCC->IOPENR & (1 << pos); - } else if (periph_base >= AHBPERIPH_BASE) { - uint32_t pos = (periph_base - AHBPERIPH_BASE) / 0x400; - return RCC->AHBENR & (1 << pos); - } else { - uint32_t pos = lookup_apb_bit(periph_base); - if (pos < 32) - return RCC->APBENR1 & (1 << pos); - return RCC->APBENR2 & (1 << (pos - 32)); - } + return (struct cline){.en=&RCC->APBENR2,.rst=&RCC->APBRSTR2,.bit=1<<20}; + uint32_t bit = 1 << ((periph_base - APBPERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->APBENR1, .rst=&RCC->APBRSTR1, .bit=bit}; } // Return the frequency of the given peripheral clock diff --git a/src/stm32/stm32h7.c b/src/stm32/stm32h7.c index 0e4094c1..ebb71cfb 100644 --- a/src/stm32/stm32h7.c +++ b/src/stm32/stm32h7.c @@ -7,7 +7,7 @@ #include "autoconf.h" // CONFIG_CLOCK_REF_FREQ #include "board/armcm_boot.h" // VectorTable #include "command.h" // DECL_CONSTANT_STR -#include "internal.h" // enable_pclock +#include "internal.h" // get_pclock_frequency #include "sched.h" // sched_main @@ -17,75 +17,34 @@ #define FREQ_PERIPH (CONFIG_CLOCK_FREQ / 4) -// Enable a peripheral clock -void -enable_pclock(uint32_t periph_base) +// Map a peripheral address to its enable bits +struct cline +lookup_clock_line(uint32_t periph_base) { - // periph_base determines in which bitfield at wich position to set a bit - // E.g. D2_AHB1PERIPH_BASE is the adress offset of the given bitfield - if (periph_base < D2_APB2PERIPH_BASE) { - uint32_t pos = (periph_base - D2_APB1PERIPH_BASE) / 0x400; - RCC->APB1LENR |= (1<APB1LENR; - } else if (periph_base < D2_AHB1PERIPH_BASE) { - uint32_t pos = (periph_base - D2_APB2PERIPH_BASE) / 0x400; - RCC->APB2ENR |= (1<APB2ENR; - } else if (periph_base < D2_AHB2PERIPH_BASE) { - uint32_t pos = (periph_base - D2_AHB1PERIPH_BASE) / 0x400; - RCC->AHB1ENR |= (1<AHB1ENR; - } else if (periph_base < D1_APB1PERIPH_BASE) { - uint32_t pos = (periph_base - D2_AHB2PERIPH_BASE) / 0x400; - RCC->AHB2ENR |= (1<AHB2ENR; - } else if (periph_base < D1_AHB1PERIPH_BASE) { - uint32_t pos = (periph_base - D1_APB1PERIPH_BASE) / 0x400; - RCC->APB3ENR |= (1<APB3ENR; - } else if (periph_base < D3_APB1PERIPH_BASE) { - uint32_t pos = (periph_base - D1_AHB1PERIPH_BASE) / 0x400; - RCC->AHB3ENR |= (1<AHB3ENR; - } else if (periph_base < D3_AHB1PERIPH_BASE) { - uint32_t pos = (periph_base - D3_APB1PERIPH_BASE) / 0x400; - RCC->APB4ENR |= (1<APB4ENR; + if (periph_base >= D3_AHB1PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - D3_AHB1PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->AHB4ENR, .rst=&RCC->AHB4RSTR, .bit=bit}; + } else if (periph_base >= D3_APB1PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - D3_APB1PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->APB4ENR, .rst=&RCC->APB4RSTR, .bit=bit}; + } else if (periph_base >= D1_AHB1PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - D1_AHB1PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->AHB3ENR, .rst=&RCC->AHB3RSTR, .bit=bit}; + } else if (periph_base >= D1_APB1PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - D1_APB1PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->APB3ENR, .rst=&RCC->APB3RSTR, .bit=bit}; + } else if (periph_base >= D2_AHB2PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - D2_AHB2PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->AHB2ENR, .rst=&RCC->AHB2RSTR, .bit=bit}; + } else if (periph_base >= D2_AHB1PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - D2_AHB1PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->AHB1ENR, .rst=&RCC->AHB1RSTR, .bit=bit}; + } else if (periph_base >= D2_APB2PERIPH_BASE) { + uint32_t bit = 1 << ((periph_base - D2_APB2PERIPH_BASE) / 0x400); + return (struct cline){.en=&RCC->APB2ENR, .rst=&RCC->APB2RSTR, .bit=bit}; } else { - uint32_t pos = (periph_base - D3_AHB1PERIPH_BASE) / 0x400; - RCC->AHB4ENR |= (1<AHB4ENR; - } -} - -// Check if a peripheral clock has been enabled -int -is_enabled_pclock(uint32_t periph_base) -{ - if (periph_base < D2_APB2PERIPH_BASE) { - uint32_t pos = (periph_base - D2_APB1PERIPH_BASE) / 0x400; - return RCC->APB1LENR & (1<APB2ENR & (1<AHB1ENR & (1<AHB2ENR & (1<APB3ENR & (1<AHB3ENR & (1<APB4ENR & (1<AHB4ENR & (1<APB1LENR,.rst=&RCC->APB1LRSTR,.bit=bit}; } } From 309b8e030f68329d04573042ffc53a2745ac088b Mon Sep 17 00:00:00 2001 From: Dmitry Butyugin Date: Wed, 8 Dec 2021 21:44:07 +0100 Subject: [PATCH 009/211] scripts: Migrated shaper calibration scripts to Python3 Also updated instructions to install python3-numpy and python3-matplotlib Python packages. Signed-off-by: Dmitry Butyugin --- docs/Config_Changes.md | 10 ++++++++++ docs/Measuring_Resonances.md | 2 +- scripts/calibrate_shaper.py | 2 +- scripts/graph_accelerometer.py | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md index 11447d4d..e9bcd120 100644 --- a/docs/Config_Changes.md +++ b/docs/Config_Changes.md @@ -8,6 +8,16 @@ All dates in this document are approximate. ## Changes +20211230: Scripts to tune input shaper (`scripts/calibrate_shaper.py` +and `scripts/graph_accelerometer.py`) were migrated to use Python3 +by default. As a result, users must install Python3 versions of certain +packages (e.g. `sudo apt install python3-numpy python3-matplotlib`) to +continue using these scripts. For more details, refer to +[Software installation](Measuring_Resonances.md#software-installation). +Alternatively, users can temporarily force the execution of these scripts +under Python 2 by explicitly calling Python2 interpretor in the console: +`python2 ~/klipper/scripts/calibrate_shaper.py ...` + 20211110: The "NTC 100K beta 3950" temperature sensor is deprecated. This sensor will be removed in the near future. Most users will find the "Generic 3950" temperature sensor more accurate. To continue to diff --git a/docs/Measuring_Resonances.md b/docs/Measuring_Resonances.md index e940713a..32a7413d 100644 --- a/docs/Measuring_Resonances.md +++ b/docs/Measuring_Resonances.md @@ -77,7 +77,7 @@ too little RAM, the installation may fail and you will need to enable swap. Next, run the following commands to install the additional dependencies: ``` sudo apt update -sudo apt install python-numpy python-matplotlib +sudo apt install python3-numpy python3-matplotlib ``` Afterwards, check and follow the instructions in the diff --git a/scripts/calibrate_shaper.py b/scripts/calibrate_shaper.py index 3d4bceff..8a0fcdf0 100755 --- a/scripts/calibrate_shaper.py +++ b/scripts/calibrate_shaper.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # Shaper auto-calibration script # # Copyright (C) 2020 Dmitry Butyugin diff --git a/scripts/graph_accelerometer.py b/scripts/graph_accelerometer.py index 990bd23b..8c09e847 100755 --- a/scripts/graph_accelerometer.py +++ b/scripts/graph_accelerometer.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # Generate adxl345 accelerometer graphs # # Copyright (C) 2020 Kevin O'Connor From f8afe49a2f93b25527ed6515d32f4f34490f5bd2 Mon Sep 17 00:00:00 2001 From: Stephen Hurd Date: Thu, 30 Dec 2021 18:56:24 -0500 Subject: [PATCH 010/211] toolhead: Fix toolhead stop on SET_VELOCITY_LIMIT (#5053) This fixes issue #5050 Signed-off-by: Stephen Hurd --- klippy/toolhead.py | 1 - 1 file changed, 1 deletion(-) diff --git a/klippy/toolhead.py b/klippy/toolhead.py index db2d47f4..b7285420 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -552,7 +552,6 @@ class ToolHead: self.wait_moves() cmd_SET_VELOCITY_LIMIT_help = "Set printer velocity limits" def cmd_SET_VELOCITY_LIMIT(self, gcmd): - print_time = self.get_last_move_time() max_velocity = gcmd.get_float('VELOCITY', None, above=0.) max_accel = gcmd.get_float('ACCEL', None, above=0.) square_corner_velocity = gcmd.get_float( From 7e4dff3b3792513d1fe6f4051016f92dbcb515bc Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 31 Dec 2021 11:03:53 -0500 Subject: [PATCH 011/211] docs: Remove mkdocs-section-index from mkdocs-requirements.txt Commit bd0185cf removed the section-index plugin. Remove it from the build requirements as well. Signed-off-by: Kevin O'Connor --- docs/_klipper3d/mkdocs-requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/_klipper3d/mkdocs-requirements.txt b/docs/_klipper3d/mkdocs-requirements.txt index 6fb832c3..e85a21a4 100644 --- a/docs/_klipper3d/mkdocs-requirements.txt +++ b/docs/_klipper3d/mkdocs-requirements.txt @@ -1,7 +1,6 @@ # Python virtualenv module requirements for mkdocs mkdocs==1.2.3 mkdocs-material==7.2.0 -mkdocs-section-index==0.3.1 mkdocs-simple-hooks==0.1.3 mkdocs-exclude==1.0.2 mdx-truly-sane-lists==1.2 From 608cd38de5603792804a49625c43f3f5d3dacb5e Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 31 Dec 2021 11:21:08 -0500 Subject: [PATCH 012/211] docs: Upgrade to mkdocs-material v8.1.3 This version seems to fix an error in text highlighting during search. Signed-off-by: Kevin O'Connor --- docs/_klipper3d/mkdocs-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_klipper3d/mkdocs-requirements.txt b/docs/_klipper3d/mkdocs-requirements.txt index e85a21a4..a7fcf1e9 100644 --- a/docs/_klipper3d/mkdocs-requirements.txt +++ b/docs/_klipper3d/mkdocs-requirements.txt @@ -1,6 +1,6 @@ # Python virtualenv module requirements for mkdocs mkdocs==1.2.3 -mkdocs-material==7.2.0 +mkdocs-material==8.1.3 mkdocs-simple-hooks==0.1.3 mkdocs-exclude==1.0.2 mdx-truly-sane-lists==1.2 From 8a3727ef742f46923275ffca4651710952cfa114 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 30 Dec 2021 17:48:33 -0500 Subject: [PATCH 013/211] docs: Note some BL-Touch clones do not support touch_mode in BLTouch.md Signed-off-by: Kevin O'Connor --- docs/BLTouch.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/BLTouch.md b/docs/BLTouch.md index e7b2f9b5..4445a6a5 100644 --- a/docs/BLTouch.md +++ b/docs/BLTouch.md @@ -64,9 +64,10 @@ run `BLTOUCH_DEBUG COMMAND=touch_mode`, run `QUERY_PROBE`, and verify that command reports "probe: open". Then while gently pushing the pin up slightly with the nail of your finger run `QUERY_PROBE` again. Verify the command reports "probe: TRIGGERED". If either query does -not report the correct message then check your wiring and -configuration again. At the completion of this test run `BLTOUCH_DEBUG -COMMAND=pin_up` and verify that the pin moves up. +not report the correct message then it usually indicates an incorrect +wiring or configuration (though some [clones](#bl-touch-clones) may +require special handling). At the completion of this test run +`BLTOUCH_DEBUG COMMAND=pin_up` and verify that the pin moves up. After completing the BL-Touch control pin and sensor pin tests, it is now time to test probing, but with a twist. Instead of letting the @@ -106,7 +107,8 @@ commands to achieve this. ## BL-Touch "clones" Many BL-Touch "clone" devices work correctly with Klipper using the -default configuration. However, some "clone" devices may require +default configuration. However, some "clone" devices may not support +the `QUERY_PROBE` command and some "clone" devices may require configuration of `pin_up_reports_not_triggered` or `pin_up_touch_mode_reports_triggered`. @@ -116,6 +118,16 @@ these directions. Do not configure either of these to False on a genuine BL-Touch. Incorrectly setting these to False can increase probing time and can increase the risk of damaging the printer. +Some "clone" devices do not support `touch_mode` and as a result the +`QUERY_PROBE` command does not work. Despite this, it may still be +possible to perform probing and homing with these devices. On these +devices the `QUERY_PROBE` command during the +[initial tests](#initial-tests) will not succeed, however the +subsequent `G28` (or `PROBE`) test does succeed. It may be possible to +use these "clone" devices with Klipper if one does not utilize the +`QUERY_PROBE` command and one does not enable the +`probe_with_touch_mode` feature. + Some "clone" devices are unable to perform Klipper's internal sensor verification test. On these devices, attempts to home or probe can result in Klipper reporting a "BLTouch failed to verify sensor state" From 7c0559c6e62506af73d0e8f22733615705664dd5 Mon Sep 17 00:00:00 2001 From: Lasse Dalegaard Date: Mon, 3 Jan 2022 23:28:54 +0100 Subject: [PATCH 014/211] rp2040: add make flash support This adds `make flash` support for the rp2040 target. Flashing is performed using a custom `rp2040_flash` tool that uses the PICOBOOT protocol. Root is not required. The user specifies the serial device of the rp2040 they wish to flash as the device. This device is reset into bootsel mode and `rp2040_flash` is invoked on the original USB device path. If the device is already in bootloader mode, the user can specify 'first' as `FLASH_DEVICE` which will simply invoke `rp2040_flash` with no bus/address options. Signed-off-by: Lasse Dalegaard --- lib/.gitignore | 1 + lib/README | 5 + lib/rp2040/boot/picoboot.h | 124 +++++++ lib/rp2040/pico/platform.h | 139 ++++++++ lib/rp2040_flash/Makefile | 20 ++ lib/rp2040_flash/main.c | 246 ++++++++++++++ lib/rp2040_flash/picoboot_connection.c | 428 +++++++++++++++++++++++++ lib/rp2040_flash/picoboot_connection.h | 111 +++++++ scripts/flash_usb.py | 44 ++- src/rp2040/Makefile | 13 +- 10 files changed, 1124 insertions(+), 7 deletions(-) create mode 100644 lib/rp2040/boot/picoboot.h create mode 100644 lib/rp2040/pico/platform.h create mode 100644 lib/rp2040_flash/Makefile create mode 100644 lib/rp2040_flash/main.c create mode 100644 lib/rp2040_flash/picoboot_connection.c create mode 100644 lib/rp2040_flash/picoboot_connection.h diff --git a/lib/.gitignore b/lib/.gitignore index 5d195d36..48aa9508 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -3,3 +3,4 @@ bossac/bin/ bossac/obj/ hidflash/hid-flash hub-ctrl/hub-ctrl +rp2040_flash/rp2040_flash diff --git a/lib/README b/lib/README index 84c3e0d9..4a94c9f2 100644 --- a/lib/README +++ b/lib/README @@ -74,6 +74,11 @@ version 1.2.0 (bfcbefafc5d2a210551a4d9d80b4303d4ae0adf7). It has been modified so that it can build outside of the pico sdk. See rp2040.patch for the modifications. +The rp2040_flash directory contains a light-weight bootsel flash tool. +It uses C part of the the `picoboot_connection` directory found in: + https://github.com/raspberrypi/picotool.git +version v1.1.0 (55fd880c3dc029b961fc1a0967a6cfdc0af02721). + The hub-ctrl directory contains code from: https://github.com/codazoda/hub-ctrl.c/ revision 42095e522859059e8a5f4ec05c1e3def01a870a9. diff --git a/lib/rp2040/boot/picoboot.h b/lib/rp2040/boot/picoboot.h new file mode 100644 index 00000000..ddfa0aaa --- /dev/null +++ b/lib/rp2040/boot/picoboot.h @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _BOOT_PICOBOOT_H +#define _BOOT_PICOBOOT_H + +#include +#include +#include + +#ifndef NO_PICO_PLATFORM +#include "pico/platform.h" +#endif + +/** \file picoboot.h +* \defgroup boot_picoboot boot_picoboot +* +* Header file for the PICOBOOT USB interface exposed by an RP2040 in BOOTSEL mode. +*/ + +#define PICOBOOT_MAGIC 0x431fd10bu + +// -------------------------------------------- +// CONTROL REQUESTS FOR THE PICOBOOT INTERFACE +// -------------------------------------------- + +// size 0 OUT - unstall EPs and reset +#define PICOBOOT_IF_RESET 0x41 + +// size 16 IN - return the status of the last command +#define PICOBOOT_IF_CMD_STATUS 0x42 + +// -------------------------------------------------- +// COMMAND REQUESTS SENT TO THE PICOBOOT OUT ENDPOINT +// -------------------------------------------------- +// +// picoboot_cmd structure of size 32 is sent to OUT endpoint +// transfer_length bytes are transferred via IN/OUT +// device responds on success with 0 length ACK packet set via OUT/IN +// device may stall the transferring endpoint in case of error + +enum picoboot_cmd_id { + PC_EXCLUSIVE_ACCESS = 0x1, + PC_REBOOT = 0x2, + PC_FLASH_ERASE = 0x3, + PC_READ = 0x84, // either RAM or FLASH + PC_WRITE = 5, // either RAM or FLASH (does no erase) + PC_EXIT_XIP = 0x6, + PC_ENTER_CMD_XIP = 0x7, + PC_EXEC = 0x8, + PC_VECTORIZE_FLASH = 0x9 +}; + +enum picoboot_status { + PICOBOOT_OK = 0, + PICOBOOT_UNKNOWN_CMD = 1, + PICOBOOT_INVALID_CMD_LENGTH = 2, + PICOBOOT_INVALID_TRANSFER_LENGTH = 3, + PICOBOOT_INVALID_ADDRESS = 4, + PICOBOOT_BAD_ALIGNMENT = 5, + PICOBOOT_INTERLEAVED_WRITE = 6, + PICOBOOT_REBOOTING = 7, + PICOBOOT_UNKNOWN_ERROR = 8, +}; + +struct __packed picoboot_reboot_cmd { + uint32_t dPC; // 0 means reset into bootrom + uint32_t dSP; + uint32_t dDelayMS; +}; + +// used for EXEC, VECTORIZE_FLASH +struct __packed picoboot_address_only_cmd { + uint32_t dAddr; +}; + +// used for READ, WRITE, FLASH_ERASE +struct __packed picoboot_range_cmd { + uint32_t dAddr; + uint32_t dSize; +}; + +enum picoboot_exclusive_type { + NOT_EXCLUSIVE = 0, + EXCLUSIVE, + EXCLUSIVE_AND_EJECT +}; + +struct __packed picoboot_exclusive_cmd { + uint8_t bExclusive; +}; + +// little endian +struct __packed __aligned(4) picoboot_cmd { + uint32_t dMagic; + uint32_t dToken; // an identifier for this token to correlate with a status response + uint8_t bCmdId; // top bit set for IN + uint8_t bCmdSize; // bytes of actual data in the arg part of this structure + uint16_t _unused; + uint32_t dTransferLength; // length of IN/OUT transfer (or 0) if none + union { + uint8_t args[16]; + struct picoboot_reboot_cmd reboot_cmd; + struct picoboot_range_cmd range_cmd; + struct picoboot_address_only_cmd address_only_cmd; + struct picoboot_exclusive_cmd exclusive_cmd; + }; +}; + +static_assert(32 == sizeof(struct picoboot_cmd), "picoboot_cmd must be 32 bytes big"); + +struct __packed __aligned(4) picoboot_cmd_status { + uint32_t dToken; + uint32_t dStatusCode; + uint8_t bCmdId; + uint8_t bInProgress; + uint8_t _pad[6]; +}; + +static_assert(16 == sizeof(struct picoboot_cmd_status), "picoboot_cmd_status must be 16 bytes big"); +#endif diff --git a/lib/rp2040/pico/platform.h b/lib/rp2040/pico/platform.h new file mode 100644 index 00000000..499bdf64 --- /dev/null +++ b/lib/rp2040/pico/platform.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _PICO_PLATFORM_H_ +#define _PICO_PLATFORM_H_ + +#include "hardware/platform_defs.h" +#include + +#ifdef __unix__ + +#include + +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define __not_in_flash(grup) +#define __not_in_flash_func(func) func +#define __no_inline_not_in_flash_func(func) +#define __in_flash(group) +#define __scratch_x(group) +#define __scratch_y(group) + +#define __packed_aligned +#define __packed + +#define __time_critical_func(x) x +#define __after_data(group) + +//int running_on_fpga() { return false; } +extern void tight_loop_contents(); + +#ifndef __STRING +#define __STRING(x) #x +#endif + +#ifndef _MSC_VER +#ifndef __noreturn +#define __noreturn __attribute((noreturn)) +#endif + +#ifndef __unused +#define __unused __attribute__((unused)) +#endif + +#ifndef __noinline +#define __noinline __attribute__((noinline)) +#endif + +#ifndef __aligned +#define __aligned(x) __attribute__((aligned(x))) +#endif + +#define PICO_WEAK_FUNCTION_DEF(x) _Pragma(__STRING(weak x)) +#define PICO_WEAK_FUNCTION_IMPL_NAME(x) x + +#else +#ifndef __noreturn +#define __noreturn __declspec(noreturn) +#endif + +#ifndef __unused +#define __unused +#endif + +#ifndef __noinline +#define __noinline __declspec(noinline) +#endif + +#ifndef __aligned +#define __aligned(x) __declspec(align(x)) +#endif + +#ifndef __CONCAT +#define __CONCAT(x,y) x ## y +#endif + +#define __thread __declspec( thread ) + +#define PICO_WEAK_FUNCTION_DEF(x) __pragma(comment(linker, __STRING(/alternatename:_##x=_##x##__weak))); +#define PICO_WEAK_FUNCTION_IMPL_NAME(x) x ## __weak + +static __noreturn void __builtin_unreachable() { +} + +#include +#define __builtin_clz __lzcnt +#endif + +#ifndef count_of +#define count_of(a) (sizeof(a)/sizeof((a)[0])) +#endif + +#ifndef MAX +#define MAX(a, b) ((a)>(b)?(a):(b)) +#endif + +#ifndef MIN +#define MIN(a, b) ((b)>(a)?(a):(b)) +#endif + +// abort in our case +void __noreturn __breakpoint(); + +void __noreturn panic_unsupported(); + +void __noreturn panic(const char *fmt, ...); + +// arggggghhhh there is a weak function called sem_init used by SDL +#define sem_init sem_init_alternative + +extern uint32_t host_safe_hw_ptr_impl(uintptr_t x); +// return a 32 bit handle for a raw ptr; DMA chaining for example embeds pointers in 32 bit values +// which of course does not work if we're running the code natively on a 64 bit platforms. Therefore +// we provide this macro which allows that code to provide a 64->32 bit mapping in host mode +#define host_safe_hw_ptr(x) host_safe_hw_ptr_impl((uintptr_t)(x)) +void *decode_host_safe_hw_ptr(uint32_t ptr); + +#define __fast_mul(a,b) ((a)*(b)) + +typedef unsigned int uint; + +static inline int32_t __mul_instruction(int32_t a,int32_t b) +{ + return a*b; +} + +static inline void __compiler_memory_barrier(void) { +} +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/rp2040_flash/Makefile b/lib/rp2040_flash/Makefile new file mode 100644 index 00000000..d98a72d9 --- /dev/null +++ b/lib/rp2040_flash/Makefile @@ -0,0 +1,20 @@ +CC=gcc +CFLAGS=-c -Wall -ggdb +LDFALGS= +SOURCES=main.c picoboot_connection.c +OBJECTS=$(SOURCES:.c=.o) +LIBS=`pkg-config libusb-1.0 --libs` +INCLUDE_DIRS+=-I../rp2040/ `pkg-config libusb-1.0 --cflags` + +EXECUTABLE=rp2040_flash + +all: $(EXECUTABLE) + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $@ + +.c.o: + $(CC) $(CFLAGS) $(INCLUDE_DIRS) $< -o $@ + +clean: + rm -f $(OBJECTS) $(EXECUTABLE) diff --git a/lib/rp2040_flash/main.c b/lib/rp2040_flash/main.c new file mode 100644 index 00000000..1c111951 --- /dev/null +++ b/lib/rp2040_flash/main.c @@ -0,0 +1,246 @@ +// Simple rp2040 picoboot based flash tool for use with Klipper +// +// Copyright (C) 2022 Lasse Dalegaard +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include +#include +#include +#include +#include +#include "picoboot_connection.h" +#include "boot/uf2.h" + +#define FLASH_MAX_SIZE (FLASH_END - FLASH_START) +#define FLASH_NUM_WRITE_BLOCKS (FLASH_MAX_SIZE / PAGE_SIZE) +#define FLASH_NUM_ERASE_BLOCKS (FLASH_MAX_SIZE / FLASH_SECTOR_ERASE_SIZE) + +struct flash_data { + size_t num_blocks; + uint8_t flash_data[FLASH_MAX_SIZE]; + bool write_blocks[FLASH_NUM_WRITE_BLOCKS]; + bool erase_blocks[FLASH_NUM_ERASE_BLOCKS]; +}; + +int load_flash_data(const char *filename, struct flash_data *target) { + int rc = 0; + FILE *file = fopen(filename, "rb"); + if (!file) { + fprintf(stderr, "Could not open image file %s\n", filename); + rc = errno; + goto do_exit; + } + + target->num_blocks = 0; + memset(target->write_blocks, 0, sizeof(target->write_blocks)); + memset(target->erase_blocks, 0, sizeof(target->erase_blocks)); + + struct uf2_block block; + + while (1) { + if(fread(&block, sizeof(struct uf2_block), 1, file) != 1) { + if (feof(file)) { + break; + } + fprintf(stderr, "Unexpected EOF reading image\n"); + rc = errno; + goto do_exit; + } + + // Check magic numbers + if (block.magic_start0 != UF2_MAGIC_START0) continue; + if (block.magic_start1 != UF2_MAGIC_START1) continue; + if (block.magic_end != UF2_MAGIC_END) continue; + + // Check block is valid for flashing + // Always family ID. + if (!(block.flags & UF2_FLAG_FAMILY_ID_PRESENT)) continue; + if (block.file_size != RP2040_FAMILY_ID) continue; + if (block.flags & UF2_FLAG_NOT_MAIN_FLASH) continue; + if (block.payload_size != PAGE_SIZE) continue; + + // Bounds and alignment checking + if (block.target_addr != (block.target_addr & ~(PAGE_SIZE-1))) continue; + if (block.target_addr > FLASH_END - PAGE_SIZE) continue; + if (block.target_addr < FLASH_START) continue; + + uint32_t offset = block.target_addr - FLASH_START; + + // Copy data and mark the matching write and erase blocks + memcpy(&target->flash_data[offset], block.data, PAGE_SIZE); + target->write_blocks[offset / PAGE_SIZE] = 1; + target->erase_blocks[offset / FLASH_SECTOR_ERASE_SIZE] = 1; + + target->num_blocks++; + } + +do_exit: + if (file) { + fclose(file); + } + return rc; +} + +const char *status_codes_strings[] = { + "ok", + "unknown command", + "bad address alignment", + "interleaved write", + "invalid address", + "invalid cmd length", + "invalid transfer length", + "rebooting", + "unknown error", +}; + +int report_error(libusb_device_handle *handle, const char *cmd) { + struct picoboot_cmd_status status; + status.dStatusCode = 0; + int rc = picoboot_cmd_status(handle, &status); + if (rc) { + fprintf(stderr, "Command %s failed, and it was not possible to " + "query PICOBOOT status\n", cmd); + } else { + if (status.dStatusCode == 0) status.dStatusCode = 8; + fprintf(stderr, "Command %s failed with status %d: %s\n", + cmd, status.dStatusCode, + status_codes_strings[status.dStatusCode]); + } + return 1; +}; + +int picoboot_flash(libusb_device_handle *handle, struct flash_data *image) { + fprintf(stderr, "Resetting interface\n"); + if (picoboot_reset(handle)) { + return report_error(handle, "reset"); + } + + fprintf(stderr, "Locking\n"); + if (picoboot_exclusive_access(handle, EXCLUSIVE)) { + return report_error(handle, "exclusive_access"); + } + + fprintf(stderr, "Exiting XIP mode\n"); + if (picoboot_exit_xip(handle)) { + return report_error(handle, "exit_xip"); + } + + fprintf(stderr, "Erasing\n"); + for(size_t i = 0; i < FLASH_NUM_ERASE_BLOCKS; i++) { + if (!image->erase_blocks[i]) continue; + uint32_t addr = FLASH_START + i * FLASH_SECTOR_ERASE_SIZE; + if (picoboot_flash_erase(handle, addr, FLASH_SECTOR_ERASE_SIZE)) { + return report_error(handle, "flash_erase"); + } + } + + fprintf(stderr, "Flashing\n"); + for(size_t i = 0; i < FLASH_NUM_WRITE_BLOCKS; i++) { + if (!image->write_blocks[i]) continue; + uint32_t addr = FLASH_START + i * PAGE_SIZE; + uint8_t *buf = &image->flash_data[i * PAGE_SIZE]; + if (picoboot_write(handle, addr, buf, PAGE_SIZE)) { + return report_error(handle, "write"); + } + } + + fprintf(stderr, "Rebooting device\n"); + if (picoboot_reboot(handle, 0, 0, 500)) { + return report_error(handle, "reboot"); + } + + return 0; +} + +void print_usage(char *argv[]) { + fprintf(stderr, "Usage: %s [bus addr]\n", argv[0]); + exit(1); +} + +int main(int argc, char *argv[]) { + libusb_context *ctx = 0; + struct libusb_device **devs = 0; + libusb_device_handle *handle = 0; + struct flash_data *image = malloc(sizeof(struct flash_data)); + int rc = 0; + + if (argc != 2 && argc != 4) { + print_usage(argv); + } + + if (load_flash_data(argv[1], image)) { + fprintf(stderr, "Could not load flash image, exiting\n"); + rc = 1; + goto do_exit; + } + fprintf(stderr, "Loaded UF2 image with %lu pages\n", image->num_blocks); + + bool has_target = false; + uint8_t target_bus = 0; + uint8_t target_address = 0; + if(argc == 4) { + has_target = true; + + char *endptr; + target_bus = strtol(argv[2], &endptr, 10); + if (endptr == argv[2] || *endptr != 0) print_usage(argv); + + target_address = strtol(argv[3], &endptr, 10); + if (endptr == argv[3] || *endptr != 0) print_usage(argv); + } + + if (libusb_init(&ctx)) { + fprintf(stderr, "Could not initialize libusb\n"); + rc = 1; + goto do_exit; + } + + ssize_t cnt = libusb_get_device_list(ctx, &devs); + if (cnt < 0) { + fprintf(stderr, "Failed to enumerate USB devices: %s", + libusb_strerror(cnt)); + rc = 1; + goto do_exit; + } + + for (libusb_device **dev = devs; *dev; ++dev) { + if (has_target) { + if (target_bus != libusb_get_bus_number(*dev)) continue; + if (target_address != libusb_get_device_address(*dev)) continue; + } + enum picoboot_device_result res = picoboot_open_device(*dev, &handle); + if (res == dr_vidpid_bootrom_ok) { + break; + } + if (handle) { + libusb_close(handle); + handle = 0; + } + } + + if (!handle) { + fprintf(stderr, "No rp2040 in BOOTSEL mode was found\n"); + goto do_exit; + } + + libusb_device *dev = libusb_get_device(handle); + fprintf(stderr, "Found rp2040 device on USB bus %d address %d\n", + libusb_get_bus_number(dev), libusb_get_device_address(dev)); + fprintf(stderr, "Flashing...\n"); + + rc = picoboot_flash(handle, image); + +do_exit: + if (handle) { + libusb_close(handle); + } + if (devs) { + libusb_free_device_list(devs, 1); + } + if (ctx) { + libusb_exit(ctx); + } + free(image); + return rc; +} diff --git a/lib/rp2040_flash/picoboot_connection.c b/lib/rp2040_flash/picoboot_connection.c new file mode 100644 index 00000000..c0d21769 --- /dev/null +++ b/lib/rp2040_flash/picoboot_connection.c @@ -0,0 +1,428 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include + +#include "picoboot_connection.h" + +#if false && !defined(NDEBUG) +#define output(format,...) printf(format, __VA_ARGS__) +#else +#define output(format,...) ((void)0) +#endif + +static bool verbose; + +// todo test sparse binary (well actually two range is this) + +#define VENDOR_ID_RASPBERRY_PI 0x2e8au +#define PRODUCT_ID_RP2_USBBOOT 0x0003u +#define PRODUCT_ID_PICOPROBE 0x0004u +#define PRODUCT_ID_MICROPYTHON 0x0005u +#define PRODUCT_ID_STDIO_USB 0x000au + +uint32_t crc32_for_byte(uint32_t remainder) { + const uint32_t POLYNOMIAL = 0x4C11DB7; + remainder <<= 24u; + for (uint bit = 8; bit > 0; bit--) { + if (remainder & 0x80000000) + remainder = (remainder << 1) ^ POLYNOMIAL; + else + remainder = (remainder << 1); + } + return remainder; +} + +uint32_t crc32_sw(const uint8_t *buf, uint count, uint32_t crc) { + static uint32_t table[0x100]; + if (!table[1]) { + for (uint i = 0; i < count_of(table); i++) { + table[i] = crc32_for_byte(i); + } + } + for (uint i = 0; i < count; ++i) { + crc = (crc << 8u) ^ table[(uint8_t) ((crc >> 24u) ^ buf[i])]; + } + return crc; +} + +uint interface; +uint out_ep; +uint in_ep; + +enum picoboot_device_result picoboot_open_device(libusb_device *device, libusb_device_handle **dev_handle) { + struct libusb_device_descriptor desc; + struct libusb_config_descriptor *config; + + *dev_handle = NULL; + int ret = libusb_get_device_descriptor(device, &desc); + if (ret && verbose) { + output("Failed to read device descriptor"); + } + if (!ret) { + if (desc.idVendor != VENDOR_ID_RASPBERRY_PI) { + return dr_vidpid_unknown; + } + switch (desc.idProduct) { + case PRODUCT_ID_MICROPYTHON: + return dr_vidpid_micropython; + case PRODUCT_ID_PICOPROBE: + return dr_vidpid_picoprobe; + case PRODUCT_ID_STDIO_USB: + return dr_vidpid_stdio_usb; + case PRODUCT_ID_RP2_USBBOOT: + break; + default: + return dr_vidpid_unknown; + } + ret = libusb_get_active_config_descriptor(device, &config); + if (ret && verbose) { + output("Failed to read config descriptor\n"); + } + } + + if (!ret) { + ret = libusb_open(device, dev_handle); + if (ret && verbose) { + output("Failed to open device %d\n", ret); + } + if (ret) { + return dr_vidpid_bootrom_cant_connect; + } + } + + if (!ret) { + if (config->bNumInterfaces == 1) { + interface = 0; + } else { + interface = 1; + } + if (config->interface[interface].altsetting[0].bInterfaceClass == 0xff && + config->interface[interface].altsetting[0].bNumEndpoints == 2) { + out_ep = config->interface[interface].altsetting[0].endpoint[0].bEndpointAddress; + in_ep = config->interface[interface].altsetting[0].endpoint[1].bEndpointAddress; + } + if (out_ep && in_ep && !(out_ep & 0x80u) && (in_ep & 0x80u)) { + if (verbose) output("Found PICOBOOT interface\n"); + ret = libusb_claim_interface(*dev_handle, interface); + if (ret) { + if (verbose) output("Failed to claim interface\n"); + return dr_vidpid_bootrom_no_interface; + } + + return dr_vidpid_bootrom_ok; + } else { + if (verbose) output("Did not find PICOBOOT interface\n"); + return dr_vidpid_bootrom_no_interface; + } + } + + assert(ret); + + if (*dev_handle) { + libusb_close(*dev_handle); + *dev_handle = NULL; + } + + return dr_error; +} + +static bool is_halted(libusb_device_handle *usb_device, int ep) { + uint8_t data[2]; + + int transferred = libusb_control_transfer( + usb_device, + /*LIBUSB_REQUEST_TYPE_STANDARD | */LIBUSB_RECIPIENT_ENDPOINT | LIBUSB_ENDPOINT_IN, + LIBUSB_REQUEST_GET_STATUS, + 0, ep, + data, sizeof(data), + 1000); + if (transferred != sizeof(data)) { + output("Get status failed\n"); + return false; + } + if (data[0] & 1) { + if (verbose) output("%d was halted\n", ep); + return true; + } + if (verbose) output("%d was not halted\n", ep); + return false; +} + +int picoboot_reset(libusb_device_handle *usb_device) { + if (verbose) output("RESET\n"); + if (is_halted(usb_device, in_ep)) + libusb_clear_halt(usb_device, in_ep); + if (is_halted(usb_device, out_ep)) + libusb_clear_halt(usb_device, out_ep); + int ret = + libusb_control_transfer(usb_device, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_INTERFACE, + PICOBOOT_IF_RESET, 0, interface, NULL, 0, 1000); + + if (ret != 0) { + output(" ...failed\n"); + return ret; + } + if (verbose) output(" ...ok\n"); + return 0; +} + +int picoboot_cmd_status_verbose(libusb_device_handle *usb_device, struct picoboot_cmd_status *status, bool local_verbose) { + struct picoboot_cmd_status s; + if (!status) status = &s; + + if (local_verbose) output("CMD_STATUS\n"); + int ret = + libusb_control_transfer(usb_device, + LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_IN, + PICOBOOT_IF_CMD_STATUS, 0, interface, (uint8_t *) status, sizeof(*status), 1000); + + if (ret != sizeof(*status)) { + output(" ...failed\n"); + return ret; + } + if (local_verbose) + output(" ... cmd %02x%s tok=%08x status=%d\n", status->bCmdId, status->bInProgress ? " (in progress)" : "", + status->dToken, status->dStatusCode); + return 0; +} + +int picoboot_cmd_status(libusb_device_handle *usb_device, struct picoboot_cmd_status *status) { + return picoboot_cmd_status_verbose(usb_device, status, verbose); +} + +int one_time_bulk_timeout; + +int picoboot_cmd(libusb_device_handle *usb_device, struct picoboot_cmd *cmd, uint8_t *buffer, uint buf_size) { + int sent = 0; + int ret; + + static int token = 1; + cmd->dMagic = PICOBOOT_MAGIC; + cmd->dToken = token++; + ret = libusb_bulk_transfer(usb_device, out_ep, (uint8_t *) cmd, sizeof(struct picoboot_cmd), &sent, 3000); + + if (ret != 0 || sent != sizeof(struct picoboot_cmd)) { + output(" ...failed to send command %d\n", ret); + return ret; + } + + int timeout = 10000; + if (one_time_bulk_timeout) { + timeout = one_time_bulk_timeout; + one_time_bulk_timeout = 0; + } + if (cmd->dTransferLength != 0) { + assert(buf_size >= cmd->dTransferLength); + if (cmd->bCmdId & 0x80u) { + if (verbose) output(" receive %d...\n", cmd->dTransferLength); + int received = 0; + ret = libusb_bulk_transfer(usb_device, in_ep, buffer, cmd->dTransferLength, &received, timeout); + if (ret != 0 || received != (int) cmd->dTransferLength) { + output(" ...failed to receive data %d %d/%d\n", ret, received, cmd->dTransferLength); + if (!ret) ret = 1; + return ret; + } + } else { + if (verbose) output(" send %d...\n", cmd->dTransferLength); + ret = libusb_bulk_transfer(usb_device, out_ep, buffer, cmd->dTransferLength, &sent, timeout); + if (ret != 0 || sent != (int) cmd->dTransferLength) { + output(" ...failed to send data %d %d/%d\n", ret, sent, cmd->dTransferLength); + if (!ret) ret = 1; + picoboot_cmd_status_verbose(usb_device, NULL, true); + return ret; + } + } + } + + // ack is in opposite direction + int received = 0; + uint8_t spoon[64]; + if (cmd->bCmdId & 0x80u) { + if (verbose) output("zero length out\n"); + ret = libusb_bulk_transfer(usb_device, out_ep, spoon, 1, &received, cmd->dTransferLength == 0 ? timeout : 3000); + } else { + if (verbose) output("zero length in\n"); + ret = libusb_bulk_transfer(usb_device, in_ep, spoon, 1, &received, cmd->dTransferLength == 0 ? timeout : 3000); + } + return ret; +} + +int picoboot_exclusive_access(libusb_device_handle *usb_device, uint8_t exclusive) { + if (verbose) output("EXCLUSIVE ACCESS %d\n", exclusive); + struct picoboot_cmd cmd; + cmd.bCmdId = PC_EXCLUSIVE_ACCESS; + cmd.exclusive_cmd.bExclusive = exclusive; + cmd.bCmdSize = sizeof(struct picoboot_exclusive_cmd); + cmd.dTransferLength = 0; + return picoboot_cmd(usb_device, &cmd, NULL, 0); +} + +int picoboot_exit_xip(libusb_device_handle *usb_device) { + struct picoboot_cmd cmd; + if (verbose) output("EXIT_XIP\n"); + cmd.bCmdId = PC_EXIT_XIP; + cmd.bCmdSize = 0; + cmd.dTransferLength = 0; + return picoboot_cmd(usb_device, &cmd, NULL, 0); +} + +int picoboot_enter_cmd_xip(libusb_device_handle *usb_device) { + struct picoboot_cmd cmd; + if (verbose) output("ENTER_CMD_XIP\n"); + cmd.bCmdId = PC_ENTER_CMD_XIP; + cmd.bCmdSize = 0; + cmd.dTransferLength = 0; + return picoboot_cmd(usb_device, &cmd, NULL, 0); +} + +int picoboot_reboot(libusb_device_handle *usb_device, uint32_t pc, uint32_t sp, uint32_t delay_ms) { + struct picoboot_cmd cmd; + if (verbose) output("REBOOT %08x %08x %u\n", (uint) pc, (uint) sp, (uint) delay_ms); + cmd.bCmdId = PC_REBOOT; + cmd.bCmdSize = sizeof(cmd.reboot_cmd); + cmd.dTransferLength = 0; + cmd.reboot_cmd.dPC = pc; + cmd.reboot_cmd.dSP = sp; + cmd.reboot_cmd.dDelayMS = delay_ms; + return picoboot_cmd(usb_device, &cmd, NULL, 0); +} + +int picoboot_exec(libusb_device_handle *usb_device, uint32_t addr) { + struct picoboot_cmd cmd; + // shouldn't be necessary any more + // addr |= 1u; // Thumb bit + if (verbose) output("EXEC %08x\n", (uint) addr); + cmd.bCmdId = PC_EXEC; + cmd.bCmdSize = sizeof(cmd.address_only_cmd); + cmd.dTransferLength = 0; + cmd.address_only_cmd.dAddr = addr; + return picoboot_cmd(usb_device, &cmd, NULL, 0); +} + +int picoboot_flash_erase(libusb_device_handle *usb_device, uint32_t addr, uint32_t len) { + struct picoboot_cmd cmd; + if (verbose) output("FLASH_ERASE %08x+%08x\n", (uint) addr, (uint) len); + cmd.bCmdId = PC_FLASH_ERASE; + cmd.bCmdSize = sizeof(cmd.range_cmd); + cmd.range_cmd.dAddr = addr; + cmd.range_cmd.dSize = len; + cmd.dTransferLength = 0; + return picoboot_cmd(usb_device, &cmd, NULL, 0); +} + +int picoboot_vector(libusb_device_handle *usb_device, uint32_t addr) { + struct picoboot_cmd cmd; + if (verbose) output("VECTOR %08x\n", (uint) addr); + cmd.bCmdId = PC_VECTORIZE_FLASH; + cmd.bCmdSize = sizeof(cmd.address_only_cmd); + cmd.range_cmd.dAddr = addr; + cmd.dTransferLength = 0; + return picoboot_cmd(usb_device, &cmd, NULL, 0); +} + +int picoboot_write(libusb_device_handle *usb_device, uint32_t addr, uint8_t *buffer, uint32_t len) { + struct picoboot_cmd cmd; + if (verbose) output("WRITE %08x+%08x\n", (uint) addr, (uint) len); + cmd.bCmdId = PC_WRITE; + cmd.bCmdSize = sizeof(cmd.range_cmd); + cmd.range_cmd.dAddr = addr; + cmd.range_cmd.dSize = cmd.dTransferLength = len; + return picoboot_cmd(usb_device, &cmd, buffer, len); +} + +int picoboot_read(libusb_device_handle *usb_device, uint32_t addr, uint8_t *buffer, uint32_t len) { + memset(buffer, 0xaa, len); + if (verbose) output("READ %08x+%08x\n", (uint) addr, (uint) len); + struct picoboot_cmd cmd; + cmd.bCmdId = PC_READ; + cmd.bCmdSize = sizeof(cmd.range_cmd); + cmd.range_cmd.dAddr = addr; + cmd.range_cmd.dSize = cmd.dTransferLength = len; + int ret = picoboot_cmd(usb_device, &cmd, buffer, len); + if (!ret && len < 256 && verbose) { + for (uint32_t i = 0; i < len; i += 32) { + output("\t"); + for (uint32_t j = i; j < MIN(len, i + 32); j++) { + output("0x%02x, ", buffer[j]); + } + output("\n"); + } + } + return ret; +} + + +#if 0 +// Peek/poke via EXEC + +// 00000000 : +// 0: 4801 ldr r0, [pc, #4] ; (8 ) +// 2: 4902 ldr r1, [pc, #8] ; (c ) +// 4: 6008 str r0, [r1, #0] +// 6: 4770 bx lr +// 00000008 : +// 8: 12345678 .word 0x12345678 +// 0000000c : +// c: 9abcdef0 .word 0x9abcdef0 + + +static const size_t picoboot_poke_cmd_len = 8; +static const uint8_t picoboot_poke_cmd[] = { + 0x01, 0x48, 0x02, 0x49, 0x08, 0x60, 0x70, 0x47 +}; + +// 00000000 : +// 0: 4802 ldr r0, [pc, #8] ; (c ) +// 2: 6800 ldr r0, [r0, #0] +// 4: 4679 mov r1, pc +// 6: 6048 str r0, [r1, #4] +// 8: 4770 bx lr +// a: 46c0 nop ; (mov r8, r8) +// 0000000c : +// c: 0add7355 .word 0x0add7355 + +static const size_t picoboot_peek_cmd_len = 12; +static const uint8_t picoboot_peek_cmd[] = { + 0x02, 0x48, 0x00, 0x68, 0x79, 0x46, 0x48, 0x60, 0x70, 0x47, 0xc0, 0x46 +}; + +// TODO better place for this e.g. the USB DPRAM location the controller has already put it in +#define PEEK_POKE_CODE_LOC 0x20000000u + +int picoboot_poke(libusb_device_handle *usb_device, uint32_t addr, uint32_t data) { + const size_t prog_size = picoboot_poke_cmd_len + 8; + uint8_t prog[prog_size]; + output("POKE (D)%08x -> (A)%08x\n", data, addr); + memcpy(prog, picoboot_poke_cmd, picoboot_poke_cmd_len); + *(uint32_t *) (prog + picoboot_poke_cmd_len) = data; + *(uint32_t *) (prog + picoboot_poke_cmd_len + 4) = addr; + + int ret = picoboot_write(usb_device, PEEK_POKE_CODE_LOC, prog, prog_size); + if (ret) + return ret; + return picoboot_exec(usb_device, PEEK_POKE_CODE_LOC); +} + +// TODO haven't checked the store goes to the right address :) +int picoboot_peek(libusb_device_handle *usb_device, uint32_t addr, uint32_t *data) { + const size_t prog_size = picoboot_peek_cmd_len + 4; + uint8_t prog[prog_size]; + output("PEEK %08x\n", addr); + memcpy(prog, picoboot_peek_cmd, picoboot_peek_cmd_len); + *(uint32_t *) (prog + picoboot_peek_cmd_len) = addr; + + int ret = picoboot_write(usb_device, PEEK_POKE_CODE_LOC, prog, prog_size); + if (ret) + return ret; + ret = picoboot_exec(usb_device, PEEK_POKE_CODE_LOC); + if (ret) + return ret; + return picoboot_read(usb_device, PEEK_POKE_CODE_LOC + picoboot_peek_cmd_len, (uint8_t *) data, sizeof(uint32_t)); +} +#endif diff --git a/lib/rp2040_flash/picoboot_connection.h b/lib/rp2040_flash/picoboot_connection.h new file mode 100644 index 00000000..ebdabfc9 --- /dev/null +++ b/lib/rp2040_flash/picoboot_connection.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _PICOBOOT_CONNECTION_H +#define _PICOBOOT_CONNECTION_H + +// todo we should use fully encapsulate libusb + +#include +#include +#include "boot/picoboot.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum picoboot_device_result { + dr_vidpid_bootrom_ok, + dr_vidpid_bootrom_no_interface, + dr_vidpid_bootrom_cant_connect, + dr_vidpid_micropython, + dr_vidpid_picoprobe, + dr_vidpid_unknown, + dr_error, + dr_vidpid_stdio_usb, +}; + +enum picoboot_device_result picoboot_open_device(libusb_device *device, libusb_device_handle **dev_handle); + +int picoboot_reset(libusb_device_handle *usb_device); +int picoboot_cmd_status_verbose(libusb_device_handle *usb_device, struct picoboot_cmd_status *status, + bool local_verbose); +int picoboot_cmd_status(libusb_device_handle *usb_device, struct picoboot_cmd_status *status); +int picoboot_exclusive_access(libusb_device_handle *usb_device, uint8_t exclusive); +int picoboot_enter_cmd_xip(libusb_device_handle *usb_device); +int picoboot_exit_xip(libusb_device_handle *usb_device); +int picoboot_reboot(libusb_device_handle *usb_device, uint32_t pc, uint32_t sp, uint32_t delay_ms); +int picoboot_exec(libusb_device_handle *usb_device, uint32_t addr); +int picoboot_flash_erase(libusb_device_handle *usb_device, uint32_t addr, uint32_t len); +int picoboot_vector(libusb_device_handle *usb_device, uint32_t addr); +int picoboot_write(libusb_device_handle *usb_device, uint32_t addr, uint8_t *buffer, uint32_t len); +int picoboot_read(libusb_device_handle *usb_device, uint32_t addr, uint8_t *buffer, uint32_t len); +int picoboot_poke(libusb_device_handle *usb_device, uint32_t addr, uint32_t data); +int picoboot_peek(libusb_device_handle *usb_device, uint32_t addr, uint32_t *data); + +#define ROM_START 0x00000000 +#define ROM_END 0x00004000 +#define FLASH_START 0x10000000 +#define FLASH_END 0x11000000 // this is maximum +#define XIP_SRAM_BASE 0x15000000 +#define XIP_SRAM_END 0x15004000 + +#define SRAM_START 0x20000000 +#define SRAM_END 0x20042000 + +#define SRAM_UNSTRIPED_START 0x21000000 +#define SRAM_UNSTRIPED_END 0x21040000 + +// we require 256 (as this is the page size supported by the device) +#define LOG2_PAGE_SIZE 8u +#define PAGE_SIZE (1u << LOG2_PAGE_SIZE) +#define FLASH_SECTOR_ERASE_SIZE 4096u + +enum memory_type { + rom, + flash, + sram, + sram_unstriped, + xip_sram, + invalid, +}; + +// inclusive of ends +static inline enum memory_type get_memory_type(uint32_t addr) { + if (addr >= ROM_START && addr <= ROM_END) { + return rom; + } + if (addr >= FLASH_START && addr <= FLASH_END) { + return flash; + } + if (addr >= SRAM_START && addr <= SRAM_END) { + return sram; + } + if (addr >= SRAM_UNSTRIPED_START && addr <= SRAM_UNSTRIPED_END) { + return sram_unstriped; + } + if (addr >= XIP_SRAM_BASE && addr <= XIP_SRAM_END) { + return xip_sram; + } + return invalid; +} + +static inline bool is_transfer_aligned(uint32_t addr) { + enum memory_type t = get_memory_type(addr); + return t != invalid && !(t == flash && addr & (PAGE_SIZE-1)); +} + +static inline bool is_size_aligned(uint32_t addr, int size) { +#ifndef _MSC_VER + assert(__builtin_popcount(size)==1); +#endif + return !(addr & (size-1)); +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py index 04e2ba3f..581aa5c0 100755 --- a/scripts/flash_usb.py +++ b/scripts/flash_usb.py @@ -162,6 +162,20 @@ def flash_atsamd(options, binfile): options.device, str(e))) sys.exit(-1) +# Look for an rp2040 and flash it with rp2040_flash. +def rp2040_flash(devpath, binfile): + args = ["lib/rp2040_flash/rp2040_flash", binfile] + if len(devpath) > 0: + with open(devpath + "/busnum") as f: + bus = f.read().strip() + with open(devpath + "/devnum") as f: + addr = f.read().strip() + args += [bus, addr] + sys.stderr.write(" ".join(args) + '\n\n') + res = subprocess.call(args) + if res != 0: + raise error("Error running rp2040_flash") + SMOOTHIE_HELP = """ Failed to flash to %s: %s @@ -240,11 +254,39 @@ def flash_stm32f4(options, binfile): options.device, str(e), options.device)) sys.exit(-1) +RP2040_HELP = """ +Failed to flash to %s: %s + +If the device is already in bootloader mode, use 'first' as FLASH_DEVICE. +This will use rp2040_flash to flash the first available rp2040. + +Alternatively, one can flash rp2040 boards like the Pico by manually +entering bootloader mode(hold bootsel button during powerup), mount the +device as a usb drive, and copy klipper.uf2 to the device. +""" + +def flash_rp2040(options, binfile): + try: + if options.device.lower() == "first": + rp2040_flash("", binfile) + return + + buspath, devpath = translate_serial_to_usb_path(options.device) + # We need one level up to get access to busnum/devnum files + devpath = os.path.dirname(devpath) + enter_bootloader(options.device) + wait_path(devpath) + rp2040_flash(devpath, binfile) + + except error as e: + sys.stderr.write(RP2040_HELP % (options.device, str(e))) + sys.exit(-1) + MCUTYPES = { 'sam3': flash_atsam3, 'sam4': flash_atsam4, 'samd': flash_atsamd, 'lpc176': flash_lpc176x, 'stm32f103': flash_stm32f1, 'stm32f4': flash_stm32f4, 'stm32f042': flash_stm32f4, - 'stm32f072': flash_stm32f4 + 'stm32f072': flash_stm32f4, 'rp2040': flash_rp2040 } diff --git a/src/rp2040/Makefile b/src/rp2040/Makefile index b40df32d..2915b994 100644 --- a/src/rp2040/Makefile +++ b/src/rp2040/Makefile @@ -43,10 +43,11 @@ $(OUT)klipper.uf2: $(OUT)klipper.elf $(OUT)lib/rp2040/elf2uf2/elf2uf2 @echo " Creating uf2 file $@" $(Q)$(OUT)lib/rp2040/elf2uf2/elf2uf2 $< $@ +lib/rp2040_flash/rp2040_flash: + @echo " Building rp2040_flash" + $(Q)make -C lib/rp2040_flash rp2040_flash + # Flash rules -flash: $(OUT)klipper.uf2 - @echo "Error: Flashing not supported on rp2040." - @echo "Place target board in bootloader mode (hold bootsel button" - @echo "during powerup), mount the device as a usb drive, and copy" - @echo "$< to the device." - @exit -1 +flash: $(OUT)klipper.uf2 lib/rp2040_flash/rp2040_flash + @echo " Flashing $< to $(FLASH_DEVICE)" + $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(OUT)klipper.uf2 From 4c8d24ae03eadf3fc5a28efb1209ce810251d02d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 7 Jan 2022 22:17:26 -0500 Subject: [PATCH 015/211] stm32: Update Kconfig as CANBUS isn't available on stm32f401 Signed-off-by: Kevin O'Connor --- src/stm32/Kconfig | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index fa263574..e6710994 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -99,7 +99,7 @@ config HAVE_STM32_USBOTG default y if MACH_STM32F2 || MACH_STM32F4 || MACH_STM32H7 config HAVE_STM32_CANBUS bool - default y if MACH_STM32F1 || MACH_STM32F2 || MACH_STM32F4 || MACH_STM32F0x2 + default y if MACH_STM32F1 || MACH_STM32F2 || MACH_STM32F4x5 || MACH_STM32F446 || MACH_STM32F0x2 config MCU string @@ -314,25 +314,32 @@ choice depends on MACH_STM32H7 select SERIAL config STM32_CANBUS_PA11_PA12 - bool "CAN bus (on PA11/PA12)" if HAVE_STM32_CANBUS + bool "CAN bus (on PA11/PA12)" + depends on HAVE_STM32_CANBUS select CANSERIAL config STM32_CANBUS_PA11_PA12_REMAP - bool "CAN bus (on PA9/PA10)" if LOW_LEVEL_OPTIONS && MACH_STM32F042 + bool "CAN bus (on PA9/PA10)" if LOW_LEVEL_OPTIONS + depends on HAVE_STM32_CANBUS && MACH_STM32F042 select CANSERIAL config STM32_CANBUS_PB8_PB9 - bool "CAN bus (on PB8/PB9)" if LOW_LEVEL_OPTIONS && HAVE_STM32_CANBUS + bool "CAN bus (on PB8/PB9)" if LOW_LEVEL_OPTIONS + depends on HAVE_STM32_CANBUS select CANSERIAL config STM32_CANBUS_PI9_PH13 - bool "CAN bus (on PI9/PH13)" if LOW_LEVEL_OPTIONS && MACH_STM32F4 + bool "CAN bus (on PI9/PH13)" if LOW_LEVEL_OPTIONS + depends on HAVE_STM32_CANBUS && MACH_STM32F4 select CANSERIAL config STM32_CANBUS_PB5_PB6 - bool "CAN bus (on PB5/PB6)" if LOW_LEVEL_OPTIONS && MACH_STM32F4 + bool "CAN bus (on PB5/PB6)" if LOW_LEVEL_OPTIONS + depends on HAVE_STM32_CANBUS && MACH_STM32F4 select CANSERIAL config STM32_CANBUS_PB12_PB13 - bool "CAN bus (on PB12/PB13)" if LOW_LEVEL_OPTIONS && MACH_STM32F4 + bool "CAN bus (on PB12/PB13)" if LOW_LEVEL_OPTIONS + depends on HAVE_STM32_CANBUS && MACH_STM32F4 select CANSERIAL config STM32_CANBUS_PD0_PD1 - bool "CAN bus (on PD0/PD1)" if LOW_LEVEL_OPTIONS && MACH_STM32F4 + bool "CAN bus (on PD0/PD1)" if LOW_LEVEL_OPTIONS + depends on HAVE_STM32_CANBUS && MACH_STM32F4 select CANSERIAL endchoice From de366ee85479d9f9bf7f117a881feb8de522265d Mon Sep 17 00:00:00 2001 From: Paul McGowan Date: Sun, 9 Jan 2022 21:13:53 -0500 Subject: [PATCH 016/211] docs: Docs comma culture (#4822) Many non-English speaking countries use a comma as a decimal separator for printed numbers. This can create some confusion in documentation and config files when not surrounded by contextual clues like parenthesis. Improve documentation by adding spaces to coordinates. Signed-off-by: Paul McGowan --- config/example-polar.cfg | 2 +- config/example-winch.cfg | 2 +- config/kit-voron2-250mm.cfg | 10 +-- config/kit-zav3d-2019.cfg | 6 +- config/printer-anycubic-4maxpro-2.0-2021.cfg | 8 +- config/printer-creality-cr20-pro-2019.cfg | 8 +- config/printer-creality-ender5plus-2019.cfg | 4 +- config/printer-creality-ender6-2020.cfg | 2 +- config/printer-creality-sermoonD1-2021.cfg | 2 +- config/printer-eryone-er20-2021.cfg | 8 +- config/printer-fokoos-odin5-f3-2021.cfg | 12 +-- config/printer-hiprecy-leo-2019.cfg | 6 +- config/printer-longer-lk4-pro-2019.cfg | 6 +- config/printer-lulzbot-mini1-2016.cfg | 8 +- config/printer-lulzbot-taz6-2017.cfg | 10 +-- config/printer-lulzbot-taz6-dual-v3-2017.cfg | 10 +-- .../printer-monoprice-select-mini-v2-2018.cfg | 8 +- config/printer-mtw-create-2015.cfg | 6 +- config/printer-prusa-mini-plus-2020.cfg | 8 +- config/printer-tevo-flash-2018.cfg | 6 +- config/printer-tronxy-x5sa-pro-2020.cfg | 20 ++--- config/printer-tronxy-x5sa-v6-2019.cfg | 20 ++--- config/printer-velleman-k8800-2017.cfg | 2 +- config/printer-wanhao-duplicator-9-2018.cfg | 14 +-- ...r-wanhao-duplicator-i3-plus-mark2-2019.cfg | 6 +- config/sample-probe-as-z-endstop.cfg | 26 +++--- docs/BLTouch.md | 2 +- docs/Bed_Mesh.md | 52 +++++------ docs/Command_Templates.md | 2 +- docs/Config_Reference.md | 88 +++++++++---------- docs/G-Codes.md | 2 +- docs/Manual_Level.md | 30 +++---- docs/Measuring_Resonances.md | 2 +- docs/Probe_Calibrate.md | 2 +- docs/Rotation_Distance.md | 2 +- 35 files changed, 201 insertions(+), 201 deletions(-) diff --git a/config/example-polar.cfg b/config/example-polar.cfg index 62055038..90840fa1 100644 --- a/config/example-polar.cfg +++ b/config/example-polar.cfg @@ -1,7 +1,7 @@ # This file is an example config file for polar style printers. One # may copy and edit this file to configure a new polar printer. -# POLAR KINEMATICS ARE A WORK IN PROGRESS. Moves around the 0,0 +# POLAR KINEMATICS ARE A WORK IN PROGRESS. Moves around the 0, 0 # position are known to not work properly. # See docs/Config_Reference.md for a description of parameters. diff --git a/config/example-winch.cfg b/config/example-winch.cfg index 5813aef7..d6d62b8a 100644 --- a/config/example-winch.cfg +++ b/config/example-winch.cfg @@ -6,7 +6,7 @@ # Homing is not implemented on cable winch kinematics. In order to # home the printer, manually send movement commands until the toolhead -# is at 0,0,0 and then issue a G28 command. +# is at 0, 0, 0 and then issue a G28 command. # See docs/Config_Reference.md for a description of parameters. diff --git a/config/kit-voron2-250mm.cfg b/config/kit-voron2-250mm.cfg index 282e7595..343e9c67 100644 --- a/config/kit-voron2-250mm.cfg +++ b/config/kit-voron2-250mm.cfg @@ -227,14 +227,14 @@ gcode: [quad_gantry_level] # Use QUAD_GANTRY_LEVEL to level a gantry. gantry_corners: - -55,-7 + -55, -7 305, 320 # Min & Max gantry corners - measure from nozzle at MIN (0,0) and MAX (250,250) to respective belt positions points: - 25,0 - 25,200 - 225,200 - 225,0 + 25, 0 + 25, 200 + 225, 200 + 225, 0 # Probe points speed: 200 horizontal_move_z: 6 diff --git a/config/kit-zav3d-2019.cfg b/config/kit-zav3d-2019.cfg index b27e6017..e3b57b8e 100644 --- a/config/kit-zav3d-2019.cfg +++ b/config/kit-zav3d-2019.cfg @@ -134,9 +134,9 @@ sample_retract_dist: 3.0 [bed_mesh] speed: 100 horizontal_move_z: 5 -mesh_min: 69,41 -mesh_max: 189,161 -probe_count: 3,3 +mesh_min: 69, 41 +mesh_max: 189, 161 +probe_count: 3, 3 [homing_override] set_position_z: 6 diff --git a/config/printer-anycubic-4maxpro-2.0-2021.cfg b/config/printer-anycubic-4maxpro-2.0-2021.cfg index f87fce49..75d32411 100644 --- a/config/printer-anycubic-4maxpro-2.0-2021.cfg +++ b/config/printer-anycubic-4maxpro-2.0-2021.cfg @@ -132,10 +132,10 @@ max_z_accel: 50 square_corner_velocity: 5 [bed_screws] -screw1: 5,5 -screw2: 265,210 -screw3: 5,210 -screw4: 265,5 +screw1: 5, 5 +screw2: 265, 210 +screw3: 5, 210 +screw4: 265, 5 [filament_switch_sensor filament_sensor] switch_pin: ^!PC4 diff --git a/config/printer-creality-cr20-pro-2019.cfg b/config/printer-creality-cr20-pro-2019.cfg index 19b46b63..29f04fe6 100644 --- a/config/printer-creality-cr20-pro-2019.cfg +++ b/config/printer-creality-cr20-pro-2019.cfg @@ -64,7 +64,7 @@ speed: 3.0 samples: 1 [safe_z_home] -home_xy_position: 117,117 +home_xy_position: 117, 117 speed: 50.0 z_hop: 10.0 z_hop_speed: 100 @@ -72,9 +72,9 @@ z_hop_speed: 100 [bed_mesh] speed: 100 horizontal_move_z: 8 -mesh_min: 106,39 -mesh_max: 281,229 -probe_count: 3,3 +mesh_min: 106, 39 +mesh_max: 281, 229 +probe_count: 3, 3 [heater_bed] heater_pin: PH5 diff --git a/config/printer-creality-ender5plus-2019.cfg b/config/printer-creality-ender5plus-2019.cfg index f8e2d1be..2dd0ef2c 100644 --- a/config/printer-creality-ender5plus-2019.cfg +++ b/config/printer-creality-ender5plus-2019.cfg @@ -75,8 +75,8 @@ pin_up_touch_mode_reports_triggered: False speed: 100 horizontal_move_z: 8 mesh_min: 50, 50 -mesh_max: 300,300 -probe_count: 3,3 +mesh_max: 300, 300 +probe_count: 3, 3 [heater_bed] heater_pin: PH5 diff --git a/config/printer-creality-ender6-2020.cfg b/config/printer-creality-ender6-2020.cfg index a5791a84..b4048cb7 100644 --- a/config/printer-creality-ender6-2020.cfg +++ b/config/printer-creality-ender6-2020.cfg @@ -75,7 +75,7 @@ position_max: 400 # mesh_min: 10, 10 # mesh_max: 239, 239 # algorithm: bicubic -# probe_count: 5,5 +# probe_count: 5, 5 [extruder] max_extrude_only_distance: 1000.0 diff --git a/config/printer-creality-sermoonD1-2021.cfg b/config/printer-creality-sermoonD1-2021.cfg index 08849814..b06abcf0 100644 --- a/config/printer-creality-sermoonD1-2021.cfg +++ b/config/printer-creality-sermoonD1-2021.cfg @@ -113,7 +113,7 @@ restart_method: command # mesh_min: 20, 15 # mesh_max: 250, 240 # algorithm: bicubic -# probe_count: 5,5 +# probe_count: 5, 5 [filament_switch_sensor filament_sensor] pause_on_runout: true diff --git a/config/printer-eryone-er20-2021.cfg b/config/printer-eryone-er20-2021.cfg index 6acd4dd0..9fc25f52 100644 --- a/config/printer-eryone-er20-2021.cfg +++ b/config/printer-eryone-er20-2021.cfg @@ -141,15 +141,15 @@ z_offset: 2.6 pin_up_touch_mode_reports_triggered: False [safe_z_home] -home_xy_position: 5,5 +home_xy_position: 5, 5 z_hop: 5.0 z_hop_speed: 5.0 [bed_mesh] speed: 80 -mesh_min: 40,20 -mesh_max: 210,205 -probe_count: 5,5 +mesh_min: 40, 20 +mesh_max: 210, 205 +probe_count: 5, 5 ###################################################################### # "RepRapDiscount 128x64 Full Graphic Smart Controller" type display diff --git a/config/printer-fokoos-odin5-f3-2021.cfg b/config/printer-fokoos-odin5-f3-2021.cfg index cdab9c41..fc75d927 100644 --- a/config/printer-fokoos-odin5-f3-2021.cfg +++ b/config/printer-fokoos-odin5-f3-2021.cfg @@ -42,10 +42,10 @@ max_z_velocity: 25 max_z_accel: 100 [bed_screws] -screw1: 33,33 -screw2: 203,33 -screw3: 203,201 -screw4: 33,201 +screw1: 33, 33 +screw2: 203, 33 +screw3: 203, 201 +screw4: 33, 201 [stepper_x] step_pin: PE3 @@ -158,7 +158,7 @@ switch_pin: !PA4 # Optional bed mesh configuration you can use if you have a BLtouch installed. #[bed_mesh] -#mesh_min: 70,15 -#mesh_max: 220,210 +#mesh_min: 70, 15 +#mesh_max: 220, 210 #horizontal_move_z: 5 #speed: 150 diff --git a/config/printer-hiprecy-leo-2019.cfg b/config/printer-hiprecy-leo-2019.cfg index a2a098cc..5651916a 100644 --- a/config/printer-hiprecy-leo-2019.cfg +++ b/config/printer-hiprecy-leo-2019.cfg @@ -93,9 +93,9 @@ speed: 5 ######################################## [bed_mesh] -mesh_min: 40,40 -mesh_max: 185,230 -probe_count: 4,4 +mesh_min: 40, 40 +mesh_max: 185, 230 +probe_count: 4, 4 speed: 100 fade_end: 0.0 algorithm: bicubic diff --git a/config/printer-longer-lk4-pro-2019.cfg b/config/printer-longer-lk4-pro-2019.cfg index 412ece2f..2ef49cfb 100644 --- a/config/printer-longer-lk4-pro-2019.cfg +++ b/config/printer-longer-lk4-pro-2019.cfg @@ -65,9 +65,9 @@ position_max: 250 # z_offset: 1.56 # [bed_mesh] -# mesh_min: 16,16 -# mesh_max: 201,200 -# probe_count: 4,3 +# mesh_min: 16, 16 +# mesh_max: 201, 200 +# probe_count: 4, 3 [extruder] step_pin: PA4 diff --git a/config/printer-lulzbot-mini1-2016.cfg b/config/printer-lulzbot-mini1-2016.cfg index 0e8e7816..b1471dd1 100644 --- a/config/printer-lulzbot-mini1-2016.cfg +++ b/config/printer-lulzbot-mini1-2016.cfg @@ -197,10 +197,10 @@ samples_tolerance_retries: 2 [bed_tilt] # Enable bed tilt measurments using the probe we defined above # Probe points using X0 Y0 offsets @ 0.01mm/step -points: -2,-6 - 156,-6 - 156,158 - -2,158 +points: -2, -6 + 156, -6 + 156, 158 + -2, 158 speed: 75 horizontal_move_z: 2 diff --git a/config/printer-lulzbot-taz6-2017.cfg b/config/printer-lulzbot-taz6-2017.cfg index 93c2bd14..8046381f 100644 --- a/config/printer-lulzbot-taz6-2017.cfg +++ b/config/printer-lulzbot-taz6-2017.cfg @@ -151,15 +151,15 @@ sample_retract_dist: 1.0 samples_tolerance: 0.075 [bed_tilt] -points: -9,-9 - 289.4,-9 - 289.4,290 - -9,289 +points: -9, -9 + 289.4, -9 + 289.4, 290 + -9, 289 speed: 75 horizontal_move_z: 5 [safe_z_home] -home_xy_position: -19.1,259.3 +home_xy_position: -19.1, 259.3 speed: 50.0 z_hop: 10.0 diff --git a/config/printer-lulzbot-taz6-dual-v3-2017.cfg b/config/printer-lulzbot-taz6-dual-v3-2017.cfg index e7a43653..2ec91f9e 100644 --- a/config/printer-lulzbot-taz6-dual-v3-2017.cfg +++ b/config/printer-lulzbot-taz6-dual-v3-2017.cfg @@ -185,10 +185,10 @@ samples_tolerance: 0.100 [bed_tilt] #Enable bed tilt measurments using the probe we defined above #Probe points using X0 Y0 offsets @ 0.01mm/step -points: -3,-6 - 282,-6 - 282,300 - -3,300 +points: -3, -6 + 282, -6 + 282, 300 + -3, 300 speed: 75 horizontal_move_z: 5 @@ -196,7 +196,7 @@ horizontal_move_z: 5 #Needed to lift the Z to clear homing switch on bed # ---> WARNING! - Z_MAX limit switch not monitored in Klipper! <--- # ---> This could potentially crash the toolhead if already at the top of Z travel! <--- -home_xy_position: -19,265 +home_xy_position: -19, 265 speed: 50.0 z_hop: 15.0 move_to_previous: False diff --git a/config/printer-monoprice-select-mini-v2-2018.cfg b/config/printer-monoprice-select-mini-v2-2018.cfg index 3bc86c75..289a931d 100644 --- a/config/printer-monoprice-select-mini-v2-2018.cfg +++ b/config/printer-monoprice-select-mini-v2-2018.cfg @@ -143,10 +143,10 @@ max_z_accel: 20 # Positions for BED_SCREWS_ADJUST levelling with bed screws still accessible [bed_screws] -screw1: 22,10 -screw2: 22,90 -screw3: 98,90 -screw4: 98,10 +screw1: 22, 10 +screw2: 22, 90 +screw3: 98, 90 +screw4: 98, 10 ###################################################################### # Optional: i2c ssd1306 OLED-display controlled by raspi host_mcu diff --git a/config/printer-mtw-create-2015.cfg b/config/printer-mtw-create-2015.cfg index 4194fd23..674d0be9 100644 --- a/config/printer-mtw-create-2015.cfg +++ b/config/printer-mtw-create-2015.cfg @@ -93,13 +93,13 @@ y_offset: 37 z_offset: 2.0 [safe_z_home] -home_xy_position: 125,150 +home_xy_position: 125, 150 z_hop: 10 z_hop_speed: 5 [bed_mesh] -mesh_min: 5,5 -mesh_max: 225,225 +mesh_min: 5, 5 +mesh_max: 225, 225 [fan] pin: PH5 diff --git a/config/printer-prusa-mini-plus-2020.cfg b/config/printer-prusa-mini-plus-2020.cfg index 2893738f..e64a27ba 100644 --- a/config/printer-prusa-mini-plus-2020.cfg +++ b/config/printer-prusa-mini-plus-2020.cfg @@ -158,15 +158,15 @@ z_offset: 0 # set this to your Live Z Offset, but negated (invert the sign) speed: 6.0 [safe_z_home] -home_xy_position: 147.4,21.1 +home_xy_position: 147.4, 21.1 z_hop: 4 [bed_mesh] speed: 100 horizontal_move_z: 5 -mesh_min: 10,10 -mesh_max: 141,167 -probe_count: 4,4 +mesh_min: 10, 10 +mesh_max: 141, 167 +probe_count: 4, 4 [filament_switch_sensor filament_sensor] switch_pin: ^PB4 diff --git a/config/printer-tevo-flash-2018.cfg b/config/printer-tevo-flash-2018.cfg index 210419ae..e6dee68f 100644 --- a/config/printer-tevo-flash-2018.cfg +++ b/config/printer-tevo-flash-2018.cfg @@ -124,7 +124,7 @@ gcode: # Mesh Bed Leveling. [bed_mesh] -mesh_min: 5,18 -mesh_max: 230,228 -probe_count: 9,9 +mesh_min: 5, 18 +mesh_max: 230, 228 +probe_count: 9, 9 algorithm: bicubic diff --git a/config/printer-tronxy-x5sa-pro-2020.cfg b/config/printer-tronxy-x5sa-pro-2020.cfg index b09fffc1..50bf2d1b 100644 --- a/config/printer-tronxy-x5sa-pro-2020.cfg +++ b/config/printer-tronxy-x5sa-pro-2020.cfg @@ -118,26 +118,26 @@ switch_pin: !PA15 pin: PB0 [safe_z_home] -home_xy_position: 165,165 +home_xy_position: 165, 165 speed: 50 z_hop: 10 z_hop_speed: 5 [bed_screws] -screw1: 5,5 -screw2: 165,5 -screw3: 325,5 -screw4: 5,325 -screw5: 165,325 -screw6: 325,325 +screw1: 5, 5 +screw2: 165, 5 +screw3: 325, 5 +screw4: 5, 325 +screw5: 165, 325 +screw6: 325, 325 [bed_mesh] speed: 120 -probe_count: 5,5 +probe_count: 5, 5 horizontal_move_z: 5 algorithm: lagrange -mesh_min : 20,20 -mesh_max : 310,310 +mesh_min : 20, 20 +mesh_max : 310, 310 mesh_pps: 0 [probe] diff --git a/config/printer-tronxy-x5sa-v6-2019.cfg b/config/printer-tronxy-x5sa-v6-2019.cfg index 069f60d6..e61dacc3 100644 --- a/config/printer-tronxy-x5sa-v6-2019.cfg +++ b/config/printer-tronxy-x5sa-v6-2019.cfg @@ -110,26 +110,26 @@ switch_pin: PA15 pin: PB0 [safe_z_home] -home_xy_position: 165,165 +home_xy_position: 165, 165 speed: 50 z_hop: 10 z_hop_speed: 5 [bed_screws] -screw1: 5,5 -screw2: 165,5 -screw3: 325,5 -screw4: 5,325 -screw5: 165,325 -screw6: 325,325 +screw1: 5, 5 +screw2: 165, 5 +screw3: 325, 5 +screw4: 5, 325 +screw5: 165, 325 +screw6: 325, 325 [bed_mesh] speed: 120 -probe_count: 5,5 +probe_count: 5, 5 horizontal_move_z: 5 algorithm: lagrange -mesh_min : 20,20 -mesh_max : 310,310 +mesh_min : 20, 20 +mesh_max : 310, 310 mesh_pps: 0 [probe] diff --git a/config/printer-velleman-k8800-2017.cfg b/config/printer-velleman-k8800-2017.cfg index c1a8abe6..97e96112 100644 --- a/config/printer-velleman-k8800-2017.cfg +++ b/config/printer-velleman-k8800-2017.cfg @@ -92,7 +92,7 @@ z_offset: -15 speed: 120 horizontal_move_z: 5 mesh_radius:65 -mesh_origin: 0,0 +mesh_origin: 0, 0 round_probe_count: 7 algorithm: bicubic diff --git a/config/printer-wanhao-duplicator-9-2018.cfg b/config/printer-wanhao-duplicator-9-2018.cfg index e3f5beeb..958a2d5f 100644 --- a/config/printer-wanhao-duplicator-9-2018.cfg +++ b/config/printer-wanhao-duplicator-9-2018.cfg @@ -91,18 +91,18 @@ square_corner_velocity: 15.0 [bed_mesh] speed: 120 -mesh_min: 27,3 -mesh_max: 270,290 -probe_count: 5,3 +mesh_min: 27, 3 +mesh_max: 270, 290 +probe_count: 5, 3 horizontal_move_z: 10 [bed_screws] -screw1: 5,5 +screw1: 5, 5 screw1_name: front left screw -screw2: 295,0 +screw2: 295, 0 screw2_name: front right screw -screw3: 295,290 +screw3: 295, 290 screw3_name: back right screw -screw4: 0,290 +screw4: 0, 290 screw4_name: back left screw probe_height: 0 diff --git a/config/printer-wanhao-duplicator-i3-plus-mark2-2019.cfg b/config/printer-wanhao-duplicator-i3-plus-mark2-2019.cfg index 5a499bc2..33b808b4 100644 --- a/config/printer-wanhao-duplicator-i3-plus-mark2-2019.cfg +++ b/config/printer-wanhao-duplicator-i3-plus-mark2-2019.cfg @@ -80,6 +80,6 @@ max_z_velocity: 5 max_z_accel: 100 [bed_mesh] -mesh_min: 20,20 -mesh_max: 190,130 -probe_count: 4,4 +mesh_min: 20, 20 +mesh_max: 190, 130 +probe_count: 4, 4 diff --git a/config/sample-probe-as-z-endstop.cfg b/config/sample-probe-as-z-endstop.cfg index 5deb088f..f458a5f3 100644 --- a/config/sample-probe-as-z-endstop.cfg +++ b/config/sample-probe-as-z-endstop.cfg @@ -21,7 +21,7 @@ position_min: -2 # The Z carriage may need to travel below the Z=0 # The safe_z_home section modifies the default G28 behavior [safe_z_home] -home_xy_position: 100,100 +home_xy_position: 100, 100 speed: 50 z_hop: 15 z_hop_speed: 5 @@ -29,18 +29,18 @@ z_hop_speed: 5 # Example bed_tilt config section [bed_tilt] points: - 100,100 - 10,10 - 10,100 - 10,190 - 100,10 - 100,190 - 190,10 - 190,100 - 190,190 + 100, 100 + 10, 10 + 10, 100 + 10, 190 + 100, 10 + 100, 190 + 190, 10 + 190, 100 + 190, 190 # Example bed_mesh config section [bed_mesh] -mesh_min: 20,20 -mesh_max: 200,200 -probe_count: 4,4 +mesh_min: 20, 20 +mesh_max: 200, 200 +probe_count: 4, 4 diff --git a/docs/BLTouch.md b/docs/BLTouch.md index 4445a6a5..9d6a7983 100644 --- a/docs/BLTouch.md +++ b/docs/BLTouch.md @@ -28,7 +28,7 @@ move to the center of the bed, and home the z axis. For example: ``` [safe_z_home] -home_xy_position: 100,100 # Change coordinates to the center of your print bed +home_xy_position: 100, 100 # Change coordinates to the center of your print bed speed: 50 z_hop: 10 # Move up 10mm z_hop_speed: 5 diff --git a/docs/Bed_Mesh.md b/docs/Bed_Mesh.md index 4b70b892..34ac2768 100644 --- a/docs/Bed_Mesh.md +++ b/docs/Bed_Mesh.md @@ -24,9 +24,9 @@ bed and a probe with an x-offset of 24 mm and y-offset of 5 mm. [bed_mesh] speed: 120 horizontal_move_z: 5 -mesh_min: 35,6 +mesh_min: 35, 6 mesh_max: 240, 198 -probe_count: 5,3 +probe_count: 5, 3 ``` - `speed: 120`\ @@ -37,21 +37,21 @@ probe_count: 5,3 _Default Value: 5_\ The Z coordinate the probe rises to prior to traveling between points. -- `mesh_min: 35,6`\ +- `mesh_min: 35, 6`\ _Required_\ The first probed coordinate, nearest to the origin. This coordinate is relative to the probe's location. -- `mesh_max: 240,198`\ +- `mesh_max: 240, 198`\ _Required_\ The probed coordinate farthest farthest from the origin. This is not necessarily the last point probed, as the probing process occurs in a zig-zag fashion. As with `mesh_min`, this coordiante is relative to the probe's location. -- `probe_count: 5,3`\ - _Default Value: 3,3_\ - The number of points to probe on each axis, specified as x,y integer +- `probe_count: 5, 3`\ + _Default Value: 3, 3_\ + The number of points to probe on each axis, specified as X, Y integer values. In this example 5 points will be probed along the X axis, with 3 points along the Y axis, for a total of 15 probed points. Note that if you wanted a square grid, for example 3x3, this could be specified @@ -76,7 +76,7 @@ and 5 mm on Y. speed: 120 horizontal_move_z: 5 mesh_radius: 75 -mesh_origin: 0,0 +mesh_origin: 0, 0 round_probe_count: 5 ``` @@ -86,10 +86,10 @@ round_probe_count: 5 that the probe's offsets limit the size of the mesh radius. In this example, a radius larger than 76 would move the tool beyond the range of the printer. -- `mesh_origin: 0,0`\ - _Default Value: 0,0_\ +- `mesh_origin: 0, 0`\ + _Default Value: 0, 0_\ The center point of the mesh. This coordinate is relative to the probe's - location. While the default is 0,0, it may be useful to adjust the origin + location. While the default is 0, 0, it may be useful to adjust the origin in an effort to probe a larger portion of the bed. See the illustration below. @@ -125,20 +125,20 @@ lagrange and bicubic interpolation to accomplish this. [bed_mesh] speed: 120 horizontal_move_z: 5 -mesh_min: 35,6 +mesh_min: 35, 6 mesh_max: 240, 198 -probe_count: 5,3 -mesh_pps: 2,3 +probe_count: 5, 3 +mesh_pps: 2, 3 algorithm: bicubic bicubic_tension: 0.2 ``` -- `mesh_pps: 2,3`\ - _Default Value: 2,2_\ +- `mesh_pps: 2, 3`\ + _Default Value: 2, 2_\ The `mesh_pps` option is shorthand for Mesh Points Per Segment. This option specifies how many points to interpolate for each segment along - the x and y axes. Consider a 'segment' to be the space between each - probed point. Like `probe_count`, `mesh_pps` is specified as an x,y + the X and Y axes. Consider a 'segment' to be the space between each + probed point. Like `probe_count`, `mesh_pps` is specified as an X, Y integer pair, and also may be specified a single integer that is applied to both axes. In this example there are 4 segments along the X axis and 2 segments along the Y axis. This evaluates to 8 interpolated @@ -179,9 +179,9 @@ control the splitting behavior. [bed_mesh] speed: 120 horizontal_move_z: 5 -mesh_min: 35,6 +mesh_min: 35, 6 mesh_max: 240, 198 -probe_count: 5,3 +probe_count: 5, 3 move_check_distance: 5 split_delta_z: .025 ``` @@ -225,9 +225,9 @@ As such, fade is disabled by default. [bed_mesh] speed: 120 horizontal_move_z: 5 -mesh_min: 35,6 +mesh_min: 35, 6 mesh_max: 240, 198 -probe_count: 5,3 +probe_count: 5, 3 fade_start: 1 fade_end: 10 fade_target: 0 @@ -273,9 +273,9 @@ These printers can benefit from configuring the relative reference index. [bed_mesh] speed: 120 horizontal_move_z: 5 -mesh_min: 35,6 +mesh_min: 35, 6 mesh_max: 240, 198 -probe_count: 5,3 +probe_count: 5, 3 relative_reference_index: 7 ``` @@ -314,9 +314,9 @@ will be averaged and inserted in the mesh as the Z value at the generated [bed_mesh] speed: 120 horizontal_move_z: 5 -mesh_min: 35,6 +mesh_min: 35, 6 mesh_max: 240, 198 -probe_count: 5,3 +probe_count: 5, 3 faulty_region_1_min: 130.0, 0.0 faulty_region_1_max: 145.0, 40.0 faulty_region_2_min: 225.0, 0.0 diff --git a/docs/Command_Templates.md b/docs/Command_Templates.md index 732ed1a1..7d5b229e 100644 --- a/docs/Command_Templates.md +++ b/docs/Command_Templates.md @@ -95,7 +95,7 @@ gcode: G90 G0 Z15 F300 {% for wipe in range(wipe_count) %} - {% for coordinate in [(275,4),(235,4)] %} + {% for coordinate in [(275, 4),(235, 4)] %} G0 X{coordinate[0]} Y{coordinate[1] + 0.25 * wipe} Z9.7 F12000 {% endfor %} {% endfor %} diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index fbd929b6..d344310a 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -462,7 +462,7 @@ Only parameters specific to polar printers are described here - see [common kinematic settings](#common-kinematic-settings) for available parameters. -POLAR KINEMATICS ARE A WORK IN PROGRESS. Moves around the `0,0` +POLAR KINEMATICS ARE A WORK IN PROGRESS. Moves around the 0, 0 position are known to not work properly. ``` @@ -597,7 +597,7 @@ available parameters. CABLE WINCH SUPPORT IS EXPERIMENTAL. Homing is not implemented on cable winch kinematics. In order to home the printer, manually send -movement commands until the toolhead is at 0,0,0 and then issue a +movement commands until the toolhead is at 0, 0, 0 and then issue a `G28` command. ``` @@ -615,7 +615,7 @@ rotation_distance: anchor_x: anchor_y: anchor_z: -# The x, y, and z position of the cable winch in cartesian space. +# The X, Y, and Z position of the cable winch in cartesian space. # These parameters must be provided. ``` @@ -793,7 +793,7 @@ information. Visual Examples: ``` - rectangular bed, probe_count = 3,3: + rectangular bed, probe_count = 3, 3: x---x---x (max_point) | x---x---x @@ -801,15 +801,15 @@ Visual Examples: (min_point) x---x---x round bed, round_probe_count = 5, bed_radius = r: - x (0,r) end - / - x---x---x - \ - (-r,0) x---x---x---x---x (r,0) - \ - x---x---x - / - x (0,-r) start + x (0, r) end + / + x---x---x + \ + (-r, 0) x---x---x---x---x (r, 0) + \ + x---x---x + / + x (0, -r) start ``` ``` @@ -826,26 +826,26 @@ Visual Examples: # mesh_origin option. This parameter must be provided for round beds # and omitted for rectangular beds. #mesh_origin: -# Defines the center x,y coordinate of the mesh for round beds. This +# Defines the center X, Y coordinate of the mesh for round beds. This # coordinate is relative to the probe's location. It may be useful # to adjust the mesh_origin in an effort to maximize the size of the -# mesh radius. Default is 0,0. This parameter must be omitted for +# mesh radius. Default is 0, 0. This parameter must be omitted for # rectangular beds. #mesh_min: -# Defines the minimum x,y coordinate of the mesh for rectangular +# Defines the minimum X, Y coordinate of the mesh for rectangular # beds. This coordinate is relative to the probe's location. This # will be the first point probed, nearest to the origin. This # parameter must be provided for rectangular beds. #mesh_max: -# Defines the maximum x,y coordinate of the mesh for rectangular +# Defines the maximum X, Y coordinate of the mesh for rectangular # beds. Adheres to the same principle as mesh_min, however this will # be the furthest point probed from the bed's origin. This parameter # must be provided for rectangular beds. -#probe_count: 3,3 +#probe_count: 3, 3 # For rectangular beds, this is a comma separate pair of integer -# values (X,Y) defining the number of points to probe along each +# values X, Y defining the number of points to probe along each # axis. A single value is also valid, in which case that value will -# be applied to both axes. Default is 3,3. +# be applied to both axes. Default is 3, 3. #round_probe_count: 5 # For round beds, this integer value defines the maximum number of # points to probe along each axis. This value must be an odd number. @@ -871,12 +871,12 @@ Visual Examples: # The distance (in mm) along a move to check for split_delta_z. # This is also the minimum length that a move can be split. Default # is 5.0. -#mesh_pps: 2,2 -# A comma separated pair of integers (X,Y) defining the number of +#mesh_pps: 2, 2 +# A comma separated pair of integers X, Y defining the number of # points per segment to interpolate in the mesh along each axis. A # "segment" can be defined as the space between each probed point. # The user may enter a single value which will be applied to both -# axes. Default is 2,2. +# axes. Default is 2, 2. #algorithm: lagrange # The interpolation algorithm to use. May be either "lagrange" or # "bicubic". This option will not affect 3x3 grids, which are forced @@ -916,12 +916,12 @@ information. # axis. The default is 0. #z_adjust: 0 # The amount to add to the Z height when the nozzle is nominally at -# 0,0. The default is 0. +# 0, 0. The default is 0. # The remaining parameters control a BED_TILT_CALIBRATE extended # g-code command that may be used to calibrate appropriate x and y # adjustment parameters. #points: -# A list of X,Y coordinates (one per line; subsequent lines +# A list of X, Y coordinates (one per line; subsequent lines # indented) that should be probed during a BED_TILT_CALIBRATE # command. Specify coordinates of the nozzle and be sure the probe # is above the bed at the given nozzle coordinates. The default is @@ -947,7 +947,7 @@ information. ``` [bed_screws] #screw1: -# The X,Y coordinate of the first bed leveling screw. This is a +# The X, Y coordinate of the first bed leveling screw. This is a # position to command the nozzle to that is directly above the bed # screw (or as close as possible while still being above the bed). # This parameter must be provided. @@ -956,7 +956,7 @@ information. # the helper script runs. The default is to use a name based upon # the screw XY location. #screw1_fine_adjust: -# An X,Y coordinate to command the nozzle to so that one can fine +# An X, Y coordinate to command the nozzle to so that one can fine # tune the bed leveling screw. The default is to not perform fine # adjustments on the bed screw. #screw2: @@ -993,7 +993,7 @@ additional information. ``` [screws_tilt_adjust] #screw1: -# The X,Y coordinate of the first bed leveling screw. This is a +# The (X, Y) coordinate of the first bed leveling screw. This is a # position to command the nozzle to that is directly above the bed # screw (or as close as possible while still being above the bed). # This is the base screw used in calculations. This parameter must @@ -1032,15 +1032,15 @@ extended [G-Code command](G-Codes.md#z-tilt) becomes available. ``` [z_tilt] #z_positions: -# A list of X,Y coordinates (one per line; subsequent lines +# A list of X, Y coordinates (one per line; subsequent lines # indented) describing the location of each bed "pivot point". The # "pivot point" is the point where the bed attaches to the given Z -# stepper. It is described using nozzle coordinates (the XY position +# stepper. It is described using nozzle coordinates (the X, Y position # of the nozzle if it could move directly above the point). The # first entry corresponds to stepper_z, the second to stepper_z1, # the third to stepper_z2, etc. This parameter must be provided. #points: -# A list of X,Y coordinates (one per line; subsequent lines +# A list of X, Y coordinates (one per line; subsequent lines # indented) that should be probed during a Z_TILT_ADJUST command. # Specify coordinates of the nozzle and be sure the probe is above # the bed at the given nozzle coordinates. This parameter must be @@ -1082,16 +1082,16 @@ configuration: |Z Z3| ---------------- ``` -Where x is the (0,0) point on the bed +Where x is the 0, 0 point on the bed ``` [quad_gantry_level] #gantry_corners: -# A newline separated list of X,Y coordinates describing the two +# A newline separated list of X, Y coordinates describing the two # opposing corners of the gantry. The first entry corresponds to Z, # the second to Z2. This parameter must be provided. #points: -# A newline separated list of four X,Y points that should be probed +# A newline separated list of four X, Y points that should be probed # during a QUAD_GANTRY_LEVEL command. Order of the locations is # important, and should correspond to Z, Z1, Z2, and Z3 location in # order. This parameter must be provided. For maximum accuracy, @@ -1131,13 +1131,13 @@ the nature of skew correction these lengths are set via gcode. See ### [safe_z_home] Safe Z homing. One may use this mechanism to home the Z axis at a -specific XY coordinate. This is useful if the toolhead, for example +specific X, Y coordinate. This is useful if the toolhead, for example has to move to the center of the bed before Z can be homed. ``` [safe_z_home] home_xy_position: -# A X,Y coordinate (e.g. 100,100) where the Z homing should be +# A X, Y coordinate (e.g. 100, 100) where the Z homing should be # performed. This parameter must be provided. #speed: 50.0 # Speed at which the toolhead is moved to the safe Z home @@ -1153,8 +1153,8 @@ home_xy_position: # Speed (in mm/s) at which the Z axis is lifted prior to homing. The # default is 20mm/s. #move_to_previous: False -# When set to True, xy are reset to their previous positions after z -# homing. The default is False. +# When set to True, the X and Y axes are reset to their previous +# positions after Z axis homing. The default is False. ``` ### [homing_override] @@ -1489,13 +1489,13 @@ cs_pin: #spi_software_miso_pin: # See the "common SPI settings" section for a description of the # above parameters. -#axes_map: x,y,z -# The accelerometer axis for each of the printer's x, y, and z axes. +#axes_map: x, y, z +# The accelerometer axis for each of the printer's X, Y, and Z axes. # This may be useful if the accelerometer is mounted in an # orientation that does not match the printer orientation. For -# example, one could set this to "y,x,z" to swap the x and y axes. +# example, one could set this to "y, x, z" to swap the X and Y axes. # It is also possible to negate an axis if the accelerometer -# direction is reversed (eg, "x,z,-y"). The default is "x,y,z". +# direction is reversed (eg, "x, z, -y"). The default is "x, y, z". #rate: 3200 # Output data rate for ADXL345. ADXL345 supports the following data # rates: 3200, 1600, 800, 400, 200, 100, 50, and 25. Note that it is @@ -1518,7 +1518,7 @@ section of the measuring resonances guide for more information on ``` [resonance_tester] #probe_points: -# A list of X,Y,Z coordinates of points (one point per line) to test +# A list of X, Y, Z coordinates of points (one point per line) to test # resonances at. At least one point is required. Make sure that all # points with some safety margin in XY plane (~a few centimeters) # are reachable by the toolhead. @@ -3891,7 +3891,7 @@ example. ``` # The "replicape" config section adds "replicape:stepper_x_enable" -# virtual stepper enable pins (for steppers x, y, z, e, and h) and +# virtual stepper enable pins (for steppers X, Y, Z, E, and H) and # "replicape:power_x" PWM output pins (for hotbed, e, h, fan0, fan1, # fan2, and fan3) that may then be used elsewhere in the config file. [replicape] diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 12070f1d..b4cb63a3 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -445,7 +445,7 @@ The following commands are available when the available while this tool is active. - `BED_MESH_OUTPUT PGP=[<0:1>]`: This command outputs the current probed z values and current mesh values to the terminal. If PGP=1 is specified - the x,y coordinates generated by bed_mesh, along with their associated + the X, Y coordinates generated by bed_mesh, along with their associated indices, will be output to the terminal. - `BED_MESH_MAP`: Like to BED_MESH_OUTPUT, this command prints the current state of the mesh to the terminal. Instead of printing the values in a diff --git a/docs/Manual_Level.md b/docs/Manual_Level.md index 6a49d499..2b73e8b4 100644 --- a/docs/Manual_Level.md +++ b/docs/Manual_Level.md @@ -63,9 +63,9 @@ This is done by creating a `[bed_screws]` config section. For example, it might look something similar to: ``` [bed_screws] -screw1: 100,50 -screw2: 100,150 -screw3: 150,100 +screw1: 100, 50 +screw2: 100, 150 +screw3: 150, 100 ``` If a bed screw is under the bed, then specify the XY position directly @@ -79,8 +79,8 @@ then one can start the tool by running: BED_SCREWS_ADJUST ``` -This tool will move the printer's nozzle to each screw XY location and -then move the nozzle to a Z=0 height. At this point one can use the +This tool will move the printer's nozzle to each screw XY location +and then move the nozzle to a Z=0 height. At this point one can use the "paper test" to adjust the bed screw directly under the nozzle. See the information described in ["the paper test"](Bed_Level.md#the-paper-test), but adjust the bed @@ -126,12 +126,12 @@ coordinates and add them to the config file. For example, it might look like: ``` [bed_screws] -screw1: 100,50 -screw1_fine_adjust: 0,0 -screw2: 100,150 -screw2_fine_adjust: 300,300 -screw3: 150,100 -screw3_fine_adjust: 0,100 +screw1: 100, 50 +screw1_fine_adjust: 0, 0 +screw2: 100, 150 +screw2_fine_adjust: 300, 300 +screw3: 150, 100 +screw3_fine_adjust: 0, 100 ``` When this feature is enabled, the `BED_SCREWS_ADJUST` tool will first @@ -151,13 +151,13 @@ config file. For example, it might look like: ``` [screws_tilt_adjust] -screw1: -5,30 +screw1: -5, 30 screw1_name: front left screw -screw2: 155,30 +screw2: 155, 30 screw2_name: front right screw -screw3: 155,190 +screw3: 155, 190 screw3_name: rear right screw -screw4: -5,190 +screw4: -5, 190 screw4_name: rear left screw horizontal_move_z: 10. speed: 50. diff --git a/docs/Measuring_Resonances.md b/docs/Measuring_Resonances.md index 32a7413d..f829a082 100644 --- a/docs/Measuring_Resonances.md +++ b/docs/Measuring_Resonances.md @@ -98,7 +98,7 @@ cs_pin: rpi:None [resonance_tester] accel_chip: adxl345 probe_points: - 100,100,20 # an example + 100, 100, 20 # an example ``` It is advised to start with 1 probe point, in the middle of the print bed, slightly above it. diff --git a/docs/Probe_Calibrate.md b/docs/Probe_Calibrate.md index 3531d13c..9bede889 100644 --- a/docs/Probe_Calibrate.md +++ b/docs/Probe_Calibrate.md @@ -1,6 +1,6 @@ # Probe calibration -This document describes the method for calibrating the x, y, and z +This document describes the method for calibrating the X, Y, and Z offsets of an "automatic z probe" in Klipper. This is useful for users that have a `[probe]` or `[bltouch]` section in their config file. diff --git a/docs/Rotation_Distance.md b/docs/Rotation_Distance.md index c2411a8a..142fe250 100644 --- a/docs/Rotation_Distance.md +++ b/docs/Rotation_Distance.md @@ -36,7 +36,7 @@ Most drivers use 16 microsteps. If unsure, set `microsteps: 16` in the config and use 16 in the formula above. Almost all printers should have a whole number for `rotation_distance` -on x, y, and z type axes. If the above formula results in a +on X, Y, and Z type axes. If the above formula results in a rotation_distance that is within .01 of a whole number then round the final value to that whole_number. From 6e6ad7b5201d3452aa605f4ae852c51239c2c7d8 Mon Sep 17 00:00:00 2001 From: maze Date: Mon, 10 Jan 2022 03:44:40 +0100 Subject: [PATCH 017/211] config: Update generic-mellow-super-infinty-hv.cfg (#4876) TMC2130/5160 can make use of `spi3`, which is operated on the software SPI pins in the current configuration. The supplied defaults for software SPI do not currently work. Heater0 pin was marked incorrectly, should be `PB0` Signed-Off-By: Wijnand Modderman-Lenstra --- config/generic-mellow-super-infinty-hv.cfg | 34 ++++++---------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/config/generic-mellow-super-infinty-hv.cfg b/config/generic-mellow-super-infinty-hv.cfg index 28099487..90aa9e08 100644 --- a/config/generic-mellow-super-infinty-hv.cfg +++ b/config/generic-mellow-super-infinty-hv.cfg @@ -53,7 +53,7 @@ microsteps: 16 rotation_distance: 33.500 nozzle_diameter: 0.400 filament_diameter: 1.750 -heater_pin: PC7 # Heat0 +heater_pin: PB0 # Heat0 sensor_pin: PF4 # ADC_0 sensor_type: EPCOS 100K B57560G104F control: pid @@ -240,72 +240,56 @@ max_z_accel: 100 #[tmc5160 stepper_x] #cs_pin: PC4 -#spi_software_miso_pin: PB5 -#spi_software_mosi_pin: PB4 -#spi_software_sclk_pin: PB3 +#spi_bus: spi3 ##diag1_pin: PG12 #run_current: 0.800 #stealthchop_threshold: 999999 #[tmc5160 stepper_y] #cs_pin: PF12 -#spi_software_miso_pin: PB5 -#spi_software_mosi_pin: PB4 -#spi_software_sclk_pin: PB3 +#spi_bus: spi3 ##diag1_pin: PG11 #run_current: 0.800 #stealthchop_threshold: 999999 #[tmc5160 stepper_z] #cs_pin: PF15 -#spi_software_miso_pin: PB5 -#spi_software_mosi_pin: PB4 -#spi_software_sclk_pin: PB3 +#spi_bus: spi3 ##diag1_pin: PG10 #run_current: 0.650 #stealthchop_threshold: 999999 #[tmc5160 extruder] #cs_pin: PE7 -#spi_software_miso_pin: PB5 -#spi_software_mosi_pin: PB4 -#spi_software_sclk_pin: PB3 +#spi_bus: spi3 ##diag1_pin: PG9 #run_current: 0.800 #stealthchop_threshold: 999999 #[tmc5160 extruder1] #cs_pin: PE10 -#spi_software_miso_pin: PB5 -#spi_software_mosi_pin: PB4 -#spi_software_sclk_pin: PB3 +#spi_bus: spi3 ##diag1_pin: PD7 #run_current: 0.800 #stealthchop_threshold: 999999 #[tmc5160 extruder2] #cs_pin: PF1 -#spi_software_miso_pin: PB5 -#spi_software_mosi_pin: PB4 -#spi_software_sclk_pin: PB3 +#spi_bus: spi3 ##diag1_pin: PD6 #run_current: 0.800 #stealthchop_threshold: 999999 #[tmc5160 extruder3] #cs_pin: PG2 -#spi_software_miso_pin: PB5 -#spi_software_mosi_pin: PB4 -#spi_software_sclk_pin: PB3 +#spi_bus: spi3 ##diag1_pin: PA8 #run_current: 0.800 #stealthchop_threshold: 999999 #[tmc5160 extruder4] #cs_pin: PG5 -#spi_software_miso_pin: PB5 -#spi_software_mosi_pin: PB4 -#spi_software_sclk_pin: PB3 +#spi_bus: spi3 ##diag1_pin: PF3 #run_current: 0.800 #stealthchop_threshold: 999999 From 090fcf928fcbd36fa6e4e90fd6c52967ad5d420d Mon Sep 17 00:00:00 2001 From: Lasse Dalegaard Date: Sun, 12 Dec 2021 12:13:13 +0100 Subject: [PATCH 018/211] rp2040: implement I2C This implements I2C for the rp2040 target. All output groupings of both I2C blocks are available for use. Signed-off-by: Lasse Dalegaard --- src/rp2040/Kconfig | 1 + src/rp2040/Makefile | 1 + src/rp2040/gpio.h | 10 +++ src/rp2040/i2c.c | 215 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 227 insertions(+) create mode 100644 src/rp2040/i2c.c diff --git a/src/rp2040/Kconfig b/src/rp2040/Kconfig index b509bc04..c2a45e55 100644 --- a/src/rp2040/Kconfig +++ b/src/rp2040/Kconfig @@ -8,6 +8,7 @@ config RP2040_SELECT select HAVE_GPIO select HAVE_GPIO_ADC select HAVE_GPIO_SPI + select HAVE_GPIO_I2C select HAVE_GPIO_BITBANGING select HAVE_STRICT_TIMING select HAVE_CHIPID diff --git a/src/rp2040/Makefile b/src/rp2040/Makefile index 2915b994..fbeccb97 100644 --- a/src/rp2040/Makefile +++ b/src/rp2040/Makefile @@ -21,6 +21,7 @@ src-$(CONFIG_USBSERIAL) += rp2040/chipid.c src-$(CONFIG_SERIAL) += rp2040/serial.c generic/serial_irq.c src-$(CONFIG_HAVE_GPIO_HARD_PWM) += rp2040/hard_pwm.c src-$(CONFIG_HAVE_GPIO_SPI) += rp2040/spi.c +src-$(CONFIG_HAVE_GPIO_I2C) += rp2040/i2c.c # rp2040 stage2 building $(OUT)stage2.o: lib/rp2040/boot_stage2/boot2_w25q080.S diff --git a/src/rp2040/gpio.h b/src/rp2040/gpio.h index 90680c6e..ae608378 100644 --- a/src/rp2040/gpio.h +++ b/src/rp2040/gpio.h @@ -44,4 +44,14 @@ void spi_prepare(struct spi_config config); void spi_transfer(struct spi_config config, uint8_t receive_data , uint8_t len, uint8_t *data); +struct i2c_config { + void *i2c; + uint8_t addr; +}; + +struct i2c_config i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr); +void i2c_write(struct i2c_config config, uint8_t write_len, uint8_t *write); +void i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg + , uint8_t read_len, uint8_t *read); + #endif // gpio.h diff --git a/src/rp2040/i2c.c b/src/rp2040/i2c.c new file mode 100644 index 00000000..954de0e5 --- /dev/null +++ b/src/rp2040/i2c.c @@ -0,0 +1,215 @@ +// I2C functions for rp2040 +// +// Copyright (C) 2022 Lasse Dalegaard +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include "board/misc.h" // timer_is_before +#include "gpio.h" // i2c_setup, i2c_read, i2c_write +#include "command.h" // shutdown +#include "sched.h" // sched_shutdown +#include "internal.h" // pclock, gpio_peripheral +#include "hardware/regs/resets.h" // RESETS_RESET_I2C*_BITS +#include "hardware/structs/i2c.h" + +struct i2c_info { + i2c_hw_t *i2c; + uint8_t sda_pin, scl_pin, pclk; +}; + +DECL_ENUMERATION("i2c_bus", "i2c0a", 0); +DECL_ENUMERATION("i2c_bus", "i2c0b", 1); +DECL_ENUMERATION("i2c_bus", "i2c0c", 2); +DECL_ENUMERATION("i2c_bus", "i2c0d", 3); +DECL_ENUMERATION("i2c_bus", "i2c0e", 4); +DECL_ENUMERATION("i2c_bus", "i2c0f", 5); +DECL_ENUMERATION("i2c_bus", "i2c0g", 6); +DECL_ENUMERATION("i2c_bus", "i2c0h", 7); +DECL_ENUMERATION("i2c_bus", "i2c1a", 8); +DECL_ENUMERATION("i2c_bus", "i2c1b", 9); +DECL_ENUMERATION("i2c_bus", "i2c1c", 10); +DECL_ENUMERATION("i2c_bus", "i2c1d", 11); +DECL_ENUMERATION("i2c_bus", "i2c1e", 12); +DECL_ENUMERATION("i2c_bus", "i2c1f", 13); +DECL_ENUMERATION("i2c_bus", "i2c1g", 14); +DECL_CONSTANT_STR("BUS_PINS_i2c0a", "gpio0,gpio1"); +DECL_CONSTANT_STR("BUS_PINS_i2c0b", "gpio4,gpio5"); +DECL_CONSTANT_STR("BUS_PINS_i2c0c", "gpio8,gpio9"); +DECL_CONSTANT_STR("BUS_PINS_i2c0d", "gpio12,gpio13"); +DECL_CONSTANT_STR("BUS_PINS_i2c0e", "gpio16,gpio17"); +DECL_CONSTANT_STR("BUS_PINS_i2c0f", "gpio20,gpio21"); +DECL_CONSTANT_STR("BUS_PINS_i2c0g", "gpio24,gpio25"); +DECL_CONSTANT_STR("BUS_PINS_i2c0h", "gpio28,gpio29"); +DECL_CONSTANT_STR("BUS_PINS_i2c1a", "gpio2,gpio3"); +DECL_CONSTANT_STR("BUS_PINS_i2c1b", "gpio6,gpio7"); +DECL_CONSTANT_STR("BUS_PINS_i2c1c", "gpio10,gpio11"); +DECL_CONSTANT_STR("BUS_PINS_i2c1d", "gpio14,gpio15"); +DECL_CONSTANT_STR("BUS_PINS_i2c1e", "gpio18,gpio19"); +DECL_CONSTANT_STR("BUS_PINS_i2c1f", "gpio22,gpio23"); +DECL_CONSTANT_STR("BUS_PINS_i2c1g", "gpio26,gpio27"); + +static const struct i2c_info i2c_bus[] = { + { i2c0_hw, 0, 1, RESETS_RESET_I2C0_BITS }, + { i2c0_hw, 4, 5, RESETS_RESET_I2C0_BITS }, + { i2c0_hw, 8, 9, RESETS_RESET_I2C0_BITS }, + { i2c0_hw, 12, 13, RESETS_RESET_I2C0_BITS }, + { i2c0_hw, 16, 17, RESETS_RESET_I2C0_BITS }, + { i2c0_hw, 20, 21, RESETS_RESET_I2C0_BITS }, + { i2c0_hw, 24, 25, RESETS_RESET_I2C0_BITS }, + { i2c0_hw, 28, 29, RESETS_RESET_I2C0_BITS }, + + { i2c1_hw, 2, 3, RESETS_RESET_I2C1_BITS }, + { i2c1_hw, 6, 7, RESETS_RESET_I2C1_BITS }, + { i2c1_hw, 10, 11, RESETS_RESET_I2C1_BITS }, + { i2c1_hw, 14, 15, RESETS_RESET_I2C1_BITS }, + { i2c1_hw, 18, 19, RESETS_RESET_I2C1_BITS }, + { i2c1_hw, 22, 23, RESETS_RESET_I2C1_BITS }, + { i2c1_hw, 26, 27, RESETS_RESET_I2C1_BITS }, +}; + +struct i2c_config +i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr) +{ + if (bus > ARRAY_SIZE(i2c_bus)) + shutdown("Invalid i2c bus"); + + const struct i2c_info *info = &i2c_bus[bus]; + + gpio_peripheral(info->sda_pin, 3, 0); + gpio_peripheral(info->scl_pin, 3, 0); + + if (!is_enabled_pclock(info->pclk)) { + enable_pclock(info->pclk); + + i2c_hw_t *i2c = info->i2c; + + i2c->enable = 0; + + // We set up the bus in 400 kHz mode, but then set timings afterwards + // to match either 100k or 400k mode. This simplifies the setup. + + i2c->con = I2C_IC_CON_SPEED_VALUE_FAST << I2C_IC_CON_SPEED_LSB + | I2C_IC_CON_MASTER_MODE_BITS + | I2C_IC_CON_IC_SLAVE_DISABLE_BITS + | I2C_IC_CON_IC_RESTART_EN_BITS; + + i2c->tx_tl = 0; + i2c->rx_tl = 0; + + uint32_t pclk = get_pclock_frequency(info->pclk); + + // See `i2c_set_baudrate` in the Pico SDK `hardware_i2c/i2c.c` file + // for details on the calculations here. + if (rate > 1000000) + rate = 1000000; // Clamp the rate to 1Mbps + uint32_t period = (pclk + rate / 2) / rate; + uint32_t lcnt = period * 3 / 5; + uint32_t hcnt = period - lcnt; + uint32_t sda_tx_hold_count = ((pclk * 3) / 10000000) + 1; + + i2c->fs_scl_hcnt = hcnt; + i2c->fs_scl_lcnt = lcnt; + i2c->fs_spklen = lcnt < 16 ? 1 : lcnt / 16; + hw_write_masked(&i2c->sda_hold, + sda_tx_hold_count << I2C_IC_SDA_HOLD_IC_SDA_TX_HOLD_LSB, + I2C_IC_SDA_HOLD_IC_SDA_TX_HOLD_BITS); + } + + return (struct i2c_config){ .i2c=info->i2c, .addr=addr }; +} + +static void +i2c_start(i2c_hw_t *i2c, uint8_t addr) +{ + i2c->enable = 0; + i2c->tar = addr; + i2c->enable = 1; +} + +static void +i2c_stop(i2c_hw_t *i2c) +{ + i2c->enable = 0; +} + +static void +i2c_do_write(i2c_hw_t *i2c, uint8_t addr, uint8_t write_len, uint8_t *write + , uint8_t send_stop, uint32_t timeout) +{ + for (int i = 0; i < write_len; i++) { + int first = i == 0; + int last = send_stop && (i == write_len - 1); + + // Wait until there's a spot in the TX FIFO + while (i2c->txflr == 16) { + if (!timer_is_before(timer_read_time(), timeout)) + shutdown("i2c timeout"); + } + + i2c->data_cmd = first << I2C_IC_DATA_CMD_RESTART_LSB + | last << I2C_IC_DATA_CMD_STOP_LSB + | write[i]; + } + + if (!send_stop) + return; + + // Drain the transmit buffer + while (i2c->txflr != 0) { + if (!timer_is_before(timer_read_time(), timeout)) + shutdown("i2c timeout"); + } +} + +static void +i2c_do_read(i2c_hw_t *i2c, uint8_t addr, uint8_t read_len, uint8_t *read + , uint32_t timeout) +{ + int have_read = 0; + int to_send = read_len; + while (have_read < read_len) { + if (!timer_is_before(timer_read_time(), timeout)) + shutdown("i2c timeout"); + + if (to_send > 0 && i2c->txflr < 16) { + int first = to_send == read_len; + int last = to_send == 1; + + // Put a read command in the TX FIFO + i2c->data_cmd = first << I2C_IC_DATA_CMD_RESTART_LSB + | last << I2C_IC_DATA_CMD_STOP_LSB + | I2C_IC_DATA_CMD_CMD_BITS; + to_send--; + } + + if (have_read < read_len && i2c->rxflr > 0) { + *read++ = i2c->data_cmd & 0xFF; + have_read++; + } + } +} + +void +i2c_write(struct i2c_config config, uint8_t write_len, uint8_t *write) +{ + i2c_hw_t *i2c = (i2c_hw_t*)config.i2c; + uint32_t timeout = timer_read_time() + timer_from_us(5000); + + i2c_start(i2c, config.addr); + i2c_do_write(i2c, config.addr, write_len, write, 1, timeout); + i2c_stop(i2c); +} + +void +i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg + , uint8_t read_len, uint8_t *read) +{ + i2c_hw_t *i2c = (i2c_hw_t*)config.i2c; + uint32_t timeout = timer_read_time() + timer_from_us(5000); + + i2c_start(i2c, config.addr); + if (reg_len != 0) + i2c_do_write(i2c, config.addr, reg_len, reg, 0, timeout); + i2c_do_read(i2c, config.addr, read_len, read, timeout); + i2c_stop(i2c); +} From babb067b60e5a0b29fa8657faf01a709483b33b1 Mon Sep 17 00:00:00 2001 From: Tim Abraham Date: Wed, 12 Jan 2022 12:18:08 -0500 Subject: [PATCH 019/211] neopixel: Update neopixel.py to add BRG color order (#5110) Add BRG color option. Document BRG color option. Signed-off-by: Timothy Abraham --- docs/Config_Reference.md | 2 +- klippy/extras/neopixel.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index d344310a..4c78b550 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -2560,7 +2560,7 @@ pin: # Neopixel is connected to the pin). #color_order: GRB # Set the pixel order required by the LED hardware. Options are GRB, -# RGB, GRBW, or RGBW. The default is GRB. +# RGB, BRG, GRBW, or RGBW. The default is GRB. #initial_RED: 0.0 #initial_GREEN: 0.0 #initial_BLUE: 0.0 diff --git a/klippy/extras/neopixel.py b/klippy/extras/neopixel.py index 481f8825..2c79b327 100644 --- a/klippy/extras/neopixel.py +++ b/klippy/extras/neopixel.py @@ -24,7 +24,7 @@ class PrinterNeoPixel: self.oid = self.mcu.create_oid() self.pin = pin_params['pin'] self.mcu.register_config_callback(self.build_config) - formats = {v: v for v in ["RGB", "GRB", "RGBW", "GRBW"]} + formats = {v: v for v in ["RGB", "GRB", "BRG", "RGBW", "GRBW"]} self.color_order = config.getchoice("color_order", formats, "GRB") elem_size = len(self.color_order) self.chain_count = config.getint('chain_count', 1, minval=1, @@ -67,6 +67,8 @@ class PrinterNeoPixel: color_data = [green, red, blue] elif self.color_order == "RGB": color_data = [red, green, blue] + elif self.color_order == "BRG": + color_data = [blue, red, green] elif self.color_order == "GRBW": color_data = [green, red, blue, white] else: From 538f09a2dadeb02afbf9516de900df37a80ae154 Mon Sep 17 00:00:00 2001 From: individ-divided <75159519+individ-divided@users.noreply.github.com> Date: Sun, 16 Jan 2022 19:00:24 +0100 Subject: [PATCH 020/211] pause_resume: Do not clobber default state name by accident (#5156) Previously accidentally used 'default' state name instead of the stated one ('PAUSE_STATE'). This might collide with user usage of the SAVE_GCODE_STATE macro. Signed-off-by: David Grundberg --- klippy/extras/pause_resume.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/klippy/extras/pause_resume.py b/klippy/extras/pause_resume.py index 4d9684f2..1f6b9752 100644 --- a/klippy/extras/pause_resume.py +++ b/klippy/extras/pause_resume.py @@ -63,7 +63,7 @@ class PauseResume: gcmd.respond_info("Print already paused") return self.send_pause_command() - self.gcode.run_script_from_command("SAVE_GCODE_STATE STATE=PAUSE_STATE") + self.gcode.run_script_from_command("SAVE_GCODE_STATE NAME=PAUSE_STATE") self.is_paused = True def send_resume_command(self): if self.sd_paused: @@ -80,7 +80,7 @@ class PauseResume: return velocity = gcmd.get_float('VELOCITY', self.recover_velocity) self.gcode.run_script_from_command( - "RESTORE_GCODE_STATE STATE=PAUSE_STATE MOVE=1 MOVE_SPEED=%.4f" + "RESTORE_GCODE_STATE NAME=PAUSE_STATE MOVE=1 MOVE_SPEED=%.4f" % (velocity)) self.send_resume_command() self.is_paused = False From 89b4fecac4a436701f264de04c0898255241d111 Mon Sep 17 00:00:00 2001 From: Filip Trplan Date: Sun, 16 Jan 2022 20:22:44 +0100 Subject: [PATCH 021/211] config: Correct Pin for the CR-6 SE 2021 Example Config (#5142) The fan pin PA0 is not correct for the 2021 revision of the CR-6 SE using the 4.5.3 revision of the Creality board. Changed the pin to PB15 in order to get it working Signed-off-by: Filip Trplan --- config/printer-creality-cr6se-2021.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/printer-creality-cr6se-2021.cfg b/config/printer-creality-cr6se-2021.cfg index 5c994645..12c17120 100644 --- a/config/printer-creality-cr6se-2021.cfg +++ b/config/printer-creality-cr6se-2021.cfg @@ -80,7 +80,7 @@ min_temp: 0 max_temp: 120 [fan] -pin: PA0 +pin: PB15 kick_start_time: 0.5 [mcu] From 34a1ce483737832fea5651f7c2d2fc9838c19414 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 12 Jan 2022 23:43:11 -0500 Subject: [PATCH 022/211] tmc2130: Rework current selection to prefer vsense=1 It is preferable to program the tmc drivers with an irun (or cs) setting near 31, as otherwise the driver may have reduced microstep precision. It was possible for the driver to be programmed with irun=16 or irun=17 when it could have been configured with irun=31 with vsense=1 instead. This would occur on tmc2130/tmc2208/tmc2209 drivers for values around 0.900 to 1.000 amps (when using a typical sense_resistor settings of 0.110 Ohms). Change the code to prefer using vsense=1 to avoid this issue. Signed-off-by: Kevin O'Connor --- docs/Config_Changes.md | 6 ++++++ klippy/extras/tmc2130.py | 41 +++++++++++++++++++++------------------- klippy/extras/tmc2660.py | 25 ++++++++++++++++-------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md index e9bcd120..ead2445c 100644 --- a/docs/Config_Changes.md +++ b/docs/Config_Changes.md @@ -8,6 +8,12 @@ All dates in this document are approximate. ## Changes +20220116: The tmc2130, tmc2208, tmc2209, and tmc2660 `run_current` +calculation code has changed. For some `run_current` settings the +drivers may now be configured differently. This new configuration +should be more accurate, but it may invalidate previous tmc driver +tuning. + 20211230: Scripts to tune input shaper (`scripts/calibrate_shaper.py` and `scripts/graph_accelerometer.py`) were migrated to use Python3 by default. As a result, users must install Python3 versions of certain diff --git a/klippy/extras/tmc2130.py b/klippy/extras/tmc2130.py index c6a54561..f2142d26 100644 --- a/klippy/extras/tmc2130.py +++ b/klippy/extras/tmc2130.py @@ -116,30 +116,33 @@ class TMCCurrentHelper: vref = 0.32 if vsense: vref = 0.18 - cs = int(32. * current * sense_resistor * math.sqrt(2.) / vref - - 1. + .5) + cs = int(32. * sense_resistor * current * math.sqrt(2.) / vref + .5) - 1 return max(0, min(31, cs)) - def _calc_current(self, run_current, hold_current): - vsense = False - irun = self._calc_current_bits(run_current, vsense) - ihold = self._calc_current_bits(min(hold_current, run_current), - vsense) - if irun < 16 and ihold < 16: - vsense = True - irun = self._calc_current_bits(run_current, vsense) - ihold = self._calc_current_bits(min(hold_current, run_current), - vsense) - return vsense, irun, ihold - def _calc_current_from_field(self, field_name): - bits = self.fields.get_field(field_name) + def _calc_current_from_bits(self, cs, vsense): sense_resistor = self.sense_resistor + 0.020 vref = 0.32 - if self.fields.get_field("vsense"): + if vsense: vref = 0.18 - return (bits + 1) * vref / (32 * sense_resistor * math.sqrt(2.)) + return (cs + 1) * vref / (32. * sense_resistor * math.sqrt(2.)) + def _calc_current(self, run_current, hold_current): + vsense = True + irun = self._calc_current_bits(run_current, True) + if irun == 31: + cur = self._calc_current_from_bits(irun, True) + if cur < run_current: + irun2 = self._calc_current_bits(run_current, False) + cur2 = self._calc_current_from_bits(irun2, False) + if abs(run_current - cur2) < abs(run_current - cur): + vsense = False + irun = irun2 + ihold = self._calc_current_bits(min(hold_current, run_current), vsense) + return vsense, irun, ihold def get_current(self): - run_current = self._calc_current_from_field("irun") - hold_current = self._calc_current_from_field("ihold") + irun = self.fields.get_field("irun") + ihold = self.fields.get_field("ihold") + vsense = self.fields.get_field("vsense") + run_current = self._calc_current_from_bits(irun, vsense) + hold_current = self._calc_current_from_bits(ihold, vsense) return run_current, hold_current, self.req_hold_current, MAX_CURRENT def set_current(self, run_current, hold_current, print_time): self.req_hold_current = hold_current diff --git a/klippy/extras/tmc2660.py b/klippy/extras/tmc2660.py index c0d8fa9b..e873c608 100644 --- a/klippy/extras/tmc2660.py +++ b/klippy/extras/tmc2660.py @@ -136,17 +136,26 @@ class TMC2660CurrentHelper: def _calc_current_bits(self, current, vsense): vref = 0.165 if vsense else 0.310 - cs = int(32 * current * self.sense_resistor * math.sqrt(2.) / vref - - 1. + .5) + sr = self.sense_resistor + cs = int(32. * sr * current * math.sqrt(2.) / vref + .5) - 1 return max(0, min(31, cs)) + def _calc_current_from_bits(self, cs, vsense): + vref = 0.165 if vsense else 0.310 + return (cs + 1) * vref / (32. * self.sense_resistor * math.sqrt(2.)) + def _calc_current(self, run_current): - vsense = False - cs = self._calc_current_bits(run_current, vsense) - if cs < 16: - vsense = True - cs = self._calc_current_bits(run_current, vsense) - return vsense, cs + vsense = True + irun = self._calc_current_bits(run_current, True) + if irun == 31: + cur = self._calc_current_from_bits(irun, True) + if cur < run_current: + irun2 = self._calc_current_bits(run_current, False) + cur2 = self._calc_current_from_bits(irun2, False) + if abs(run_current - cur2) < abs(run_current - cur): + vsense = False + irun = irun2 + return vsense, irun def _handle_printing(self, print_time): print_time -= 0.100 # Schedule slightly before deadline From 29724a7411063879d3343a0610b4f288e045cabf Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 11 Jan 2022 13:21:07 -0500 Subject: [PATCH 023/211] extruder: Don't store pressure_advance value in trapq moves Store the pressure_advance value in "struct extruder_stepper" instead of in the trapq's "struct move". This makes it possible for multiple stepper motors to have different pressure advance values while still using the same trapq. Signed-off-by: Kevin O'Connor --- klippy/chelper/__init__.py | 4 ++-- klippy/chelper/kin_extruder.c | 28 +++++++++++++++++----------- klippy/kinematics/extruder.py | 13 +++++++------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py index 66d701d3..e04d431d 100644 --- a/klippy/chelper/__init__.py +++ b/klippy/chelper/__init__.py @@ -133,8 +133,8 @@ defs_kin_winch = """ defs_kin_extruder = """ struct stepper_kinematics *extruder_stepper_alloc(void); - void extruder_set_smooth_time(struct stepper_kinematics *sk - , double smooth_time); + void extruder_set_pressure_advance(struct stepper_kinematics *sk + , double pressure_advance, double smooth_time); """ defs_kin_shaper = """ diff --git a/klippy/chelper/kin_extruder.c b/klippy/chelper/kin_extruder.c index 63dca909..b8d1cc22 100644 --- a/klippy/chelper/kin_extruder.c +++ b/klippy/chelper/kin_extruder.c @@ -52,15 +52,17 @@ extruder_integrate_time(double base, double start_v, double half_accel // Calculate the definitive integral of extruder for a given move static double -pa_move_integrate(struct move *m, double base, double start, double end, - double time_offset) +pa_move_integrate(struct move *m, double pressure_advance + , double base, double start, double end, double time_offset) { if (start < 0.) start = 0.; if (end > m->move_t) end = m->move_t; // Calculate base position and velocity with pressure advance - double pressure_advance = m->axes_r.y; + int can_pressure_advance = m->axes_r.y != 0.; + if (!can_pressure_advance) + pressure_advance = 0.; base += pressure_advance * m->start_v; double start_v = m->start_v + pressure_advance * 2. * m->half_accel; // Calculate definitive integral @@ -72,34 +74,36 @@ pa_move_integrate(struct move *m, double base, double start, double end, // Calculate the definitive integral of the extruder over a range of moves static double -pa_range_integrate(struct move *m, double move_time, double hst) +pa_range_integrate(struct move *m, double move_time + , double pressure_advance, double hst) { // Calculate integral for the current move double res = 0., start = move_time - hst, end = move_time + hst; double start_base = m->start_pos.x; - res += pa_move_integrate(m, 0., start, move_time, start); - res -= pa_move_integrate(m, 0., move_time, end, end); + res += pa_move_integrate(m, pressure_advance, 0., start, move_time, start); + res -= pa_move_integrate(m, pressure_advance, 0., move_time, end, end); // Integrate over previous moves struct move *prev = m; while (unlikely(start < 0.)) { prev = list_prev_entry(prev, node); start += prev->move_t; double base = prev->start_pos.x - start_base; - res += pa_move_integrate(prev, base, start, prev->move_t, start); + res += pa_move_integrate(prev, pressure_advance, base, start + , prev->move_t, start); } // Integrate over future moves while (unlikely(end > m->move_t)) { end -= m->move_t; m = list_next_entry(m, node); double base = m->start_pos.x - start_base; - res -= pa_move_integrate(m, base, 0., end, end); + res -= pa_move_integrate(m, pressure_advance, base, 0., end, end); } return res; } struct extruder_stepper { struct stepper_kinematics sk; - double half_smooth_time, inv_half_smooth_time2; + double pressure_advance, half_smooth_time, inv_half_smooth_time2; }; static double @@ -112,12 +116,13 @@ extruder_calc_position(struct stepper_kinematics *sk, struct move *m // Pressure advance not enabled return m->start_pos.x + move_get_distance(m, move_time); // Apply pressure advance and average over smooth_time - double area = pa_range_integrate(m, move_time, hst); + double area = pa_range_integrate(m, move_time, es->pressure_advance, hst); return m->start_pos.x + area * es->inv_half_smooth_time2; } void __visible -extruder_set_smooth_time(struct stepper_kinematics *sk, double smooth_time) +extruder_set_pressure_advance(struct stepper_kinematics *sk + , double pressure_advance, double smooth_time) { struct extruder_stepper *es = container_of(sk, struct extruder_stepper, sk); double hst = smooth_time * .5; @@ -126,6 +131,7 @@ extruder_set_smooth_time(struct stepper_kinematics *sk, double smooth_time) if (! hst) return; es->inv_half_smooth_time2 = 1. / (hst * hst); + es->pressure_advance = pressure_advance; } struct stepper_kinematics * __visible diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index 76ca7b2e..852f576f 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -54,7 +54,6 @@ class PrinterExtruder: self.stepper.set_stepper_kinematics(self.sk_extruder) self.stepper.set_trapq(self.trapq) toolhead.register_step_generator(self.stepper.generate_steps) - self.extruder_set_smooth_time = ffi_lib.extruder_set_smooth_time self._set_pressure_advance(pressure_advance, smooth_time) # Register commands gcode = self.printer.lookup_object('gcode') @@ -86,7 +85,9 @@ class PrinterExtruder: toolhead = self.printer.lookup_object("toolhead") toolhead.note_step_generation_scan_time(new_smooth_time * .5, old_delay=old_smooth_time * .5) - self.extruder_set_smooth_time(self.sk_extruder, new_smooth_time) + ffi_main, ffi_lib = chelper.get_ffi() + espa = ffi_lib.extruder_set_pressure_advance + espa(self.sk_extruder, pressure_advance, new_smooth_time) self.pressure_advance = pressure_advance self.pressure_advance_smooth_time = smooth_time def get_status(self, eventtime): @@ -145,14 +146,14 @@ class PrinterExtruder: accel = move.accel * axis_r start_v = move.start_v * axis_r cruise_v = move.cruise_v * axis_r - pressure_advance = 0. + can_pressure_advance = False if axis_r > 0. and (move.axes_d[0] or move.axes_d[1]): - pressure_advance = self.pressure_advance - # Queue movement (x is extruder movement, y is pressure advance) + can_pressure_advance = True + # Queue movement (x is extruder movement, y is pressure advance flag) self.trapq_append(self.trapq, print_time, move.accel_t, move.cruise_t, move.decel_t, move.start_pos[3], 0., 0., - 1., pressure_advance, 0., + 1., can_pressure_advance, 0., start_v, cruise_v, accel) def find_past_position(self, print_time): mcu_pos = self.stepper.get_past_mcu_position(print_time) From ffbd2698fe906dbfc4b21923989b9679adf8561b Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 11 Jan 2022 14:21:57 -0500 Subject: [PATCH 024/211] extruder: Separate extruder stepper tracking to new ExtruderStepper class Move the stepper handling (including pressure advance handling) to a new class. Signed-off-by: Kevin O'Connor --- klippy/kinematics/extruder.py | 172 +++++++++++++++++++--------------- 1 file changed, 97 insertions(+), 75 deletions(-) diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index 852f576f..c042a2dd 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -1,15 +1,94 @@ # Code for handling printer nozzle extruders # -# Copyright (C) 2016-2019 Kevin O'Connor +# Copyright (C) 2016-2022 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. import math, logging import stepper, chelper +class ExtruderStepper: + def __init__(self, config): + self.printer = config.get_printer() + self.name = config.get_name() + self.pressure_advance = self.pressure_advance_smooth_time = 0. + # Setup stepper + self.stepper = stepper.PrinterStepper(config) + ffi_main, ffi_lib = chelper.get_ffi() + self.sk_extruder = ffi_main.gc(ffi_lib.extruder_stepper_alloc(), + ffi_lib.free) + self.stepper.set_stepper_kinematics(self.sk_extruder) + toolhead = self.printer.lookup_object('toolhead') + toolhead.register_step_generator(self.stepper.generate_steps) + # Register commands + gcode = self.printer.lookup_object('gcode') + if self.name == 'extruder': + gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None, + self.cmd_default_SET_PRESSURE_ADVANCE, + desc=self.cmd_SET_PRESSURE_ADVANCE_help) + gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", + self.name, self.cmd_SET_PRESSURE_ADVANCE, + desc=self.cmd_SET_PRESSURE_ADVANCE_help) + gcode.register_mux_command("SET_EXTRUDER_STEP_DISTANCE", "EXTRUDER", + self.name, self.cmd_SET_E_STEP_DISTANCE, + desc=self.cmd_SET_E_STEP_DISTANCE_help) + def get_status(self, eventtime): + return {'pressure_advance': self.pressure_advance, + 'smooth_time': self.pressure_advance_smooth_time} + def find_past_position(self, print_time): + mcu_pos = self.stepper.get_past_mcu_position(print_time) + return self.stepper.mcu_to_commanded_position(mcu_pos) + def _set_pressure_advance(self, pressure_advance, smooth_time): + old_smooth_time = self.pressure_advance_smooth_time + if not self.pressure_advance: + old_smooth_time = 0. + new_smooth_time = smooth_time + if not pressure_advance: + new_smooth_time = 0. + toolhead = self.printer.lookup_object("toolhead") + toolhead.note_step_generation_scan_time(new_smooth_time * .5, + old_delay=old_smooth_time * .5) + ffi_main, ffi_lib = chelper.get_ffi() + espa = ffi_lib.extruder_set_pressure_advance + espa(self.sk_extruder, pressure_advance, new_smooth_time) + self.pressure_advance = pressure_advance + self.pressure_advance_smooth_time = smooth_time + cmd_SET_PRESSURE_ADVANCE_help = "Set pressure advance parameters" + def cmd_default_SET_PRESSURE_ADVANCE(self, gcmd): + extruder = self.printer.lookup_object('toolhead').get_extruder() + extruder.extruder_stepper.cmd_SET_PRESSURE_ADVANCE(gcmd) + def cmd_SET_PRESSURE_ADVANCE(self, gcmd): + pressure_advance = gcmd.get_float('ADVANCE', self.pressure_advance, + minval=0.) + smooth_time = gcmd.get_float('SMOOTH_TIME', + self.pressure_advance_smooth_time, + minval=0., maxval=.200) + self._set_pressure_advance(pressure_advance, smooth_time) + msg = ("pressure_advance: %.6f\n" + "pressure_advance_smooth_time: %.6f" + % (pressure_advance, smooth_time)) + self.printer.set_rollover_info(self.name, "%s: %s" % (self.name, msg)) + gcmd.respond_info(msg, log=False) + cmd_SET_E_STEP_DISTANCE_help = "Set extruder step distance" + def cmd_SET_E_STEP_DISTANCE(self, gcmd): + toolhead = self.printer.lookup_object('toolhead') + dist = gcmd.get_float('DISTANCE', None, above=0.) + if dist is None: + step_dist = self.stepper.get_step_dist() + gcmd.respond_info("Extruder '%s' step distance is %0.6f" + % (self.name, step_dist)) + return + toolhead.flush_step_generation() + self.stepper.set_step_dist(dist) + gcmd.respond_info("Extruder '%s' step distance set to %0.6f" + % (self.name, dist)) + +# Tracking for hotend heater, extrusion motion queue, and extruder stepper class PrinterExtruder: def __init__(self, config, extruder_num): self.printer = config.get_printer() self.name = config.get_name() + self.last_position = 0. + # Setup hotend heater shared_heater = config.get('shared_heater', None) pheaters = self.printer.load_object(config, 'heaters') gcode_id = 'T%d' % (extruder_num,) @@ -17,7 +96,7 @@ class PrinterExtruder: self.heater = pheaters.setup_heater(config, gcode_id) else: self.heater = pheaters.lookup_heater(shared_heater) - self.stepper = stepper.PrinterStepper(config) + # Setup kinematic checks self.nozzle_diameter = config.getfloat('nozzle_diameter', above=0.) filament_diameter = config.getfloat( 'filament_diameter', minval=self.nozzle_diameter) @@ -40,61 +119,34 @@ class PrinterExtruder: 'max_extrude_only_distance', 50., minval=0.) self.instant_corner_v = config.getfloat( 'instantaneous_corner_velocity', 1., minval=0.) - self.pressure_advance = self.pressure_advance_smooth_time = 0. - pressure_advance = config.getfloat('pressure_advance', 0., minval=0.) - smooth_time = config.getfloat('pressure_advance_smooth_time', - 0.040, above=0., maxval=.200) - # Setup iterative solver + # Setup extruder trapq (trapezoidal motion queue) ffi_main, ffi_lib = chelper.get_ffi() self.trapq = ffi_main.gc(ffi_lib.trapq_alloc(), ffi_lib.trapq_free) self.trapq_append = ffi_lib.trapq_append self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves - self.sk_extruder = ffi_main.gc(ffi_lib.extruder_stepper_alloc(), - ffi_lib.free) - self.stepper.set_stepper_kinematics(self.sk_extruder) - self.stepper.set_trapq(self.trapq) - toolhead.register_step_generator(self.stepper.generate_steps) - self._set_pressure_advance(pressure_advance, smooth_time) + # Setup extruder stepper + self.extruder_stepper = ExtruderStepper(config) + self.extruder_stepper.stepper.set_trapq(self.trapq) + pa = config.getfloat('pressure_advance', 0., minval=0.) + smooth_time = config.getfloat('pressure_advance_smooth_time', + 0.040, above=0., maxval=.200) + self.extruder_stepper._set_pressure_advance(pa, smooth_time) # Register commands gcode = self.printer.lookup_object('gcode') if self.name == 'extruder': toolhead.set_extruder(self, 0.) gcode.register_command("M104", self.cmd_M104) gcode.register_command("M109", self.cmd_M109) - gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None, - self.cmd_default_SET_PRESSURE_ADVANCE, - desc=self.cmd_SET_PRESSURE_ADVANCE_help) - gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", - self.name, self.cmd_SET_PRESSURE_ADVANCE, - desc=self.cmd_SET_PRESSURE_ADVANCE_help) gcode.register_mux_command("ACTIVATE_EXTRUDER", "EXTRUDER", self.name, self.cmd_ACTIVATE_EXTRUDER, desc=self.cmd_ACTIVATE_EXTRUDER_help) - gcode.register_mux_command("SET_EXTRUDER_STEP_DISTANCE", "EXTRUDER", - self.name, self.cmd_SET_E_STEP_DISTANCE, - desc=self.cmd_SET_E_STEP_DISTANCE_help) def update_move_time(self, flush_time): self.trapq_finalize_moves(self.trapq, flush_time) - def _set_pressure_advance(self, pressure_advance, smooth_time): - old_smooth_time = self.pressure_advance_smooth_time - if not self.pressure_advance: - old_smooth_time = 0. - new_smooth_time = smooth_time - if not pressure_advance: - new_smooth_time = 0. - toolhead = self.printer.lookup_object("toolhead") - toolhead.note_step_generation_scan_time(new_smooth_time * .5, - old_delay=old_smooth_time * .5) - ffi_main, ffi_lib = chelper.get_ffi() - espa = ffi_lib.extruder_set_pressure_advance - espa(self.sk_extruder, pressure_advance, new_smooth_time) - self.pressure_advance = pressure_advance - self.pressure_advance_smooth_time = smooth_time def get_status(self, eventtime): - return dict(self.heater.get_status(eventtime), - can_extrude=self.heater.can_extrude, - pressure_advance=self.pressure_advance, - smooth_time=self.pressure_advance_smooth_time) + sts = self.heater.get_status(eventtime) + sts['can_extrude'] = self.heater.can_extrude + sts.update(self.extruder_stepper.get_status(eventtime)) + return sts def get_name(self): return self.name def get_heater(self): @@ -104,8 +156,7 @@ class PrinterExtruder: def sync_stepper(self, stepper): toolhead = self.printer.lookup_object('toolhead') toolhead.flush_step_generation() - epos = self.stepper.get_commanded_position() - stepper.set_position([epos, 0., 0.]) + stepper.set_position([self.last_position, 0., 0.]) stepper.set_trapq(self.trapq) def stats(self, eventtime): return self.heater.stats(eventtime) @@ -155,9 +206,9 @@ class PrinterExtruder: move.start_pos[3], 0., 0., 1., can_pressure_advance, 0., start_v, cruise_v, accel) + self.last_position = move.end_pos[3] def find_past_position(self, print_time): - mcu_pos = self.stepper.get_past_mcu_position(print_time) - return self.stepper.mcu_to_commanded_position(mcu_pos) + return self.extruder_stepper.find_past_position(print_time) def cmd_M104(self, gcmd, wait=False): # Set Extruder Temperature temp = gcmd.get_float('S', 0.) @@ -178,35 +229,6 @@ class PrinterExtruder: def cmd_M109(self, gcmd): # Set Extruder Temperature and Wait self.cmd_M104(gcmd, wait=True) - cmd_SET_PRESSURE_ADVANCE_help = "Set pressure advance parameters" - def cmd_default_SET_PRESSURE_ADVANCE(self, gcmd): - extruder = self.printer.lookup_object('toolhead').get_extruder() - extruder.cmd_SET_PRESSURE_ADVANCE(gcmd) - def cmd_SET_PRESSURE_ADVANCE(self, gcmd): - pressure_advance = gcmd.get_float('ADVANCE', self.pressure_advance, - minval=0.) - smooth_time = gcmd.get_float('SMOOTH_TIME', - self.pressure_advance_smooth_time, - minval=0., maxval=.200) - self._set_pressure_advance(pressure_advance, smooth_time) - msg = ("pressure_advance: %.6f\n" - "pressure_advance_smooth_time: %.6f" - % (pressure_advance, smooth_time)) - self.printer.set_rollover_info(self.name, "%s: %s" % (self.name, msg)) - gcmd.respond_info(msg, log=False) - cmd_SET_E_STEP_DISTANCE_help = "Set extruder step distance" - def cmd_SET_E_STEP_DISTANCE(self, gcmd): - toolhead = self.printer.lookup_object('toolhead') - dist = gcmd.get_float('DISTANCE', None, above=0.) - if dist is None: - step_dist = self.stepper.get_step_dist() - gcmd.respond_info("Extruder '%s' step distance is %0.6f" - % (self.name, step_dist)) - return - toolhead.flush_step_generation() - self.stepper.set_step_dist(dist) - gcmd.respond_info("Extruder '%s' step distance set to %0.6f" - % (self.name, dist)) cmd_ACTIVATE_EXTRUDER_help = "Change the active extruder" def cmd_ACTIVATE_EXTRUDER(self, gcmd): toolhead = self.printer.lookup_object('toolhead') @@ -215,7 +237,7 @@ class PrinterExtruder: return gcmd.respond_info("Activating extruder %s" % (self.name,)) toolhead.flush_step_generation() - toolhead.set_extruder(self, self.stepper.get_commanded_position()) + toolhead.set_extruder(self, self.last_position) self.printer.send_event("extruder:activate_extruder") # Dummy extruder class used when a printer has no extruder at all From eb2a67cb956f96e9ed92d5c070411d7dec08bcfd Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 11 Jan 2022 15:00:36 -0500 Subject: [PATCH 025/211] extruder: Support SYNC_STEPPER_TO_EXTRUDER on extruder objects Refactor the extruder_stepper support so that it uses the ExtruderStepper class defined in extruder.py. Support the SYNC_STEPPER_TO_EXTRUDER command on steppers defined in either extruder_stepper or extruder config sections. Signed-off-by: Kevin O'Connor --- docs/G-Codes.md | 15 +++++---------- klippy/extras/extruder_stepper.py | 29 +++++------------------------ klippy/kinematics/extruder.py | 31 +++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index b4cb63a3..119f1fbb 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -182,6 +182,11 @@ The following standard commands are supported: result in excessive pressure between extruder and hot end. Do proper calibration steps with filament before use. If 'DISTANCE' value is not included command will return current step distance. +- `SYNC_STEPPER_TO_EXTRUDER STEPPER= [EXTRUDER=]`: This + command will cause the given extruder STEPPER (as specified in an + [extruder](Config_Reference#extruder) or + [extruder stepper](Config_Reference#extruder_stepper) config + section) to become synchronized to the given EXTRUDER. - `SET_STEPPER_ENABLE STEPPER= ENABLE=[0|1]`: Enable or disable only the given stepper. This is a diagnostic and debugging tool and must be used with care. Disabling an axis motor does not @@ -344,16 +349,6 @@ enabled: future G-Code movement commands may run in parallel with the stepper movement. -### Extruder stepper Commands - -The following command is available when an -[extruder_stepper config section](Config_Reference.md#extruder_stepper) -is enabled: -- `SYNC_STEPPER_TO_EXTRUDER STEPPER= - [EXTRUDER=]`: This command will cause the given - STEPPER to become synchronized to the given EXTRUDER, overriding - the extruder defined in the "extruder_stepper" config section. - ### Probe The following commands are available when a diff --git a/klippy/extras/extruder_stepper.py b/klippy/extras/extruder_stepper.py index a62b3f83..40b394ce 100644 --- a/klippy/extras/extruder_stepper.py +++ b/klippy/extras/extruder_stepper.py @@ -4,36 +4,17 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import logging -import stepper +from kinematics import extruder -class ExtruderStepper: +class PrinterExtruderStepper: def __init__(self, config): self.printer = config.get_printer() - stepper_name = config.get_name().split()[1] + self.extruder_stepper = extruder.ExtruderStepper(config) self.extruder_name = config.get('extruder', 'extruder') - self.stepper = stepper.PrinterStepper(config) - self.stepper.setup_itersolve('extruder_stepper_alloc') self.printer.register_event_handler("klippy:connect", self.handle_connect) - gcode = self.printer.lookup_object('gcode') - gcode.register_mux_command("SYNC_STEPPER_TO_EXTRUDER", "STEPPER", - stepper_name, - self.cmd_SYNC_STEPPER_TO_EXTRUDER, - desc=self.cmd_SYNC_STEPPER_TO_EXTRUDER_help) def handle_connect(self): - extruder = self.printer.lookup_object(self.extruder_name) - extruder.sync_stepper(self.stepper) - toolhead = self.printer.lookup_object('toolhead') - toolhead.register_step_generator(self.stepper.generate_steps) - cmd_SYNC_STEPPER_TO_EXTRUDER_help = "Set extruder stepper" - def cmd_SYNC_STEPPER_TO_EXTRUDER(self, gcmd): - ename = gcmd.get('EXTRUDER') - extruder = self.printer.lookup_object(ename, None) - if extruder is None: - raise gcmd.error("'%s' is not a valid extruder." % (ename,)) - extruder.sync_stepper(self.stepper) - self.extruder_name = ename - gcmd.respond_info("Extruder stepper now syncing with '%s'" % (ename,)) + self.extruder_stepper.sync_to_extruder(self.extruder_name) def load_config_prefix(config): - return ExtruderStepper(config) + return PrinterExtruderStepper(config) diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index c042a2dd..e3db152b 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -9,7 +9,7 @@ import stepper, chelper class ExtruderStepper: def __init__(self, config): self.printer = config.get_printer() - self.name = config.get_name() + self.name = config.get_name().split()[-1] self.pressure_advance = self.pressure_advance_smooth_time = 0. # Setup stepper self.stepper = stepper.PrinterStepper(config) @@ -17,9 +17,9 @@ class ExtruderStepper: self.sk_extruder = ffi_main.gc(ffi_lib.extruder_stepper_alloc(), ffi_lib.free) self.stepper.set_stepper_kinematics(self.sk_extruder) - toolhead = self.printer.lookup_object('toolhead') - toolhead.register_step_generator(self.stepper.generate_steps) # Register commands + self.printer.register_event_handler("klippy:connect", + self._handle_connect) gcode = self.printer.lookup_object('gcode') if self.name == 'extruder': gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None, @@ -31,12 +31,27 @@ class ExtruderStepper: gcode.register_mux_command("SET_EXTRUDER_STEP_DISTANCE", "EXTRUDER", self.name, self.cmd_SET_E_STEP_DISTANCE, desc=self.cmd_SET_E_STEP_DISTANCE_help) + gcode.register_mux_command("SYNC_STEPPER_TO_EXTRUDER", "STEPPER", + self.name, self.cmd_SYNC_STEPPER_TO_EXTRUDER, + desc=self.cmd_SYNC_STEPPER_TO_EXTRUDER_help) + def _handle_connect(self): + toolhead = self.printer.lookup_object('toolhead') + toolhead.register_step_generator(self.stepper.generate_steps) def get_status(self, eventtime): return {'pressure_advance': self.pressure_advance, 'smooth_time': self.pressure_advance_smooth_time} def find_past_position(self, print_time): mcu_pos = self.stepper.get_past_mcu_position(print_time) return self.stepper.mcu_to_commanded_position(mcu_pos) + def sync_to_extruder(self, extruder_name): + extruder = self.printer.lookup_object(extruder_name, None) + if extruder is None or not isinstance(extruder, PrinterExtruder): + raise self.printer.command_error("'%s' is not a valid extruder." + % (extruder_name,)) + toolhead = self.printer.lookup_object('toolhead') + toolhead.flush_step_generation() + self.stepper.set_position([extruder.last_position, 0., 0.]) + self.stepper.set_trapq(extruder.get_trapq()) def _set_pressure_advance(self, pressure_advance, smooth_time): old_smooth_time = self.pressure_advance_smooth_time if not self.pressure_advance: @@ -81,6 +96,11 @@ class ExtruderStepper: self.stepper.set_step_dist(dist) gcmd.respond_info("Extruder '%s' step distance set to %0.6f" % (self.name, dist)) + cmd_SYNC_STEPPER_TO_EXTRUDER_help = "Set extruder stepper" + def cmd_SYNC_STEPPER_TO_EXTRUDER(self, gcmd): + ename = gcmd.get('EXTRUDER') + self.sync_to_extruder(ename) + gcmd.respond_info("Extruder stepper now syncing with '%s'" % (ename,)) # Tracking for hotend heater, extrusion motion queue, and extruder stepper class PrinterExtruder: @@ -153,11 +173,6 @@ class PrinterExtruder: return self.heater def get_trapq(self): return self.trapq - def sync_stepper(self, stepper): - toolhead = self.printer.lookup_object('toolhead') - toolhead.flush_step_generation() - stepper.set_position([self.last_position, 0., 0.]) - stepper.set_trapq(self.trapq) def stats(self, eventtime): return self.heater.stats(eventtime) def check_move(self, move): From 02d5f9754fc7f9e493c8bc5a6418e2a9ea9d7ae1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 11 Jan 2022 18:13:21 -0500 Subject: [PATCH 026/211] extruder: Support disassociating a stepper from all extruders Support SYNC_STEPPER_TO_EXTRUDER commands with an EXTRUDER parameter set to an empty string. Signed-off-by: Kevin O'Connor --- docs/Config_Reference.md | 5 +++-- docs/G-Codes.md | 4 +++- klippy/kinematics/extruder.py | 7 +++++-- test/klippy/extruders.test | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 4c78b550..fd77f9e3 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -1835,8 +1835,9 @@ more information. ``` [extruder_stepper my_extra_stepper] #extruder: extruder -# The extruder this stepper is synchronized to. The default is -# "extruder". +# The extruder this stepper is synchronized to. If this is set to an +# empty string then the stepper will not be synchronized to an +# extruder. The default is "extruder". #step_pin: #dir_pin: #enable_pin: diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 119f1fbb..6450f0ef 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -186,7 +186,9 @@ The following standard commands are supported: command will cause the given extruder STEPPER (as specified in an [extruder](Config_Reference#extruder) or [extruder stepper](Config_Reference#extruder_stepper) config - section) to become synchronized to the given EXTRUDER. + section) to become synchronized to the given EXTRUDER. If EXTRUDER + is an empty string then the stepper will not be synchronized to an + extruder. - `SET_STEPPER_ENABLE STEPPER= ENABLE=[0|1]`: Enable or disable only the given stepper. This is a diagnostic and debugging tool and must be used with care. Disabling an axis motor does not diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index e3db152b..e3bc8916 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -44,12 +44,15 @@ class ExtruderStepper: mcu_pos = self.stepper.get_past_mcu_position(print_time) return self.stepper.mcu_to_commanded_position(mcu_pos) def sync_to_extruder(self, extruder_name): + toolhead = self.printer.lookup_object('toolhead') + toolhead.flush_step_generation() + if not extruder_name: + self.stepper.set_trapq(None) + return extruder = self.printer.lookup_object(extruder_name, None) if extruder is None or not isinstance(extruder, PrinterExtruder): raise self.printer.command_error("'%s' is not a valid extruder." % (extruder_name,)) - toolhead = self.printer.lookup_object('toolhead') - toolhead.flush_step_generation() self.stepper.set_position([extruder.last_position, 0., 0.]) self.stepper.set_trapq(extruder.get_trapq()) def _set_pressure_advance(self, pressure_advance, smooth_time): diff --git a/test/klippy/extruders.test b/test/klippy/extruders.test index 22dc6ab5..ff7c5917 100644 --- a/test/klippy/extruders.test +++ b/test/klippy/extruders.test @@ -15,3 +15,32 @@ G1 X25 Y25 E7.5 # Update step_distance SET_EXTRUDER_STEP_DISTANCE EXTRUDER=extruder DISTANCE=.005 G1 X30 Y30 E8.0 + +# Disable extruder stepper motor +SYNC_STEPPER_TO_EXTRUDER STEPPER=extruder EXTRUDER= +G1 X35 Y35 E8.5 + +# Disable my_extra_stepper stepper motor +SYNC_STEPPER_TO_EXTRUDER STEPPER=my_extra_stepper EXTRUDER= +G1 X40 Y40 E9.0 + +# Enable extruder stepper motor +SYNC_STEPPER_TO_EXTRUDER STEPPER=extruder EXTRUDER=extruder +G1 X45 Y45 E9.5 + +# Switch to just my_extra_stepper stepper motor +SYNC_STEPPER_TO_EXTRUDER STEPPER=extruder EXTRUDER= +SYNC_STEPPER_TO_EXTRUDER STEPPER=my_extra_stepper EXTRUDER=extruder +G1 X50 Y50 E10.0 + +# Test pressure advance move +SET_PRESSURE_ADVANCE EXTRUDER=my_extra_stepper ADVANCE=0.020 +G1 X55 Y55 E0 +G1 X55 Y55 E0.5 +G1 X60 Y60 E1.1 +G1 X50 Y50 +SET_PRESSURE_ADVANCE EXTRUDER=extruder ADVANCE=0.025 +G1 X55 Y55 E1.5 +G1 X50 Y50 +G1 X55 Y55 E2.0 +G1 X50 Y50 From f97fd7c6e392e376bd1552afdd39a2150d3e21d0 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 18 Jan 2022 11:21:53 -0500 Subject: [PATCH 027/211] gcode: Handle M117 and M118 commands that start with a special character Commit 7ef7bf60 broke the special handling for M117 commands that start with a number or special character. Fix that support and extend to M118 as well. Also improve handling of commands not separated by a space (eg, "M117HELLO"). Signed-off-by: Kevin O'Connor --- klippy/gcode.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/klippy/gcode.py b/klippy/gcode.py index abd431d5..07e312f9 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -27,20 +27,19 @@ class GCodeCommand: def get_command_parameters(self): return self._params def get_raw_command_parameters(self): - rawparams = self._commandline command = self._command + if command.startswith("M117 ") or command.startswith("M118 "): + command = command[:4] + rawparams = self._commandline urawparams = rawparams.upper() if not urawparams.startswith(command): - start = urawparams.find(command) + rawparams = rawparams[urawparams.find(command):] end = rawparams.rfind('*') if end >= 0: rawparams = rawparams[:end] - rawparams = rawparams[start:] - commandlen = len(command) + 1 - if len(rawparams) > commandlen: - rawparams = rawparams[commandlen:] - else: - rawparams = '' + rawparams = rawparams[len(command):] + if rawparams.startswith(' '): + rawparams = rawparams[1:] return rawparams def ack(self, msg=None): if not self._need_ack: @@ -277,9 +276,9 @@ class GCodeDispatch: if cmdline: logging.debug(cmdline) return - if cmd.startswith("M117 "): - # Handle M117 gcode with numeric and special characters - handler = self.gcode_handlers.get("M117", None) + if cmd.startswith("M117 ") or cmd.startswith("M118 "): + # Handle M117/M118 gcode with numeric and special characters + handler = self.gcode_handlers.get(cmd[:4], None) if handler is not None: handler(gcmd) return From 2f1edac9222d0a106ae533ebaf762d419861d586 Mon Sep 17 00:00:00 2001 From: D4SK <42315676+D4SK@users.noreply.github.com> Date: Sun, 23 Jan 2022 02:41:44 +0100 Subject: [PATCH 028/211] tmc: Fix number of arguments in phase endstop warning (#5184) Signed-off-by: Konstantin Vogel --- klippy/extras/tmc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/klippy/extras/tmc.py b/klippy/extras/tmc.py index 6a59bbfb..0c5036f9 100644 --- a/klippy/extras/tmc.py +++ b/klippy/extras/tmc.py @@ -313,7 +313,7 @@ class TMCCommandHelper: moff = (phase - stepper.get_mcu_position()) % phases if self.mcu_phase_offset is not None and self.mcu_phase_offset != moff: logging.warning("Stepper %s phase change (was %d now %d)", - self.mcu_phase_offset, moff) + self.stepper_name, self.mcu_phase_offset, moff) self.mcu_phase_offset = moff # Stepper enable/disable tracking def _do_enable(self, print_time): From 28b568a6ace40af5f92383d23797409f4c1bcce3 Mon Sep 17 00:00:00 2001 From: Nick Douma Date: Sun, 23 Jan 2022 02:47:51 +0100 Subject: [PATCH 029/211] gcode_arcs: detect CW / CCW move with renamed G2/G3 command (#5096) The G2 / G3 command might be renamed using `gcode_macro` + `rename_existing`. This change allow detecting clockwise / anti-clockwise moves when the command gets renamed. Signed-off-by: Nick Douma --- klippy/extras/gcode_arcs.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/klippy/extras/gcode_arcs.py b/klippy/extras/gcode_arcs.py index 71f83ffb..61fa7234 100644 --- a/klippy/extras/gcode_arcs.py +++ b/klippy/extras/gcode_arcs.py @@ -20,9 +20,15 @@ class ArcSupport: self.gcode_move = self.printer.load_object(config, 'gcode_move') self.gcode = self.printer.lookup_object('gcode') self.gcode.register_command("G2", self.cmd_G2) - self.gcode.register_command("G3", self.cmd_G2) + self.gcode.register_command("G3", self.cmd_G3) def cmd_G2(self, gcmd): + self._cmd_inner(gcmd, True) + + def cmd_G3(self, gcmd): + self._cmd_inner(gcmd, False) + + def _cmd_inner(self, gcmd, clockwise): gcodestatus = self.gcode_move.get_status() if not gcodestatus['absolute_coordinates']: raise gcmd.error("G2/G3 does not support relative move mode") @@ -40,7 +46,6 @@ class ArcSupport: raise gcmd.error("G2/G3 neither I nor J given") asE = gcmd.get_float("E", None) asF = gcmd.get_float("F", None) - clockwise = (gcmd.get_command() == 'G2') # Build list of linear coordinates to move to coords = self.planArc(currentPos, [asX, asY, asZ], [asI, asJ], From 7d57a7c4c846bbf0b6e271b4cc7f86cb0a04d11d Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Wed, 26 Jan 2022 15:00:18 -0800 Subject: [PATCH 030/211] docs: Various minor fixes (#5175) Signed-off-by: Yifei Ding Date: Sun, 23 Jan 2022 15:24:55 +0100 Subject: [PATCH 031/211] docs: Updated simulavr building instructions Signed-off-by: Dmitry Butyugin --- docs/Debugging.md | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/docs/Debugging.md b/docs/Debugging.md index 792301a9..8fd69b5e 100644 --- a/docs/Debugging.md +++ b/docs/Debugging.md @@ -202,20 +202,33 @@ run this on a desktop class machine (not a Raspberry Pi) as it does require significant cpu to run efficiently. To use simulavr, download the simulavr package and compile with python -support: +support. Note that the build system may need to have some packages (such as +swig) installed in order to build the python module. ``` git clone git://git.savannah.nongnu.org/simulavr.git cd simulavr -./bootstrap -./configure --enable-python -make +make python +make build ``` +Make sure a file like **./build/pysimulavr/_pysimulavr.*.so** is present +after the above compilation: +``` +ls ./build/pysimulavr/_pysimulavr.*.so +``` +This commmand should report a specific file (e.g. +**./build/pysimulavr/_pysimulavr.cpython-39-x86_64-linux-gnu.so**) and +not an error. -Note that the build system may need to have some packages (such as -swig) installed in order to build the python module. Make sure the -file **src/python/_pysimulavr.so** is present after the above -compilation. +If you are on a Debian-based system (Debian, Ubuntu, etc.) you can +install the following packages and generate *.deb files for system-wide +installation of simulavr: +``` +sudo apt update +sudo apt install g++ make cmake swig rst2pdf help2man texinfo +make cfgclean python debian +sudo dpkg -i build/debian/python3-simulavr*.deb +``` To compile Klipper for use in simulavr, run: @@ -229,7 +242,12 @@ select SIMULAVR software emulation support. Then one can compile Klipper (run `make`) and then start the simulation with: ``` -PYTHONPATH=/path/to/simulavr/src/python/ ./scripts/avrsim.py out/klipper.elf +PYTHONPATH=/path/to/simulavr/build/pysimulavr/ ./scripts/avrsim.py out/klipper.elf +``` +Note that if you have installed python3-simulavr system-wide, you do +not need to set `PYTHONPATH`, and can simply run the simulator as +``` +./scripts/avrsim.py out/klipper.elf ``` Then, with simulavr running in another window, one can run the From fb6d6d381c28a5aa90a8f1f1ee22ef9179077dbb Mon Sep 17 00:00:00 2001 From: Sergey1560 <53866542+Sergey1560@users.noreply.github.com> Date: Thu, 27 Jan 2022 02:06:55 +0300 Subject: [PATCH 032/211] stm32: Add remap CAN to PD0/PD1 for stm32f103 (#5173) Signed-off-by: Sergey Terentiev --- src/stm32/Kconfig | 2 +- src/stm32/stm32f1.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index e6710994..29d7afa2 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -339,7 +339,7 @@ choice select CANSERIAL config STM32_CANBUS_PD0_PD1 bool "CAN bus (on PD0/PD1)" if LOW_LEVEL_OPTIONS - depends on HAVE_STM32_CANBUS && MACH_STM32F4 + depends on HAVE_STM32_CANBUS select CANSERIAL endchoice diff --git a/src/stm32/stm32f1.c b/src/stm32/stm32f1.c index 5680cfba..526ec485 100644 --- a/src/stm32/stm32f1.c +++ b/src/stm32/stm32f1.c @@ -204,6 +204,9 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup) if (gpio == GPIO('B', 8) || gpio == GPIO('B', 9)) stm32f1_alternative_remap(AFIO_MAPR_CAN_REMAP_Msk, AFIO_MAPR_CAN_REMAP_REMAP2); + if (gpio == GPIO('D', 0) || gpio == GPIO('D', 1)) + stm32f1_alternative_remap(AFIO_MAPR_CAN_REMAP_Msk, + AFIO_MAPR_CAN_REMAP_REMAP3); } } From 31cefe15cf4b084f8ae2d627e80cd06a3ef5ff5e Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 28 Jan 2022 18:24:25 -0500 Subject: [PATCH 033/211] docs: Improvements to RPi_microcontroller.md Wraps lines to 80 columns. Only use triple backticks on multi-line code excerpts. Add backticks around "sudo raspi-config". Move "Enabling SPI" section to be near pwm and gpio configuration. Signed-off-by: Kevin O'Connor --- docs/RPi_microcontroller.md | 90 ++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/docs/RPi_microcontroller.md b/docs/RPi_microcontroller.md index 591d2864..79b46afb 100644 --- a/docs/RPi_microcontroller.md +++ b/docs/RPi_microcontroller.md @@ -1,23 +1,26 @@ # RPi microcontroller -This document describes the process of running Klipper on a RPi -and use the same RPi as secondary mcu. +This document describes the process of running Klipper on a RPi and +use the same RPi as secondary mcu. ## Why use RPi as a secondary MCU? Often the MCUs dedicated to controlling 3D printers have a limited and pre-configured number of exposed pins to manage the main printing -functions (thermal resistors, extruders, steppers ...). -Using the RPi where Klipper is installed as a secondary MCU gives the -possibility to directly use the GPIOs and the buses (i2c, spi) of the RPi -inside klipper without using Octoprint plugins (if used) or external -programs giving the ability to control everything within the print GCODE. +functions (thermal resistors, extruders, steppers ...). Using the RPi +where Klipper is installed as a secondary MCU gives the possibility to +directly use the GPIOs and the buses (i2c, spi) of the RPi inside +klipper without using Octoprint plugins (if used) or external programs +giving the ability to control everything within the print GCODE. -**Warning**: If your platform is a _Beaglebone_ and you have correctly followed the installation steps, the linux mcu is already installed and configured for your system. +**Warning**: If your platform is a _Beaglebone_ and you have correctly +followed the installation steps, the linux mcu is already installed +and configured for your system. ## Install the rc script -If you want to use the host as a secondary MCU the klipper_mcu process must run before the klippy process. +If you want to use the host as a secondary MCU the klipper_mcu process +must run before the klippy process. After installing Klipper, install the script. run: ``` @@ -26,10 +29,6 @@ sudo cp "./scripts/klipper-mcu-start.sh" /etc/init.d/klipper_mcu sudo update-rc.d klipper_mcu defaults ``` -## Enabling SPI - -Make sure the Linux SPI driver is enabled by running sudo raspi-config and enabling SPI under the "Interfacing options" menu. - ## Building the micro-controller code To compile the Klipper micro-controller code, start by configuring it @@ -38,7 +37,9 @@ for the "Linux process": cd ~/klipper/ make menuconfig ``` -In the menu, set "Microcontroller Architecture" to "Linux process," then save and exit. + +In the menu, set "Microcontroller Architecture" to "Linux process," +then save and exit. To build and install the new micro-controller code, run: ``` @@ -47,9 +48,10 @@ make flash sudo service klipper start ``` -If klippy.log reports a "Permission denied" error when attempting to connect -to `/tmp/klipper_host_mcu` then you need to add your user to the tty group. -The following command will add the "pi" user to the tty group: +If klippy.log reports a "Permission denied" error when attempting to +connect to `/tmp/klipper_host_mcu` then you need to add your user to +the tty group. The following command will add the "pi" user to the +tty group: ``` sudo usermod -a -G tty pi ``` @@ -61,12 +63,24 @@ following the instructions in [RaspberryPi sample config](../config/sample-raspberry-pi.cfg) and [Multi MCU sample config](../config/sample-multi-mcu.cfg). +## Optional: Enabling SPI + +Make sure the Linux SPI driver is enabled by running +`sudo raspi-config` and enabling SPI under the "Interfacing options" +menu. + ## Optional: Identify the correct gpiochip -On Rasperry Pi and on many clones the pins exposed on the GPIO belong to the first gpiochip. They can therefore be used on klipper simply by referring them with the name `gpio0..n`. -However, there are cases in which the exposed pins belong to gpiochips other than the first. For example in the case of some OrangePi models or if a Port Expander is used. In these cases it is useful to use the commands to access the _Linux GPIO character device_ to verify the configuration. +On Rasperry and on many clones the pins exposed on the GPIO belong to +the first gpiochip. They can therefore be used on klipper simply by +referring them with the name `gpio0..n`. However, there are cases in +which the exposed pins belong to gpiochips other than the first. For +example in the case of some OrangePi models or if a Port Expander is +used. In these cases it is useful to use the commands to access the +_Linux GPIO character device_ to verify the configuration. -To install the _Linux GPIO character device - binary_ on a debian based distro like OctoPi run: +To install the _Linux GPIO character device - binary_ on a debian +based distro like octopi run: ``` sudo apt-get install gpiod ``` @@ -81,9 +95,13 @@ To check the pin number and the pin availability tun: gpioinfo ``` -The chosen pin can thus be used within the configuration as `gpiochip/gpio` where **n** is the chip number as seen by the `gpiodetect` command and **o** is the line number seen by the` gpioinfo` command. +The chosen pin can thus be used within the configuration as +`gpiochip/gpio` where **n** is the chip number as seen by the +`gpiodetect` command and **o** is the line number seen by the` +gpioinfo` command. -***Warning:*** only gpio marked as `unused` can be used. It is not possible for a _line_ to be used by multiple processes simultaneously. +***Warning:*** only gpio marked as `unused` can be used. It is not +possible for a _line_ to be used by multiple processes simultaneously. For example on a RPi 3B+ where klipper use the GPIO20 for a switch: ``` @@ -160,23 +178,32 @@ gpiochip1 - 8 lines: ## Optional: Hardware PWM -Raspberry Pi's have two PWM channels (PWM0 and PWM1) which are exposed on the header or if not, can be routed to existing gpio pins. -The Linux mcu daemon uses the pwmchip sysfs interface to control hardware pwm devices on Linux hosts. -The pwm sysfs interface is not exposed by default on a Raspberry and can be activated by adding a line to ```/boot/config.txt```: +Raspberry Pi's have two PWM channels (PWM0 and PWM1) which are exposed +on the header or if not, can be routed to existing gpio pins. The +Linux mcu daemon uses the pwmchip sysfs interface to control hardware +pwm devices on Linux hosts. The pwm sysfs interface is not exposed by +default on a Raspberry and can be activated by adding a line to +`/boot/config.txt`: ``` # Enable pwmchip sysfs interface dtoverlay=pwm,pin=12,func=4 ``` -This example enables only PWM0 and routes it to gpio12. If both PWM channels need to be enabled you can use ```pwm-2chan```. +This example enables only PWM0 and routes it to gpio12. If both PWM +channels need to be enabled you can use `pwm-2chan`. -The overlay does not expose the pwm line on sysfs on boot and needs to be exported by echo'ing the number of the pwm channel to ```/sys/class/pwm/pwmchip0/export```: +The overlay does not expose the pwm line on sysfs on boot and needs to +be exported by echo'ing the number of the pwm channel to +`/sys/class/pwm/pwmchip0/export`: ``` echo 0 > /sys/class/pwm/pwmchip0/export ``` -This will create device ```/sys/class/pwm/pwmchip0/pwm0``` in the filesystem. -The easiest way to do this is by adding this to ```/etc/rc.local``` before the ```exit 0``` line. -With the sysfs in place, you can now use either the pwm channel(s) by adding the following piece of configuration to your ```printer.cfg```: +This will create device `/sys/class/pwm/pwmchip0/pwm0` in the +filesystem. The easiest way to do this is by adding this to +`/etc/rc.local` before the `exit 0` line. + +With the sysfs in place, you can now use either the pwm channel(s) by +adding the following piece of configuration to your `printer.cfg`: ``` [output_pin caselight] pin: host:pwmchip0/pwm0 @@ -184,7 +211,8 @@ pwm: True hardware_pwm: True cycle_time: 0.000001 ``` -This will add hardware pwm control to gpio12 on the Pi (because the overlay was configured to route pwm0 to pin=12). +This will add hardware pwm control to gpio12 on the Pi (because the +overlay was configured to route pwm0 to pin=12). PWM0 can be routed to gpio12 and gpio18, PWM1 can be routed to gpio13 and gpio19: From c15d38b973a56978535f36c0fe61f5f8de468248 Mon Sep 17 00:00:00 2001 From: adelyser <12093019+adelyser@users.noreply.github.com> Date: Sat, 29 Jan 2022 11:31:41 -0700 Subject: [PATCH 034/211] config: Add BIQU BX printer config (#4950) Signed-off-by: Aaron DeLyser --- config/printer-biqu-bx-2021.cfg | 317 ++++++++++++++++++++++++++++++++ test/configs/stm32h743.config | 3 + test/klippy/printers.test | 4 + 3 files changed, 324 insertions(+) create mode 100644 config/printer-biqu-bx-2021.cfg create mode 100644 test/configs/stm32h743.config diff --git a/config/printer-biqu-bx-2021.cfg b/config/printer-biqu-bx-2021.cfg new file mode 100644 index 00000000..01225fb8 --- /dev/null +++ b/config/printer-biqu-bx-2021.cfg @@ -0,0 +1,317 @@ +# This file contains common pin mappings for the BigTreeTech SKR SE BX. +# To use this config, the firmware should be compiled for the +# STM32H743 with a "128KiB bootloader". Additionally, GPIO pins PB5 +# and PE5 need to be set at microcontroller startup. + +###################################################################### +# NOTE: In order enable the TFT70-BX display when the printer first +# starts, add PB5 and PE5 to the `GPIO pins to set at micro-controller +# startup` section when running "make menuconfig" +###################################################################### + +# The "make flash" command does not work on the SKR SE BX. Instead, +# after running "make", copy the generated "out/klipper.bin" file to a +# file named "firmware.bin" on an SD card and then restart the SKR SE BX +# with that SD card. After klipper has been flashed once to the board, +# you can update klipper by leaving a microSD inserted and running the +# scripts/flash-sd.sh script. + +# See docs/Config_Reference.md for a description of parameters. + +######################################## +# Steppers +######################################## + +[stepper_x] +step_pin: PG13 +dir_pin: !PG12 +enable_pin: !PG14 +microsteps: 16 +rotation_distance: 40 +full_steps_per_rotation: 400 +endstop_pin: tmc2209_stepper_x:virtual_endstop +position_endstop: -13 +position_min: -13 +position_max: 250 +homing_speed: 30 +homing_retract_dist: 0 + +[stepper_y] +step_pin: PB3 +dir_pin: !PD3 +enable_pin: !PB4 +microsteps: 16 +rotation_distance: 40 +full_steps_per_rotation: 400 +endstop_pin: tmc2209_stepper_y:virtual_endstop +position_endstop: -7 +position_min: -7 +position_max: 250 +homing_speed: 30 +homing_retract_dist: 0 + +[stepper_z] +step_pin: PD7 +dir_pin: PD6 +enable_pin: !PG9 +microsteps: 16 +rotation_distance: 8 +full_steps_per_rotation: 400 +endstop_pin: probe:z_virtual_endstop +position_min: -2 +position_max: 250 + +[stepper_z1] +step_pin: PA8 +dir_pin: PC9 +enable_pin: !PD2 +microsteps: 16 +rotation_distance: 8 +full_steps_per_rotation: 400 + +[extruder] +step_pin: PC14 +dir_pin: !PC13 +enable_pin: !PC15 +microsteps: 16 +rotation_distance: 24.031 +gear_ratio: 7:1 +full_steps_per_rotation: 200 +nozzle_diameter: 0.400 +filament_diameter: 1.750 +heater_pin: PC4 +sensor_type: EPCOS 100K B57560G104F +sensor_pin: PH4 +control: pid +pid_Kp: 22.2 +pid_Ki: 1.08 +pid_Kd: 114 +min_temp: 0 +max_temp: 350 + +[safe_z_home] +home_xy_position: 125,125 +speed: 200 +z_hop: 10 +z_hop_speed: 25 + +######################################## +# TMC2209 configuration +######################################## + +[tmc2209 stepper_x] +uart_pin: PG10 +diag_pin: ^PB11 +run_current: 0.800 +sense_resistor: 0.150 +driver_SGTHRS: 127 +stealthchop_threshold: 999999 + +[tmc2209 stepper_y] +uart_pin: PD4 +diag_pin: ^PB12 +run_current: 0.800 +sense_resistor: 0.150 +driver_SGTHRS: 137 +stealthchop_threshold: 999999 + +[tmc2209 stepper_z] +uart_pin: PD5 +run_current: 1.000 +sense_resistor: 0.150 +stealthchop_threshold: 999999 + +[tmc2209 stepper_z1] +uart_pin: PC8 +run_current: 1.000 +sense_resistor: 0.150 +stealthchop_threshold: 999999 + +[tmc2209 extruder] +uart_pin: PI8 +run_current: 0.800 +sense_resistor: 0.150 +stealthchop_threshold: 0 + +######################################## +# PRINTER +######################################## + +[mcu] +serial: /dev/ttyAMA0 +restart_method: command + +[printer] +kinematics: cartesian +max_velocity: 200 +max_accel: 1000 +max_z_velocity: 10 +max_z_accel: 1000 + +[fan] +pin: PA5 + +[heater_fan extruder_fan] +pin: PA6 +heater: extruder + +[controller_fan controller_fan] +pin: PA7 +idle_timeout: 300 # 5 minute timeout + +[output_pin motor_power] +pin: PI11 +value: 1 + +[idle_timeout] +gcode: + TURN_OFF_HEATERS + M84 + SET_PIN PIN=screen VALUE=0 + SET_LED LED=led BLUE=0.0 RED=0.0 GREEN=0.0 + +[pause_resume] + +######################################## +# DISPLAY +######################################## + +[output_pin screen] +pin: PB5 +value: 1 + +[display_status] + +[gcode_button lcd_button] +pin: PH8 +press_gcode: + SET_PIN PIN=screen VALUE=1 + SET_LED LED=led BLUE=1.0 RED=1.0 GREEN=1.0 + +[output_pin beeper] +pin: PA14 +pwm: True +cycle_time: 0.001 + +######################################## +# LEDS +######################################## + +[neopixel led] +pin: PH3 +chain_count: 15 + +[neopixel knob] +pin: PB1 +chain_count: 2 + +[delayed_gcode welcome] +initial_duration: 0.1 +gcode: + SET_LED LED=knob RED=0.0 BLUE=1.0 GREEN=0.0 + SET_LED LED=led RED=0.0 BLUE=1.0 GREEN=0.0 + G4 P1000 + SET_LED LED=led RED=1.0 BLUE=0.0 GREEN=0.0 + G4 P1000 + SET_LED LED=led RED=0.0 BLUE=0.0 GREEN=1.0 + G4 P1000 + SET_LED LED=led RED=1.0 BLUE=1.0 GREEN=1.0 + +######################################## +# BED +######################################## + +[heater_bed] +heater_pin: PA4 +sensor_type: EPCOS 100K B57560G104F +sensor_pin: PH5 +control: watermark +min_temp: 0 +max_temp: 250 + +[probe] +pin: PH2 +x_offset: -30.1 +y_offset: 26.78 +z_offset: 0 +speed: 5 +samples: 3 +samples_result: median +sample_retract_dist: 3.0 +samples_tolerance: 0.006 +samples_tolerance_retries: 5 + +[bed_mesh] +speed: 120 +mesh_min: 10,19.78 +mesh_max: 219.9,230 +probe_count: 4,4 + +[screws_tilt_adjust] +screw1: 58,-7 +screw1_name: front left +screw2: 245,-7 +screw2_name: front right +screw3: 245,179 +screw3_name: rear right +screw4: 58,179 +screw4_name: rear left +speed: 100 +screw_thread: CCW-M3 + +######################################## +## MACROS +######################################## + +# Slicer setup: "print_start NOZZLE= BED= +# This macro does a preheat on the probe for better accuracy and needs +# the temps passed in. examples: +# Cura: PRINT_START BED={material_bed_temperature_layer_0} NOZZLE={material_print_temperature_layer_0} +# PrusaSlicer: PRINT_START NOZZLE=[first_layer_temperature] BED=[bed_temperature] +# Use PRINT_END for the slicer ending script +[gcode_macro PRINT_START] +gcode: + # Turn on screen if it's not on + SET_PIN PIN=screen VALUE=1 + G28 + G0 Z1 + # Warm up nozzle, not to full temps yet + M104 S150 + # Set LED to Purple for bed heating + SET_LED LED=led BLUE=0.94 RED=0.63 GREEN=0.13 + M117 Heating Bed + + # Allow probe to warm up, then re-home Z + M190 S60 + M105 + G4 P90000 + G28 Z + + M190 S{params.BED} + M105 + G90 # Ensure we are in absolute mode + G21 + M83 # Set the extruder to relative mode + G92 E0 + + # Set LED to Red for nozzle heating + SET_LED LED=led BLUE=0.0 RED=1.0 GREEN=0.0 + M117 Heating Nozzle + G0 X2 Y0 F6000 + G0 Z0.4 + M109 S{params.NOZZLE} + M105 + # Set LED to white for printing + SET_LED LED=led BLUE=1.0 RED=1.0 GREEN=1.0 + M117 Printing + + # Purge Line + G1 X120 E30 F1200 + G1 Y1 + G1 X2 E30 F1200 + G92 E0 + + G1 Z1.0 F600 + G92 E0 + G0 F9000 + G90 # Set back to Absolute mode diff --git a/test/configs/stm32h743.config b/test/configs/stm32h743.config new file mode 100644 index 00000000..768e79b2 --- /dev/null +++ b/test/configs/stm32h743.config @@ -0,0 +1,3 @@ +# Base config file for STM32H743 ARM processor +CONFIG_MACH_STM32=y +CONFIG_MACH_STM32H743=y diff --git a/test/klippy/printers.test b/test/klippy/printers.test index 5d1787d9..03274a51 100644 --- a/test/klippy/printers.test +++ b/test/klippy/printers.test @@ -190,6 +190,10 @@ CONFIG ../../config/generic-fysetc-s6-v2.cfg CONFIG ../../config/generic-fysetc-spider.cfg CONFIG ../../config/generic-mks-rumba32-v1.0.cfg +# Printers using the stm32h743 +DICTIONARY stm32h743.dict +CONFIG ../../config/printer-biqu-bx-2021.cfg + # Printers using the stm32g0b1 DICTIONARY stm32g0b1.dict CONFIG ../../config/generic-bigtreetech-skr-mini-e3-v3.0.cfg From b414fc4975264b9c06ab91fd07697d614dda4f3b Mon Sep 17 00:00:00 2001 From: adelyser <12093019+adelyser@users.noreply.github.com> Date: Sat, 29 Jan 2022 11:32:48 -0700 Subject: [PATCH 035/211] spi_flash: Add btt-skr-bx-se to the board types (#4951) Signed-off-by: Aaron DeLyser --- scripts/spi_flash/board_defs.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/spi_flash/board_defs.py b/scripts/spi_flash/board_defs.py index ec0c5750..bb23db15 100644 --- a/scripts/spi_flash/board_defs.py +++ b/scripts/spi_flash/board_defs.py @@ -60,6 +60,11 @@ BOARD_DEFS = { 'spi_bus': "spi1", "cs_pin": "PA4", "current_firmware_path": "OLD.BIN" + }, + 'btt-skr-se-bx': { + 'mcu': 'stm32h743xx', + 'spi_bus': 'spi3a', + 'cs_pin': 'PA15' } } From 15ffa859540cd051bc06c2e333ed5c93994aa10b Mon Sep 17 00:00:00 2001 From: Haxk20 <16738302+Haxk20@users.noreply.github.com> Date: Sun, 30 Jan 2022 00:18:03 +0100 Subject: [PATCH 036/211] doc: Fix typo in Manual_Level.md (#5161) Just a small commit fixing a tiny typo i noticed. Signed-off-by: Martin Botka --- docs/Manual_Level.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Manual_Level.md b/docs/Manual_Level.md index 2b73e8b4..1ade08e6 100644 --- a/docs/Manual_Level.md +++ b/docs/Manual_Level.md @@ -184,7 +184,7 @@ This means that: - front left screw is the reference point you must not change it. - front right screw must be turned clockwise 1 full turn and a quarter turn - rear right screw must be turned counter-clockwise 50 minutes -- read left screw must be turned clockwise 2 minutes (not need it's ok) +- rear left screw must be turned clockwise 2 minutes (not need it's ok) Repeat the process several times until you get a good level bed - normally when all adjustments are below 6 minutes. From a7b01857f55ebab1aabb28dc81f98f859f018923 Mon Sep 17 00:00:00 2001 From: Lasse Dalegaard Date: Mon, 31 Jan 2022 08:48:04 +0100 Subject: [PATCH 037/211] flash_usb: use sudo for rp2040 flashing The rp2040 can be flashed without sudo when using udev rules to give the user permission, but in a standard configuration sudo is required. Here we make it possible for flash_usb to use sudo for the rp2040 target, and make it the default when using `make flash` for the rp2040. As for other targets, one can set `NOSUDO=1` to not call through sudo. Signed-off-by: Lasse Dalegaard --- scripts/flash_usb.py | 8 +++++--- src/rp2040/Makefile | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py index 581aa5c0..ca41293a 100755 --- a/scripts/flash_usb.py +++ b/scripts/flash_usb.py @@ -163,7 +163,7 @@ def flash_atsamd(options, binfile): sys.exit(-1) # Look for an rp2040 and flash it with rp2040_flash. -def rp2040_flash(devpath, binfile): +def rp2040_flash(devpath, binfile, sudo): args = ["lib/rp2040_flash/rp2040_flash", binfile] if len(devpath) > 0: with open(devpath + "/busnum") as f: @@ -172,6 +172,8 @@ def rp2040_flash(devpath, binfile): addr = f.read().strip() args += [bus, addr] sys.stderr.write(" ".join(args) + '\n\n') + if sudo: + args.insert(0, "sudo") res = subprocess.call(args) if res != 0: raise error("Error running rp2040_flash") @@ -268,7 +270,7 @@ device as a usb drive, and copy klipper.uf2 to the device. def flash_rp2040(options, binfile): try: if options.device.lower() == "first": - rp2040_flash("", binfile) + rp2040_flash("", binfile, options.sudo) return buspath, devpath = translate_serial_to_usb_path(options.device) @@ -276,7 +278,7 @@ def flash_rp2040(options, binfile): devpath = os.path.dirname(devpath) enter_bootloader(options.device) wait_path(devpath) - rp2040_flash(devpath, binfile) + rp2040_flash(devpath, binfile, options.sudo) except error as e: sys.stderr.write(RP2040_HELP % (options.device, str(e))) diff --git a/src/rp2040/Makefile b/src/rp2040/Makefile index fbeccb97..f15302d1 100644 --- a/src/rp2040/Makefile +++ b/src/rp2040/Makefile @@ -51,4 +51,4 @@ lib/rp2040_flash/rp2040_flash: # Flash rules flash: $(OUT)klipper.uf2 lib/rp2040_flash/rp2040_flash @echo " Flashing $< to $(FLASH_DEVICE)" - $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(OUT)klipper.uf2 + $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(CONFIG_MCU) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.uf2 From 9c4172784ad832ab05e543f5afc68775cd90c922 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 28 Jan 2022 19:04:10 -0500 Subject: [PATCH 038/211] docs: Update Resonance_Compensation.md to recommend SET_VELOCITY_LIMIT It's no longer necessary to update the printer.cfg file to alter the max_accel and square_corner_velocity parameters. Update the Resonance_Compensation.md document to reflect this. Also, recommend using STEP_DELTA in the TUNING_TOWER commands. Signed-off-by: Kevin O'Connor --- docs/Resonance_Compensation.md | 138 +++++++++++++++------------------ 1 file changed, 64 insertions(+), 74 deletions(-) diff --git a/docs/Resonance_Compensation.md b/docs/Resonance_Compensation.md index 64222c28..d168748f 100644 --- a/docs/Resonance_Compensation.md +++ b/docs/Resonance_Compensation.md @@ -23,9 +23,8 @@ of the stealthChop mode of Trinamic stepper drivers. ## Tuning -Basic tuning requires measuring the ringing frequencies of the printer and -adding a few parameters to `printer.cfg` file. - +Basic tuning requires measuring the ringing frequencies of the printer +by printing a test model. Slice the ringing test model, which can be found in [docs/prints/ringing_tower.stl](prints/ringing_tower.stl), in the slicer: @@ -45,31 +44,28 @@ Slice the ringing test model, which can be found in First, measure the **ringing frequency**. -1. Increase `max_accel` and `max_accel_to_decel` parameters in your - `printer.cfg` to 7000. Note that this is only needed for tuning, and more - proper value will be selected in the corresponding - [section](#selecting-max_accel). -2. If `square_corner_velocity` parameter was changed, revert it back to 5.0. - It is not advised to increase it when using the input shaper because it can - cause more smoothing in parts - it is better to use higher acceleration - value instead. -3. Restart the firmware: `RESTART`. -4. Disable Pressure Advance: `SET_PRESSURE_ADVANCE ADVANCE=0`. -5. If you have already added `[input_shaper]` section to the printer.cfg, +1. If `square_corner_velocity` parameter was changed, revert it back + to 5.0. It is not advised to increase it when using input shaper + because it can cause more smoothing in parts - it is better to use + higher acceleration value instead. +2. Increase `max_accel_to_decel` by issuing the following command: + `SET_VELOCITY_LIMIT ACCEL_TO_DECEL=7000` +3. Disable Pressure Advance: `SET_PRESSURE_ADVANCE ADVANCE=0` +4. If you have already added `[input_shaper]` section to the printer.cfg, execute `SET_INPUT_SHAPER SHAPER_FREQ_X=0 SHAPER_FREQ_Y=0` command. If you get "Unknown command" error, you can safely ignore it at this point and continue with the measurements. -6. Execute the command - `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1250 FACTOR=100 BAND=5`. +5. Execute the command: + `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1500 STEP_DELTA=500 STEP_HEIGHT=5` Basically, we try to make ringing more pronounced by setting different large values for acceleration. This command will increase the acceleration every 5 mm starting from 1500 mm/sec^2: 1500 mm/sec^2, 2000 mm/sec^2, 2500 mm/sec^2 and so forth up until 7000 mm/sec^2 at the last band. -7. Print the test model sliced with the suggested parameters. -8. You can stop the print earlier if the ringing is clearly visible and you see +6. Print the test model sliced with the suggested parameters. +7. You can stop the print earlier if the ringing is clearly visible and you see that acceleration gets too high for your printer (e.g. printer shakes too much or starts skipping steps). -9. Use X and Y marks at the back of the model for reference. The measurements +8. Use X and Y marks at the back of the model for reference. The measurements from the side with X mark should be used for X axis *configuration*, and Y mark - for Y axis configuration. Measure the distance *D* (in mm) between several oscillations on the part with X mark, near the notches, preferably @@ -79,14 +75,14 @@ First, measure the **ringing frequency**. |![Mark ringing](img/ringing-mark.jpg)|![Measure ringing](img/ringing-measure.jpg)| -10. Count how many oscillations *N* the measured distance *D* corresponds to. - If you are unsure how to count the oscillations, refer to the picture - above, which shows *N* = 6 oscillations. -11. Compute the ringing frequency of X axis as *V* · *N* / *D* (Hz), +9. Count how many oscillations *N* the measured distance *D* corresponds to. + If you are unsure how to count the oscillations, refer to the picture + above, which shows *N* = 6 oscillations. +10. Compute the ringing frequency of X axis as *V* · *N* / *D* (Hz), where *V* is the velocity for outer perimeters (mm/sec). For the example above, we marked 6 oscillations, and the test was printed at 100 mm/sec velocity, so the frequency is 100 * 6 / 12.14 ≈ 49.4 Hz. -12. Do (9) - (11) for Y mark as well. +11. Do (8) - (10) for Y mark as well. Note that ringing on the test print should follow the pattern of the curved notches, as in the picture above. If it doesn't, then this defect is not really @@ -150,16 +146,15 @@ For most of the printers, either MZV or EI shapers can be recommended. This section describes a testing process to choose between them, and figure out a few other related parameters. -Print the ringing test model as follows (assuming you already have -shaper_freq_x/y set and max_accel/max_accel_to_decel increased to 7000 in -printer.cfg file): +Print the ringing test model as follows: -1. Restart the firmware: `RESTART`. -2. Disable Pressure Advance: `SET_PRESSURE_ADVANCE ADVANCE=0`. -3. Execute `SET_INPUT_SHAPER SHAPER_TYPE=MZV`. -4. Execute the command - `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1250 FACTOR=100 BAND=5`. -5. Print the test model sliced with the suggested parameters. +1. Restart the firmware: `RESTART` +2. Prepare for test: `SET_VELOCITY_LIMIT ACCEL_TO_DECEL=7000` +3. Disable Pressure Advance: `SET_PRESSURE_ADVANCE ADVANCE=0` +4. Execute: `SET_INPUT_SHAPER SHAPER_TYPE=MZV` +5. Execute the command: + `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1500 STEP_DELTA=500 STEP_HEIGHT=5` +6. Print the test model sliced with the suggested parameters. If you see no ringing at this point, then MZV shaper can be recommended for use. @@ -169,8 +164,8 @@ differ significantly from the values you obtained earlier, a more complex input shaper configuration is needed. You can refer to Technical details of [Input shapers](#input-shapers) section. Otherwise, proceed to the next step. -Now try EI input shaper. To try it, repeat steps (1)-(5) from above, but -executing at step 3 the following command instead: +Now try EI input shaper. To try it, repeat steps (1)-(6) from above, but +executing at step 4 the following command instead: `SET_INPUT_SHAPER SHAPER_TYPE=EI`. Compare two prints with MZV and EI input shaper. If EI shows noticeably better @@ -207,7 +202,7 @@ You should have a printed test for the shaper you chose from the previous step (if you don't, print the test model sliced with the [suggested parameters](#tuning) with the pressure advance disabled `SET_PRESSURE_ADVANCE ADVANCE=0` and with the tuning tower enabled as -`TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1250 FACTOR=100 BAND=5`). +`TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1500 STEP_DELTA=500 STEP_HEIGHT=5`). Note that at very high accelerations, depending on the resonance frequency and the input shaper you chose (e.g. EI shaper creates more smoothing than MZV), input shaping may cause too much smoothing and rounding of the parts. So, @@ -242,8 +237,7 @@ It may also be a result of a miscalibrated (too high) filament flow, so it is a good idea to check that too. Choose the minimum out of the two acceleration values (from ringing and -smoothing), and put it as max_accel into printer.cfg (you can delete -max_accel_to_decel or revert it to the old value). +smoothing), and put it as `max_accel` into printer.cfg. As a note, it may happen - especially at low ringing frequencies - that EI @@ -273,29 +267,29 @@ your choice with the same frequencies as you have measured earlier), you can follow the steps in this section. Note that if you see ringing at different frequencies after enabling [input_shaper], this section will not help with that. -Assuming that you have sliced the ringing model with suggested parameters and -increased `max_accel` and `max_accel_to_decel` parameters in the `printer.cfg` -to 7000 already, complete the following steps for each of the axes X and Y: +Assuming that you have sliced the ringing model with suggested +parameters, complete the following steps for each of the axes X and Y: -1. Make sure Pressure Advance is disabled: `SET_PRESSURE_ADVANCE ADVANCE=0`. -2. Execute `SET_INPUT_SHAPER SHAPER_TYPE=ZV`. -3. From the existing ringing test model with your chosen input shaper select +1. Prepare for test: `SET_VELOCITY_LIMIT ACCEL_TO_DECEL=7000` +2. Make sure Pressure Advance is disabled: `SET_PRESSURE_ADVANCE ADVANCE=0` +3. Execute: `SET_INPUT_SHAPER SHAPER_TYPE=ZV` +4. From the existing ringing test model with your chosen input shaper select the acceleration that shows ringing sufficiently well, and set it with: - `SET_VELOCITY_LIMIT ACCEL=...`. -4. Calculate the necessary parameters for the `TUNING_TOWER` command to tune + `SET_VELOCITY_LIMIT ACCEL=...` +5. Calculate the necessary parameters for the `TUNING_TOWER` command to tune `shaper_freq_x` parameter as follows: start = shaper_freq_x * 83 / 132 and factor = shaper_freq_x / 66, where `shaper_freq_x` here is the current value in `printer.cfg`. -5. Execute the command +6. Execute the command: `TUNING_TOWER COMMAND=SET_INPUT_SHAPER PARAMETER=SHAPER_FREQ_X START=start FACTOR=factor BAND=5` - using `start` and `factor` values calculated at step (4). -6. Print the test model. -7. Reset the original frequency value: + using `start` and `factor` values calculated at step (5). +7. Print the test model. +8. Reset the original frequency value: `SET_INPUT_SHAPER SHAPER_FREQ_X=...`. -8. Find the band which shows ringing the least and count its number from the +9. Find the band which shows ringing the least and count its number from the bottom starting at 1. -9. Calculate the new shaper_freq_x value via old - shaper_freq_x * (39 + 5 * #band-number) / 66. +10. Calculate the new shaper_freq_x value via old + shaper_freq_x * (39 + 5 * #band-number) / 66. Repeat these steps for the Y axis in the same manner, replacing references to X axis with the axis Y (e.g. replace `shaper_freq_x` with `shaper_freq_y` in @@ -312,16 +306,12 @@ After both new `shaper_freq_x` and `shaper_freq_y` parameters have been calculated, you can update `[input_shaper]` section in `printer.cfg` with the new `shaper_freq_x` and `shaper_freq_y` values. -Do not forget to revert the changes to `max_accel` and `max_accel_to_decel` -parameters in the `printer.cfg` after finishing this section. - ### Pressure Advance If you use Pressure Advance, it may need to be re-tuned. Follow the -[instructions](Pressure_Advance.md#tuning-pressure-advance) to find the -new value, if it differs from the previous one. Make sure to restore the -original values of `max_accel` and `max_accel_to_decel` parameters in the -`printer.cfg` and restart Klipper before tuning Pressure Advance. +[instructions](Pressure_Advance.md#tuning-pressure-advance) to find +the new value, if it differs from the previous one. Make sure to +restart Klipper before tuning Pressure Advance. ### Unreliable measurements of ringing frequencies @@ -335,26 +325,26 @@ accelerometer and measure the resonances with it (refer to the process) - but this option requires some crimping and soldering. -For tuning, add empty `[input_shaper]` section to your `printer.cfg`. Then, -assuming that you have sliced the ringing model with suggested parameters and -increased `max_accel` and `max_accel_to_decel` parameters in the `printer.cfg` -to 7000 already, print the test model 3 times as follows. First time, prior to -printing, run +For tuning, add empty `[input_shaper]` section to your +`printer.cfg`. Then, assuming that you have sliced the ringing model +with suggested parameters, print the test model 3 times as +follows. First time, prior to printing, run 1. `RESTART` -2. `SET_PRESSURE_ADVANCE ADVANCE=0`. -3. `SET_INPUT_SHAPER SHAPER_TYPE=2HUMP_EI SHAPER_FREQ_X=60 SHAPER_FREQ_Y=60`. -4. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1250 FACTOR=100 BAND=5`. +2. `SET_VELOCITY_LIMIT ACCEL_TO_DECEL=7000` +3. `SET_PRESSURE_ADVANCE ADVANCE=0` +4. `SET_INPUT_SHAPER SHAPER_TYPE=2HUMP_EI SHAPER_FREQ_X=60 SHAPER_FREQ_Y=60` +5. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1500 STEP_DELTA=500 STEP_HEIGHT=5` and print the model. Then print the model again, but before printing run instead -1. `SET_INPUT_SHAPER SHAPER_TYPE=2HUMP_EI SHAPER_FREQ_X=50 SHAPER_FREQ_Y=50`. -2. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1250 FACTOR=100 BAND=5`. +1. `SET_INPUT_SHAPER SHAPER_TYPE=2HUMP_EI SHAPER_FREQ_X=50 SHAPER_FREQ_Y=50` +2. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1500 STEP_DELTA=500 STEP_HEIGHT=5` Then print the model for the 3rd time, but now run -1. `SET_INPUT_SHAPER SHAPER_TYPE=2HUMP_EI SHAPER_FREQ_X=40 SHAPER_FREQ_Y=40`. -2. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1250 FACTOR=100 BAND=5`. +1. `SET_INPUT_SHAPER SHAPER_TYPE=2HUMP_EI SHAPER_FREQ_X=40 SHAPER_FREQ_Y=40` +2. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1500 STEP_DELTA=500 STEP_HEIGHT=5` Essentially, we are printing the ringing test model with TUNING_TOWER using 2HUMP_EI shaper with shaper_freq = 60 Hz, 50 Hz, and 40 Hz. @@ -377,8 +367,8 @@ frequency based on the frequency of 2HUMP_EI shaper you chose: Now print the test model one more time, running -1. `SET_INPUT_SHAPER SHAPER_TYPE=EI SHAPER_FREQ_X=... SHAPER_FREQ_Y=...`. -2. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1250 FACTOR=100 BAND=5`. +1. `SET_INPUT_SHAPER SHAPER_TYPE=EI SHAPER_FREQ_X=... SHAPER_FREQ_Y=...` +2. `TUNING_TOWER COMMAND=SET_VELOCITY_LIMIT PARAMETER=ACCEL START=1500 STEP_DELTA=500 STEP_HEIGHT=5` providing the shaper_freq_x=... and shaper_freq_y=... as determined previously. From c80552f9e7750d8d425888b7809b5af5bdcf9b74 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 29 Jan 2022 12:54:07 -0500 Subject: [PATCH 039/211] docs: Reorganize layout of G-Codes.md Break listing up by module name. Provide links to "extended" commands. Sort reference by module name. Signed-off-by: Kevin O'Connor --- docs/Config_Reference.md | 83 +- docs/G-Codes.md | 1847 +++++++++++++---------- docs/Hall_Filament_Width_Sensor.md | 2 +- docs/Measuring_Resonances.md | 9 +- docs/Probe_Calibrate.md | 12 +- docs/TMC_Drivers.md | 12 +- docs/TSL1401CL_Filament_Width_Sensor.md | 2 +- 7 files changed, 1108 insertions(+), 859 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index f7781484..f4b36e70 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -788,8 +788,7 @@ recommended to define a safe_z_home section in printer.cfg to home toward the center of the print area. See the [bed mesh guide](Bed_Mesh.md) and -[command reference](G-Codes.md#mesh-bed-leveling) for additional -information. +[command reference](G-Codes.md#bed_mesh) for additional information. Visual Examples: ``` @@ -903,7 +902,7 @@ Bed tilt compensation. One may define a bed_tilt config section to enable move transformations that account for a tilted bed. Note that bed_mesh and bed_tilt are incompatible; both cannot be defined. -See the [command reference](G-Codes.md#bed-tilt) for additional +See the [command reference](G-Codes.md#bed_tilt) for additional information. ``` @@ -941,8 +940,7 @@ config section to enable a BED_SCREWS_ADJUST g-code command. See the [leveling guide](Manual_Level.md#adjusting-bed-leveling-screws) and -[command reference](G-Codes.md#bed-screws-helper) for additional -information. +[command reference](G-Codes.md#bed_screws) for additional information. ``` [bed_screws] @@ -987,8 +985,8 @@ g-code command. See the [leveling guide](Manual_Level.md#adjusting-bed-leveling-screws-using-the-bed-probe) -and [command reference](G-Codes.md#bed-screws-tilt-adjust-helper) for -additional information. +and [command reference](G-Codes.md#screws_tilt_adjust) for additional +information. ``` [screws_tilt_adjust] @@ -1027,7 +1025,7 @@ additional information. Multiple Z stepper tilt adjustment. This feature enables independent adjustment of multiple z steppers (see the "stepper_z1" section) to adjust for tilt. If this section is present then a Z_TILT_ADJUST -extended [G-Code command](G-Codes.md#z-tilt) becomes available. +extended [G-Code command](G-Codes.md#z_tilt) becomes available. ``` [z_tilt] @@ -1120,7 +1118,7 @@ printer skew across 3 planes, xy, xz, yz. This is done by printing a calibration model along a plane and measuring three lengths. Due to the nature of skew correction these lengths are set via gcode. See [Skew Correction](Skew_Correction.md) and -[Command Reference](G-Codes.md#skew-correction) for details. +[Command Reference](G-Codes.md#skew_correction) for details. ``` [skew_correction] @@ -1199,8 +1197,8 @@ endstop switches. Add a bare "[endstop_phase]" declaration to enable the ENDSTOP_PHASE_CALIBRATE command. See the [endstop phases guide](Endstop_Phase.md) and -[command reference](G-Codes.md#endstop-adjustments-by-stepper-phase) -for additional information. +[command reference](G-Codes.md#endstop_phase) for additional +information. ``` [endstop_phase stepper_z] @@ -1265,7 +1263,7 @@ G-Code macros (one may define any number of sections with a Execute a gcode on a set delay. See the [command template guide](Command_Templates.md#delayed-gcodes) and -[command reference](G-Codes.md#delayed-gcode) for more information. +[command reference](G-Codes.md#delayed_gcode) for more information. ``` [delayed_gcode my_delayed_gcode] @@ -1287,7 +1285,7 @@ gcode: Support saving variables to disk so that they are retained across restarts. See [command templates](Command_Templates.md#save-variables-to-disk) and -[G-Code reference](G-Codes.md#save-variables) for further information. +[G-Code reference](G-Codes.md#save_variables) for further information. ``` [save_variables] @@ -1338,7 +1336,7 @@ a belt printer, can find use in looping sections of the sdcard file. (For example, to print the same part over and over, or repeat the a section of a part for a chain or other repeated pattern). -See the [command reference](G-Codes.md#sdcard-loop) for supported +See the [command reference](G-Codes.md#sdcard_loop) for supported commands. See the [sample-macros.cfg](../config/sample-macros.cfg) file for a Marlin compatible M808 G-Code macro. @@ -1350,7 +1348,7 @@ file for a Marlin compatible M808 G-Code macro. Support manually moving stepper motors for diagnostic purposes. Note, using this feature may place the printer in an invalid state - see the -[command reference](G-Codes.md#force-movement) for important details. +[command reference](G-Codes.md#force_move) for important details. ``` [force_move] @@ -1362,7 +1360,7 @@ using this feature may place the printer in an invalid state - see the ### [pause_resume] Pause/Resume functionality with support of position capture and -restore. See the [command reference](G-Codes.md#pause-resume) for more +restore. See the [command reference](G-Codes.md#pause_resume) for more information. ``` @@ -1377,7 +1375,7 @@ information. Firmware filament retraction. This enables G10 (retract) and G11 (unretract) GCODE commands issued by many slicers. The parameters below provide startup defaults, although the values can be adjusted -via the SET_RETRACTION [command](G-Codes.md#firmware-retraction)), +via the SET_RETRACTION [command](G-Codes.md#firmware_retraction)), allowing per-filament settings and runtime tuning. ``` @@ -1412,7 +1410,7 @@ Support for gcode arc (G2/G3) commands. ### [respond] Enable the "M118" and "RESPOND" extended -[commands](G-Codes.md#send-message-respond-to-host). +[commands](G-Codes.md#respond). ``` [respond] @@ -1432,7 +1430,7 @@ Enable the "M118" and "RESPOND" extended ### [input_shaper] Enables [resonance compensation](Resonance_Compensation.md). Also see -the [command reference](G-Codes.md#resonance-compensation). +the [command reference](G-Codes.md#input_shaper). ``` [input_shaper] @@ -1471,10 +1469,9 @@ the [command reference](G-Codes.md#resonance-compensation). Support for ADXL345 accelerometers. This support allows one to query accelerometer measurements from the sensor. This enables an -ACCELEROMETER_MEASURE command (see -[G-Codes](G-Codes.md#adxl345-accelerometer-commands) for more -information). The default chip name is "default", but one may specify -an explicit name (eg, [adxl345 my_chip_name]). +ACCELEROMETER_MEASURE command (see [G-Codes](G-Codes.md#adxl345) for +more information). The default chip name is "default", but one may +specify an explicit name (eg, [adxl345 my_chip_name]). ``` [adxl345] @@ -1510,7 +1507,7 @@ Support for resonance testing and automatic input shaper calibration. In order to use most of the functionality of this module, additional software dependencies must be installed; refer to [Measuring Resonances](Measuring_Resonances.md) and the -[command reference](G-Codes.md#resonance-testing-commands) for more +[command reference](G-Codes.md#resonance_tester) for more information. See the [Max smoothing](Measuring_Resonances.md#max-smoothing) section of the measuring resonances guide for more information on `max_smoothing` parameter and its use. @@ -1829,8 +1826,7 @@ Support for additional steppers synchronized to the movement of an extruder (one may define any number of sections with an "extruder_stepper" prefix). -See the [command reference](G-Codes.md#extruder-stepper-commands) for -more information. +See the [command reference](G-Codes.md#extruder) for more information. ``` [extruder_stepper my_extra_stepper] @@ -1853,9 +1849,9 @@ Manual steppers (one may define any number of sections with a "manual_stepper" prefix). These are steppers that are controlled by the MANUAL_STEPPER g-code command. For example: "MANUAL_STEPPER STEPPER=my_stepper MOVE=10 SPEED=5". See -[G-Codes](G-Codes.md#manual-stepper-commands) file for a description -of the MANUAL_STEPPER command. The steppers are not connected to the -normal printer kinematics. +[G-Codes](G-Codes.md#manual_stepper) file for a description of the +MANUAL_STEPPER command. The steppers are not connected to the normal +printer kinematics. ``` [manual_stepper my_stepper] @@ -2010,8 +2006,8 @@ section. Generic heaters (one may define any number of sections with a "heater_generic" prefix). These heaters behave similarly to standard heaters (extruders, heated beds). Use the SET_HEATER_TEMPERATURE -command (see [G-Codes](G-Codes.md) for details) to set the target -temperature. +command (see [G-Codes](G-Codes.md#heaters) for details) to set the +target temperature. ``` [heater_generic my_generic_heater] @@ -2445,8 +2441,8 @@ fan that will be enabled whenever its associated sensor is above a set temperature. By default, a temperature_fan has a shutdown_speed equal to max_power. -See the [command reference](G-Codes.md#temperature-fan-commands) for -additional information. +See the [command reference](G-Codes.md#temperature_fan) for additional +information. ``` [temperature_fan my_temp_fan] @@ -2492,8 +2488,7 @@ additional information. Manually controlled fan (one may define any number of sections with a "fan_generic" prefix). The speed of a manually controlled fan is set -with the SET_FAN_SPEED -[gcode command](G-Codes.md#manually-controlled-fans-commands). +with the SET_FAN_SPEED [gcode command](G-Codes.md#fan_generic). ``` [fan_generic extruder_partfan] @@ -2516,7 +2511,7 @@ with the SET_FAN_SPEED Servos (one may define any number of sections with a "servo" prefix). The servos may be controlled using the SET_SERVO -[g-code command](G-Codes.md#servo-commands). For example: SET_SERVO +[g-code command](G-Codes.md#servo). For example: SET_SERVO SERVO=my_servo ANGLE=180 ``` @@ -2548,7 +2543,7 @@ pin: Neopixel (aka WS2812) LED support (one may define any number of sections with a "neopixel" prefix). One may set the LED color via "SET_LED LED=my_neopixel RED=0.1 GREEN=0.1 BLUE=0.1" type extended -[g-code commands](G-Codes.md#neopixel-and-dotstar-commands). +[g-code commands](G-Codes.md#neopixel). ``` [neopixel my_neopixel] @@ -2576,7 +2571,7 @@ pin: Dotstar (aka APA102) LED support (one may define any number of sections with a "dotstar" prefix). One may set the LED color via "SET_LED LED=my_dotstar RED=0.1 GREEN=0.1 BLUE=0.1" type extended -[g-code commands](G-Codes.md#neopixel-and-dotstar-commands). +[g-code commands](G-Codes.md#neopixel). ``` [dotstar my_dotstar] @@ -2651,7 +2646,7 @@ Run-time configurable output pins (one may define any number of sections with an "output_pin" prefix). Pins configured here will be setup as output pins and one may modify them at run-time using "SET_PIN PIN=my_pin VALUE=.1" type extended -[g-code commands](G-Codes.md#custom-pin-commands). +[g-code commands](G-Codes.md#output_pin). ``` [output_pin my_pin] @@ -2738,7 +2733,7 @@ pins: Configuration of Trinamic stepper motor drivers in UART/SPI mode. Additional information is in the [TMC Drivers guide](TMC_Drivers.md) -and in the [command reference](G-Codes.md#tmc-stepper-drivers). +and in the [command reference](G-Codes.md#tmcxxxx). ### [tmc2130] @@ -3663,8 +3658,8 @@ information on menu attributes available during template rendering. Filament Switch Sensor. Support for filament insert and runout detection using a switch sensor, such as an endstop switch. -See the [command reference](G-Codes.md#filament-sensor) for more -information. +See the [command reference](G-Codes.md#filament_switch_sensor) for +more information. ``` [filament_switch_sensor my_sensor] @@ -3703,8 +3698,8 @@ Filament Motion Sensor. Support for filament insert and runout detection using an encoder that toggles the output pin during filament movement through the sensor. -See the [command reference](G-Codes.md#filament-sensor) for more -information. +See the [command reference](G-Codes.md#filament_switch_sensor) for +more information. ``` [filament_motion_sensor my_sensor] diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 6450f0ef..6b903342 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -50,9 +50,1044 @@ to implement it with a custom example, one might use this to implement: `G12`, `G29`, `G30`, `G31`, `M42`, `M80`, `M81`, `T1`, etc. -### G-Code SD card commands +## Additional Commands -Klipper also supports the following standard G-Code commands if the +Klipper uses "extended" G-Code commands for general configuration and +status. These extended commands all follow a similar format - they +start with a command name and may be followed by one or more +parameters. For example: `SET_SERVO SERVO=myservo ANGLE=5.3`. In this +document, the commands and parameters are shown in uppercase, however +they are not case sensitive. (So, "SET_SERVO" and "set_servo" both run +the same command.) + +This section is organized my Klipper module name, which generally +follows the section names specified in the +[printer configuration file](Config_Reference.md). Note that some +modules are automatically loaded. + +### [adxl345] + +The following commands are available when an +[adxl345 config section](Config_Reference.md#adxl345) is enabled. + +#### ACCELEROMETER_MEASURE +`ACCELEROMETER_MEASURE [CHIP=] [NAME=]`: Starts +accelerometer measurements at the requested number of samples per +second. If CHIP is not specified it defaults to "adxl345". The command +works in a start-stop mode: when executed for the first time, it +starts the measurements, next execution stops them. The results of +measurements are written to a file named +`/tmp/adxl345--.csv` where `` is the name of the +accelerometer chip (`my_chip_name` from `[adxl345 my_chip_name]`) and +`` is the optional NAME parameter. If NAME is not specified it +defaults to the current time in "YYYYMMDD_HHMMSS" format. If the +accelerometer does not have a name in its config section (simply +`[adxl345]`) then `` part of the name is not generated. + +#### ACCELEROMETER_QUERY +`ACCELEROMETER_QUERY [CHIP=] [RATE=]`: queries +accelerometer for the current value. If CHIP is not specified it +defaults to "adxl345". If RATE is not specified, the default value is +used. This command is useful to test the connection to the ADXL345 +accelerometer: one of the returned values should be a free-fall +acceleration (+/- some noise of the chip). + +#### ACCELEROMETER_DEBUG_READ +`ACCELEROMETER_DEBUG_READ [CHIP=] REG=`: +queries ADXL345 register (e.g. 44 or 0x2C). Can be useful +for debugging purposes. + +#### ACCELEROMETER_DEBUG_WRITE +`ACCELEROMETER_DEBUG_WRITE [CHIP=] REG= +VAL=`: Writes raw into a register . Both + and can be a decimal or a hexadecimal integer. Use +with care, and refer to ADXL345 data sheet for the reference. + +### [bed_mesh] + +The following commands are available when the +[bed_mesh config section](Config_Reference.md#bed_mesh) is enabled +(also see the [bed mesh guide](Bed_Mesh.md)). + +#### BED_MESH_CALIBRATE +`BED_MESH_CALIBRATE [METHOD=manual] [=] +[=]`: This command probes the bed using +generated points specified by the parameters in the config. After +probing, a mesh is generated and z-movement is adjusted according to +the mesh. See the PROBE command for details on the optional probe +parameters. If METHOD=manual is specified then the manual probing tool +is activated - see the MANUAL_PROBE command above for details on the +additional commands available while this tool is active. + +#### BED_MESH_OUTPUT +`BED_MESH_OUTPUT PGP=[<0:1>]`: This command outputs the current probed +z values and current mesh values to the terminal. If PGP=1 is +specified the X, Y coordinates generated by bed_mesh, along with their +associated indices, will be output to the terminal. + +#### BED_MESH_MAP +`BED_MESH_MAP`: Like to BED_MESH_OUTPUT, this command prints the +current state of the mesh to the terminal. Instead of printing the +values in a human readable format, the state is serialized in json +format. This allows octoprint plugins to easily capture the data and +generate height maps approximating the bed's surface. + +#### BED_MESH_CLEAR +`BED_MESH_CLEAR`: This command clears the mesh and removes all z +adjustment. It is recommended to put this in your end-gcode. + +#### BED_MESH_PROFILE +`BED_MESH_PROFILE LOAD= SAVE= REMOVE=`: This command +provides profile management for mesh state. LOAD will restore the mesh +state from the profile matching the supplied name. SAVE will save the +current mesh state to a profile matching the supplied name. Remove +will delete the profile matching the supplied name from persistent +memory. Note that after SAVE or REMOVE operations have been run the +SAVE_CONFIG gcode must be run to make the changes to persistent memory +permanent. + +#### BED_MESH_OFFSET +`BED_MESH_OFFSET [X=] [Y=]`: Applies X and/or Y offsets +to the mesh lookup. This is useful for printers with independent +extruders, as an offset is necessary to produce correct Z adjustment +after a tool change. + +### [bed_screws] + +The following commands are available when the +[bed_screws config section](Config_Reference.md#bed_screws) is enabled +(also see the +[manual level guide](Manual_Level.md#adjusting-bed-leveling-screws)). + +#### BED_SCREWS_ADJUST +`BED_SCREWS_ADJUST`: This command will invoke the bed screws +adjustment tool. It will command the nozzle to different locations (as +defined in the config file) and allow one to make adjustments to the +bed screws so that the bed is a constant distance from the nozzle. + +### [bed_tilt] + +The following commands are available when the +[bed_tilt config section](Config_Reference.md#bed_tilt) is enabled. + +#### BED_TILT_CALIBRATE +`BED_TILT_CALIBRATE [METHOD=manual] [=]`: This +command will probe the points specified in the config and then +recommend updated x and y tilt adjustments. See the PROBE command for +details on the optional probe parameters. If METHOD=manual is +specified then the manual probing tool is activated - see the +MANUAL_PROBE command above for details on the additional commands +available while this tool is active. + +### [bltouch] + +The following command is available when a +[bltouch config section](Config_Reference.md#bltouch) is enabled (also +see the [BL-Touch guide](BLTouch.md)). + +#### BLTOUCH_DEBUG +`BLTOUCH_DEBUG COMMAND=`: This sends a command to the +BLTouch. It may be useful for debugging. Available commands are: +`pin_down`, `touch_mode`, `pin_up`, `self_test`, `reset`. A BL-Touch +V3.0 or V3.1 may also support `set_5V_output_mode`, +`set_OD_output_mode`, `output_mode_store` commands. + +#### BLTOUCH_STORE +`BLTOUCH_STORE MODE=`: This stores an output mode in the +EEPROM of a BLTouch V3.1 Available output_modes are: `5V`, `OD` + +### [configfile] + +The configfile module is automatically loaded. + +#### SAVE_CONFIG +`SAVE_CONFIG`: This command will overwrite the main printer config +file and restart the host software. This command is used in +conjunction with other calibration commands to store the results of +calibration tests. + +### [delayed_gcode] + +The following command is enabled if a +[delayed_gcode config section](Config_Reference.md#delayed_gcode) has +been enabled (also see the +[template guide](Command_Templates.md#delayed-gcodes)). + +#### UPDATE_DELAYED_GCODE +`UPDATE_DELAYED_GCODE [ID=] [DURATION=]`: Updates the +delay duration for the identified [delayed_gcode] and starts the timer +for gcode execution. A value of 0 will cancel a pending delayed gcode +from executing. + +### [delta_calibrate] + +The following commands are available when the +[delta_calibrate config section](Config_Reference.md#linear-delta-kinematics) +is enabled (also see the [delta calibrate guide](Delta_Calibrate.md)). + +#### DELTA_CALIBRATE +`DELTA_CALIBRATE [METHOD=manual] [=]`: This +command will probe seven points on the bed and recommend updated +endstop positions, tower angles, and radius. See the PROBE command for +details on the optional probe parameters. If METHOD=manual is +specified then the manual probing tool is activated - see the +MANUAL_PROBE command above for details on the additional commands +available while this tool is active. + +#### DELTA_ANALYZE +`DELTA_ANALYZE`: This command is used during enhanced delta +calibration. See [Delta Calibrate](Delta_Calibrate.md) for details. + +### [display] + +The following command is available when a +[display config section](Config_Reference.md#gcode_macro) is enabled. + +#### SET_DISPLAY_GROUP +`SET_DISPLAY_GROUP [DISPLAY=] GROUP=`: Set the active +display group of an lcd display. This allows to define multiple +display data groups in the config, e.g. `[display_data +]` and switch between them using this extended gcode +command. If DISPLAY is not specified it defaults to "display" (the +primary display). + +### [display_status] + +The display_status module is automatically loaded if a +[display config section](Config_Reference.md#display) is enabled. It +provides the following standard G-Code commands: +- Display Message: `M117 ` +- Set build percentage: `M73 P` + +### [dual_carriage] + +The following command is available when the +[dual_carriage config section](Config_Reference.md#dual_carriage) is +enabled. + +#### SET_DUAL_CARRIAGE +`SET_DUAL_CARRIAGE CARRIAGE=[0|1]`: This command will set the active +carriage. It is typically invoked from the activate_gcode and +deactivate_gcode fields in a multiple extruder configuration. + +### [endstop_phase] + +The following commands are available when an +[endstop_phase config section](Config_Reference.md#endstop_phase) is +enabled (also see the [endstop phase guide](Endstop_Phase.md)). + +#### ENDSTOP_PHASE_CALIBRATE +`ENDSTOP_PHASE_CALIBRATE [STEPPER=]`: If no STEPPER +parameter is provided then this command will reports statistics on +endstop stepper phases during past homing operations. When a STEPPER +parameter is provided it arranges for the given endstop phase setting +to be written to the config file (in conjunction with the SAVE_CONFIG +command). + +### [extruder] + +The following commands are available if an +[extruder config section](Config_Reference.md#extruder) is enabled: + +#### ACTIVATE_EXTRUDER +`ACTIVATE_EXTRUDER EXTRUDER=`: In a printer with multiple +extruders this command is used to change the active extruder. + +#### SET_PRESSURE_ADVANCE +`SET_PRESSURE_ADVANCE [EXTRUDER=] +[ADVANCE=] +[SMOOTH_TIME=]`: Set pressure advance +parameters. If EXTRUDER is not specified, it defaults to the active +extruder. + +#### SET_EXTRUDER_STEP_DISTANCE +`SET_EXTRUDER_STEP_DISTANCE [EXTRUDER=] +[DISTANCE=]`: Set a new value for the provided extruder's +"step distance". The "step distance" is +`rotation_distance/(full_steps_per_rotation*microsteps)`. Value is not +retained on Klipper reset. Use with caution, small changes can result +in excessive pressure between extruder and hot end. Do proper +calibration steps with filament before use. If 'DISTANCE' value is not +included command will return current step distance. + +#### SYNC_STEPPER_TO_EXTRUDER +`SYNC_STEPPER_TO_EXTRUDER STEPPER= [EXTRUDER=]`: This +command will cause the given extruder STEPPER (as specified in an +[extruder](Config_Reference#extruder) or +[extruder stepper](Config_Reference#extruder_stepper) config section) +to become synchronized to the given EXTRUDER. If EXTRUDER is an empty +string then the stepper will not be synchronized to an extruder. + +### [fan_generic] + +The following command is available when a +[fan_generic config section](Config_Reference.md#fan_generic) is +enabled. + +#### SET_FAN_SPEED +`SET_FAN_SPEED FAN=config_name SPEED=` This command sets the +speed of a fan. must be between 0.0 and 1.0. + +### [firmware_retraction] + +The following standard G-Code commands are available when the +[firmware_retraction config section](Config_Reference.md#firmware_retraction) +is enabled. These commands allow you to utilize the firmware +retraction feature available in many slicers, to reduce stringing +during non-extrusion moves from one part of the print to another. +Appropriately configuring pressure advance reduces the length of +retraction required. +- `G10`: Retracts the extruder using the currently configured + parameters. +- `G11`: Unretracts the extruder using the currently configured + parameters. + +The following additional commands are also available. + +#### SET_RETRACTION +`SET_RETRACTION [RETRACT_LENGTH=] [RETRACT_SPEED=] +[UNRETRACT_EXTRA_LENGTH=] [UNRETRACT_SPEED=]`: Adjust the +parameters used by firmware retraction. RETRACT_LENGTH determines the +length of filament to retract and unretract. The speed of retraction +is adjusted via RETRACT_SPEED, and is typically set relatively +high. The speed of unretraction is adjusted via UNRETRACT_SPEED, and +is not particularly critical, although often lower than RETRACT_SPEED. +In some cases it is useful to add a small amount of additional length +on unretraction, and this is set via UNRETRACT_EXTRA_LENGTH. +SET_RETRACTION is commonly set as part of slicer per-filament +configuration, as different filaments require different parameter +settings. + +#### GET_RETRACTION +`GET_RETRACTION`: Queries the current parameters used by firmware +retraction and displays them on the terminal. + +### [filament_switch_sensor] + +The following command is available when a +[filament_switch_sensor](Config_Reference.md#filament_switch_sensor) +or +[filament_motion_sensor](Config_Reference.md#filament_motion_sensor) +config section is enabled. + +#### QUERY_FILAMENT_SENSOR +`QUERY_FILAMENT_SENSOR SENSOR=`: Queries the current +status of the filament sensor. The data displayed on the terminal will +depend on the sensor type defined in the configuration. + +#### SET_FILAMENT_SENSOR +`SET_FILAMENT_SENSOR SENSOR= ENABLE=[0|1]`: Sets the +filament sensor on/off. If ENABLE is set to 0, the filament sensor +will be disabled, if set to 1 it is enabled. + +### [firmware_retraction] + +The following standard G-Code commands are available if a +[firmware_retraction config section](Config_Reference.md#firmware_retraction) +is enabled: +- Retract: `G10` +- Unretract: `G11` + +### [force_move] + +The force_move module is automatically loaded, however some commands +require setting `enable_force_move` in the +[printer config](Config_Reference#force_move). + +#### STEPPER_BUZZ +`STEPPER_BUZZ STEPPER=`: Move the given stepper forward +one mm and then backward one mm, repeated 10 times. This is a +diagnostic tool to help verify stepper connectivity. + +#### FORCE_MOVE +`FORCE_MOVE STEPPER= DISTANCE= VELOCITY= +[ACCEL=]`: This command will forcibly move the given stepper +the given distance (in mm) at the given constant velocity (in mm/s). +If ACCEL is specified and is greater than zero, then the given +acceleration (in mm/s^2) will be used; otherwise no acceleration is +performed. No boundary checks are performed; no kinematic updates are +made; other parallel steppers on an axis will not be moved. Use +caution as an incorrect command could cause damage! Using this command +will almost certainly place the low-level kinematics in an incorrect +state; issue a G28 afterwards to reset the kinematics. This command is +intended for low-level diagnostics and debugging. + +#### SET_KINEMATIC_POSITION +`SET_KINEMATIC_POSITION [X=] [Y=] [Z=]`: Force +the low-level kinematic code to believe the toolhead is at the given +cartesian position. This is a diagnostic and debugging command; use +SET_GCODE_OFFSET and/or G92 for regular axis transformations. If an +axis is not specified then it will default to the position that the +head was last commanded to. Setting an incorrect or invalid position +may lead to internal software errors. This command may invalidate +future boundary checks; issue a G28 afterwards to reset the +kinematics. + +### [gcode] + +The gcode module is automatically loaded. + +#### RESTART +`RESTART`: This will cause the host software to reload its config and +perform an internal reset. This command will not clear error state +from the micro-controller (see FIRMWARE_RESTART) nor will it load new +software (see +[the FAQ](FAQ.md#how-do-i-upgrade-to-the-latest-software)). + +#### FIRMWARE_RESTART +`FIRMWARE_RESTART`: This is similar to a RESTART command, but it also +clears any error state from the micro-controller. + +#### STATUS +`STATUS`: Report the Klipper host software status. + +#### HELP +`HELP`: Report the list of available extended G-Code commands. + +### [gcode_arcs] + +The following standard G-Code commands are available if a +[gcode_arcs config section](Config_Reference.md#gcode_arcs) is +enabled: +- Controlled Arc Move (G2 or G3): `G2 [X] [Y] [Z] + [E] [F] I J` + +### [gcode_macro] + +The following command is available when a +[gcode_macro config section](Config_Reference.md#gcode_macro) is +enabled (also see the +[command templates guide](Command_Templates.md)). + +#### SET_GCODE_VARIABLE +`SET_GCODE_VARIABLE MACRO= VARIABLE= VALUE=`: +This command allows one to change the value of a gcode_macro variable +at run-time. The provided VALUE is parsed as a Python literal. + +### [gcode_move] + +The gcode_move module is automatically loaded. + +#### GET_POSITION +`GET_POSITION`: Return information on the current location of the +toolhead. + +#### SET_GCODE_OFFSET +`SET_GCODE_OFFSET [X=|X_ADJUST=] +[Y=|Y_ADJUST=] [Z=|Z_ADJUST=] [MOVE=1 +[MOVE_SPEED=]]`: Set a positional offset to apply to future +G-Code commands. This is commonly used to virtually change the Z bed +offset or to set nozzle XY offsets when switching extruders. For +example, if "SET_GCODE_OFFSET Z=0.2" is sent, then future G-Code moves +will have 0.2mm added to their Z height. If the X_ADJUST style +parameters are used, then the adjustment will be added to any existing +offset (eg, "SET_GCODE_OFFSET Z=-0.2" followed by "SET_GCODE_OFFSET +Z_ADJUST=0.3" would result in a total Z offset of 0.1). If "MOVE=1" is +specified then a toolhead move will be issued to apply the given +offset (otherwise the offset will take effect on the next absolute +G-Code move that specifies the given axis). If "MOVE_SPEED" is +specified then the toolhead move will be performed with the given +speed (in mm/s); otherwise the toolhead move will use the last +specified G-Code speed. + +#### SAVE_GCODE_STATE +`SAVE_GCODE_STATE [NAME=]`: Save the current g-code +coordinate parsing state. Saving and restoring the g-code state is +useful in scripts and macros. This command saves the current g-code +absolute coordinate mode (G90/G91), absolute extrude mode (M82/M83), +origin (G92), offset (SET_GCODE_OFFSET), speed override (M220), +extruder override (M221), move speed, current XYZ position, and +relative extruder "E" position. If NAME is provided it allows one to +name the saved state to the given string. If NAME is not provided it +defaults to "default". + +#### RESTORE_GCODE_STATE +`RESTORE_GCODE_STATE [NAME=] [MOVE=1 +[MOVE_SPEED=]]`: Restore a state previously saved via +SAVE_GCODE_STATE. If "MOVE=1" is specified then a toolhead move will +be issued to move back to the previous XYZ position. If "MOVE_SPEED" +is specified then the toolhead move will be performed with the given +speed (in mm/s); otherwise the toolhead move will use the restored +g-code speed. + +### [hall_filament_width_sensor] + +The following commands are available when the +[tsl1401cl filament width sensor config section](Config_Reference.md#tsl1401cl_filament_width_sensor) +or [hall filament width sensor config section](Config_Reference.md#hall_filament_width_sensor) +is enabled (also see [TSLl401CL Filament Width Sensor](TSL1401CL_Filament_Width_Sensor.md) +and [Hall Filament Width Sensor](Hall_Filament_Width_Sensor.md)): + +#### QUERY_FILAMENT_WIDTH +`QUERY_FILAMENT_WIDTH`: Return the current measured filament width. + +#### RESET_FILAMENT_WIDTH_SENSOR +`RESET_FILAMENT_WIDTH_SENSOR`: Clear all sensor readings. Helpful +after filament change. + +#### DISABLE_FILAMENT_WIDTH_SENSOR +`DISABLE_FILAMENT_WIDTH_SENSOR`: Turn off the filament width sensor +and stop using it for flow control. + +#### ENABLE_FILAMENT_WIDTH_SENSOR +`ENABLE_FILAMENT_WIDTH_SENSOR`: Turn on the filament width sensor and +start using it for flow control. + +#### QUERY_RAW_FILAMENT_WIDTH +`QUERY_RAW_FILAMENT_WIDTH`: Return the current ADC channel readings +and RAW sensor value for calibration points. + +#### ENABLE_FILAMENT_WIDTH_LOG +`ENABLE_FILAMENT_WIDTH_LOG`: Turn on diameter logging. + +#### DISABLE_FILAMENT_WIDTH_LOG +`DISABLE_FILAMENT_WIDTH_LOG`: Turn off diameter logging. + +### [heaters] + +The heaters module is automatically loaded if a heater is defined in +the config file. + +#### TURN_OFF_HEATERS +`TURN_OFF_HEATERS`: Turn off all heaters. + +#### TEMPERATURE_WAIT +`TEMPERATURE_WAIT SENSOR= [MINIMUM=] +[MAXIMUM=]`: Wait until the given temperature sensor is at or +above the supplied MINIMUM and/or at or below the supplied MAXIMUM. + +#### SET_HEATER_TEMPERATURE +`SET_HEATER_TEMPERATURE HEATER= +[TARGET=]`: Sets the target temperature for a +heater. If a target temperature is not supplied, the target is 0. + +### [idle_timeout] + +The idle_timeout module is automatically loaded. + +#### SET_IDLE_TIMEOUT +`SET_IDLE_TIMEOUT [TIMEOUT=]`: Allows the user to set the +idle timeout (in seconds). + +### [input_shaper] + +The following command is enabled if an +[input_shaper config section](Config_Reference.md#input_shaper) has +been enabled (also see the +[resonance compensation guide](Resonance_Compensation.md)). + +#### SET_INPUT_SHAPER +`SET_INPUT_SHAPER [SHAPER_FREQ_X=] +[SHAPER_FREQ_Y=] [DAMPING_RATIO_X=] +[DAMPING_RATIO_Y=] [SHAPER_TYPE=] +[SHAPER_TYPE_X=] [SHAPER_TYPE_Y=]`: +Modify input shaper parameters. Note that SHAPER_TYPE parameter resets +input shaper for both X and Y axes even if different shaper types have +been configured in [input_shaper] section. SHAPER_TYPE cannot be used +together with either of SHAPER_TYPE_X and SHAPER_TYPE_Y parameters. +See [config reference](Config_Reference.md#input_shaper) for more +details on each of these parameters. + +### [manual_probe] + +The manual_probe module is automatically loaded. + +#### MANUAL_PROBE +`MANUAL_PROBE [SPEED=]`: Run a helper script useful for +measuring the height of the nozzle at a given location. If SPEED is +specified, it sets the speed of TESTZ commands (the default is +5mm/s). During a manual probe, the following additional commands are +available: +- `ACCEPT`: This command accepts the current Z position and concludes + the manual probing tool. +- `ABORT`: This command terminates the manual probing tool. +- `TESTZ Z=`: This command moves the nozzle up or down by the + amount specified in "value". For example, `TESTZ Z=-.1` would move + the nozzle down .1mm while `TESTZ Z=.1` would move the nozzle up + .1mm. The value may also be `+`, `-`, `++`, or `--` to move the + nozzle up or down an amount relative to previous attempts. + +#### Z_ENDSTOP_CALIBRATE +`Z_ENDSTOP_CALIBRATE [SPEED=]`: Run a helper script useful for +calibrating a Z position_endstop config setting. See the MANUAL_PROBE +command for details on the parameters and the additional commands +available while the tool is active. + +#### Z_OFFSET_APPLY_ENDSTOP +`Z_OFFSET_APPLY_ENDSTOP`: Take the current Z Gcode offset (aka, +babystepping), and subtract it from the stepper_z endstop_position. +This acts to take a frequently used babystepping value, and "make it +permanent". Requires a `SAVE_CONFIG` to take effect. + +### [manual_stepper] + +The following command is available when a +[manual_stepper config section](Config_Reference.md#manual_stepper) is +enabled. + +#### MANUAL_STEPPER +`MANUAL_STEPPER STEPPER=config_name [ENABLE=[0|1]] +[SET_POSITION=] [SPEED=] [ACCEL=] [MOVE= +[STOP_ON_ENDSTOP=[1|2|-1|-2]] [SYNC=0]]`: This command will alter the +state of the stepper. Use the ENABLE parameter to enable/disable the +stepper. Use the SET_POSITION parameter to force the stepper to think +it is at the given position. Use the MOVE parameter to request a +movement to the given position. If SPEED and/or ACCEL is specified +then the given values will be used instead of the defaults specified +in the config file. If an ACCEL of zero is specified then no +acceleration will be performed. If STOP_ON_ENDSTOP=1 is specified then +the move will end early should the endstop report as triggered (use +STOP_ON_ENDSTOP=2 to complete the move without error even if the +endstop does not trigger, use -1 or -2 to stop when the endstop +reports not triggered). Normally future G-Code commands will be +scheduled to run after the stepper move completes, however if a manual +stepper move uses SYNC=0 then future G-Code movement commands may run +in parallel with the stepper movement. + +### [neopixel] + +The following command is available when a +[neopixel config section](Config_Reference.md#neopixel) or +[dotstar config section](Config_Reference.md#dotstar) is enabled. + +#### SET_LED +`SET_LED LED= RED= GREEN= BLUE= +WHITE= [INDEX=] [TRANSMIT=0] [SYNC=1]`: This sets the +LED output. Each color `` must be between 0.0 and 1.0. The +WHITE option is only valid on RGBW LEDs. If multiple LED chips are +daisy-chained then one may specify INDEX to alter the color of just +the given chip (1 for the first chip, 2 for the second, etc.). If +INDEX is not provided then all LEDs in the daisy-chain will be set to +the provided color. If TRANSMIT=0 is specified then the color change +will only be made on the next SET_LED command that does not specify +TRANSMIT=0; this may be useful in combination with the INDEX parameter +to batch multiple updates in a daisy-chain. By default, the SET_LED +command will sync it's changes with other ongoing gcode commands. +This can lead to undesirable behavior if LEDs are being set while the +printer is not printing as it will reset the idle timeout. If careful +timing is not needed, the optional SYNC=0 parameter can be specified +to apply the changes instantly and not reset the idle timeout. + +### [output_pin] + +The following command is available when an +[output_pin config section](Config_Reference.md#output_pin) is +enabled. + +#### SET_PIN +`SET_PIN PIN=config_name VALUE= CYCLE_TIME=`: +Note - hardware PWM does not currently support the CYCLE_TIME +parameter and will use the cycle time defined in the config. + +### [palette2] + +The following commands are available when the +[palette2 config section](Config_Reference.md#palette2) is enabled. + +Palette prints work by embedding special OCodes (Omega Codes) in the +GCode file: +- `O1`...`O32`: These codes are read from the GCode stream and processed + by this module and passed to the Palette 2 device. + +The following additional commands are also available. + +#### PALETTE_CONNECT +`PALETTE_CONNECT`: This command initializes the connection with the +Palette 2. + +#### PALETTE_DISCONNECT +`PALETTE_DISCONNECT`: This command disconnects from the Palette 2. + +#### PALETTE_CLEAR +`PALETTE_CLEAR`: This command instructs the Palette 2 to clear all of +the input and output paths of filament. + +#### PALETTE_CUT +`PALETTE_CUT`: This command instructs the Palette 2 to cut the +filament currently loaded in the splice core. + +#### PALETTE_SMART_LOAD +`PALETTE_SMART_LOAD`: This command start the smart load sequence on +the Palette 2. Filament is loaded automatically by extruding it the +distance calibrated on the device for the printer, and instructs the +Palette 2 once the loading has been completed. This command is the +same as pressing **Smart Load** directly on the Palette 2 screen after +the filament load is complete. + +### [pid_calibrate] + +The pid_calibrate module is automatically loaded if a heater is defined +in the config file. + +#### PID_CALIBRATE +`PID_CALIBRATE HEATER= TARGET= +[WRITE_FILE=1]`: Perform a PID calibration test. The specified heater +will be enabled until the specified target temperature is reached, and +then the heater will be turned off and on for several cycles. If the +WRITE_FILE parameter is enabled, then the file /tmp/heattest.txt will +be created with a log of all temperature samples taken during the +test. + +### [pause_resume] + +The following commands are available when the +[pause_resume config section](Config_Reference.md#pause_resume) is +enabled: + +#### PAUSE +`PAUSE`: Pauses the current print. The current position is captured +for restoration upon resume. + +#### RESUME +`RESUME [VELOCITY=]`: Resumes the print from a pause, first +restoring the previously captured position. The VELOCITY parameter +determines the speed at which the tool should return to the original +captured position. + +#### CLEAR_PAUSE +`CLEAR_PAUSE`: Clears the current paused state without resuming the +print. This is useful if one decides to cancel a print after a +PAUSE. It is recommended to add this to your start gcode to make sure +the paused state is fresh for each print. + +#### CANCEL_PRINT +`CANCEL_PRINT`: Cancels the current print. + +### [probe] + +The following commands are available when a +[probe config section](Config_Reference.md#probe) or +[bltouch config section](Config_Reference.md#bltouch) is enabled (also +see the [probe calibrate guide](Probe_Calibrate.md)). + +#### PROBE +`PROBE [PROBE_SPEED=] [LIFT_SPEED=] [SAMPLES=] +[SAMPLE_RETRACT_DIST=] [SAMPLES_TOLERANCE=] +[SAMPLES_TOLERANCE_RETRIES=] [SAMPLES_RESULT=median|average]`: +Move the nozzle downwards until the probe triggers. If any of the +optional parameters are provided they override their equivalent +setting in the [probe config section](Config_Reference.md#probe). + +#### QUERY_PROBE +`QUERY_PROBE`: Report the current status of the probe ("triggered" or +"open"). + +#### PROBE_ACCURACY +`PROBE_ACCURACY [PROBE_SPEED=] [SAMPLES=] +[SAMPLE_RETRACT_DIST=]`: Calculate the maximum, minimum, average, +median, and standard deviation of multiple probe samples. By default, +10 SAMPLES are taken. Otherwise the optional parameters default to +their equivalent setting in the probe config section. + +#### PROBE_CALIBRATE +`PROBE_CALIBRATE [SPEED=] [=]`: Run a +helper script useful for calibrating the probe's z_offset. See the +PROBE command for details on the optional probe parameters. See the +MANUAL_PROBE command for details on the SPEED parameter and the +additional commands available while the tool is active. Please note, +the PROBE_CALIBRATE command uses the speed variable to move in XY +direction as well as Z. + +#### Z_OFFSET_APPLY_PROBE +`Z_OFFSET_APPLY_PROBE`: Take the current Z Gcode offset (aka, +babystepping), and subtract if from the probe's z_offset. This acts +to take a frequently used babystepping value, and "make it permanent". +Requires a `SAVE_CONFIG` to take effect. + +### [query_adc] + +The query_endstops module is automatically loaded. + +#### QUERY_ADC +`QUERY_ADC [NAME=] [PULLUP=]`: Report the last +analog value received for a configured analog pin. If NAME is not +provided, the list of available adc names are reported. If PULLUP is +provided (as a value in Ohms), the raw analog value along with the +equivalent resistance given that pullup is reported. + +### [query_endstops] + +The query_endstops module is automatically loaded. The following +standard G-Code commands are currently available, but using them is +not recommended: +- Get Endstop Status: `M119` (Use QUERY_ENDSTOPS instead.) + +#### QUERY_ENDSTOPS +`QUERY_ENDSTOPS`: Probe the axis endstops and report if they are +"triggered" or in an "open" state. This command is typically used to +verify that an endstop is working correctly. + +### [resonance_tester] + +The following commands are available when a +[resonance_tester config section](Config_Reference.md#resonance_tester) +is enabled (also see the +[measuring resonances guide](Measuring_Resonances.md)). + +#### MEASURE_AXES_NOISE +`MEASURE_AXES_NOISE`: Measures and outputs the noise for all axes of +all enabled accelerometer chips. + +#### TEST_RESONANCES +`TEST_RESONANCES AXIS= OUTPUT= +[NAME=] [FREQ_START=] [FREQ_END=] +[HZ_PER_SEC=] [INPUT_SHAPING=[<0:1>]]`: Runs the resonance +test in all configured probe points for the requested and +measures the acceleration using the accelerometer chips configured for +the respective axis. can either be X or Y, or specify an +arbitrary direction as `AXIS=dx,dy`, where dx and dy are floating +point numbers defining a direction vector (e.g. `AXIS=X`, `AXIS=Y`, or +`AXIS=1,-1` to define a diagonal direction). Note that `AXIS=dx,dy` +and `AXIS=-dx,-dy` is equivalent. If `INPUT_SHAPING=0` or not set +(default), disables input shaping for the resonance testing, because +it is not valid to run the resonance testing with the input shaper +enabled. `OUTPUT` parameter is a comma-separated list of which outputs +will be written. If `raw_data` is requested, then the raw +accelerometer data is written into a file or a series of files +`/tmp/raw_data__[_].csv` with (`_` part of +the name generated only if more than 1 probe point is configured). If +`resonances` is specified, the frequency response is calculated +(across all probe points) and written into +`/tmp/resonances__.csv` file. If unset, OUTPUT defaults to +`resonances`, and NAME defaults to the current time in +"YYYYMMDD_HHMMSS" format. + +#### SHAPER_CALIBRATE +`SHAPER_CALIBRATE [AXIS=] [NAME=] [FREQ_START=] +[FREQ_END=] [HZ_PER_SEC=] +[MAX_SMOOTHING=]`: Similarly to `TEST_RESONANCES`, runs +the resonance test as configured, and tries to find the optimal +parameters for the input shaper for the requested axis (or both X and +Y axes if `AXIS` parameter is unset). If `MAX_SMOOTHING` is unset, its +value is taken from `[resonance_tester]` section, with the default +being unset. See the +[Max smoothing](Measuring_Resonances.md#max-smoothing) of the +measuring resonances guide for more information on the use of this +feature. The results of the tuning are printed to the console, and the +frequency responses and the different input shapers values are written +to a CSV file(s) `/tmp/calibration_data__.csv`. Unless +specified, NAME defaults to the current time in "YYYYMMDD_HHMMSS" +format. Note that the suggested input shaper parameters can be +persisted in the config by issuing `SAVE_CONFIG` command. + +### [respond] + +The following standard G-Code commands are available when the +[respond config section](Config_Reference.md#respond) is enabled: +- `M118 `: echo the message prepended with the configured + default prefix (or `echo: ` if no prefix is configured). + +The following additional commands are also available. + +#### RESPOND +- `RESPOND MSG=""`: echo the message prepended with the + configured default prefix (or `echo: ` if no prefix is configured). +- `RESPOND TYPE=echo MSG=""`: echo the message prepended with + `echo: `. +- `RESPOND TYPE=command MSG=""`: echo the message prepended + with `// `. OctoPrint can be configured to respond to these messages + (e.g. `RESPOND TYPE=command MSG=action:pause`). +- `RESPOND TYPE=error MSG=""`: echo the message prepended + with `!! `. +- `RESPOND PREFIX= MSG=""`: echo the message + prepended with ``. (The `PREFIX` parameter will take + priority over the `TYPE` parameter) + +### [save_variables] + +The following command is enabled if a +[save_variables config section](Config_Reference.md#save_variables) +has been enabled. + +#### SAVE_VARIABLE +`SAVE_VARIABLE VARIABLE= VALUE=`: Saves the variable to +disk so that it can be used across restarts. All stored variables are +loaded into the `printer.save_variables.variables` dict at startup and +can be used in gcode macros. The provided VALUE is parsed as a Python +literal. + +### [screws_tilt_adjust] + +The following commands are available when the +[screws_tilt_adjust config section](Config_Reference.md#screws_tilt_adjust) +is enabled (also see the +[manual level guide](Manual_Level.md#adjusting-bed-leveling-screws-using-the-bed-probe)). + +#### SCREWS_TILT_CALCULATE +`SCREWS_TILT_CALCULATE [DIRECTION=CW|CCW] +[=]`: This command will invoke the bed screws +adjustment tool. It will command the nozzle to different locations (as +defined in the config file) probing the z height and calculate the +number of knob turns to adjust the bed level. If DIRECTION is +specified, the knob turns will all be in the same direction, clockwise +(CW) or counterclockwise (CCW). See the PROBE command for details on +the optional probe parameters. IMPORTANT: You MUST always do a G28 +before using this command. + +### [sdcard_loop] + +When the [sdcard_loop config section](Config_Reference.md#sdcard_loop) +is enabled, the following extended commands are available. + +#### SDCARD_LOOP_BEGIN +`SDCARD_LOOP_BEGIN COUNT=`: Begin a looped section in the SD +print. A count of 0 indicates that the section should be looped +indefinitely. + +#### SDCARD_LOOP_END +`SDCARD_LOOP_END`: End a looped section in the SD print. + +#### SDCARD_LOOP_DESIST +`SDCARD_LOOP_DESIST`: Complete existing loops without further +iterations. + +### [servo] + +The following commands are available when a +[servo config section](Config_Reference.md#servo) is enabled. + +#### SET_SERVO +`SET_SERVO SERVO=config_name [ANGLE= | WIDTH=]`: Set +the servo position to the given angle (in degrees) or pulse width (in +seconds). Use `WIDTH=0` to disable the servo output. + +### [skew_correction] + +The following commands are available when the +[skew_correction config section](Config_Reference.md#skew_correction) +is enabled (also see the [Skew Correction](Skew_Correction.md) guide). + +#### SET_SKEW +`SET_SKEW [XY=] [XZ=] +[YZ=] [CLEAR=<0|1>]`: Configures the [skew_correction] +module with measurements (in mm) taken from a calibration print. One +may enter measurements for any combination of planes, planes not +entered will retain their current value. If `CLEAR=1` is entered then +all skew correction will be disabled. + +#### GET_CURRENT_SKEW +`GET_CURRENT_SKEW`: Reports the current printer skew for each plane in +both radians and degrees. The skew is calculated based on parameters +provided via the `SET_SKEW` gcode. + +#### CALC_MEASURED_SKEW +`CALC_MEASURED_SKEW [AC=] [BD=] +[AD=]`: Calculates and reports the skew (in radians and +degrees) based on a measured print. This can be useful for determining +the printer's current skew after correction has been applied. It may +also be useful before correction is applied to determine if skew +correction is necessary. See [Skew Correction](Skew_Correction.md) for +details on skew calibration objects and measurements. + +#### SKEW_PROFILE +`SKEW_PROFILE [LOAD=] [SAVE=] [REMOVE=]`: Profile +management for skew_correction. LOAD will restore skew state from the +profile matching the supplied name. SAVE will save the current skew +state to a profile matching the supplied name. Remove will delete the +profile matching the supplied name from persistent memory. Note that +after SAVE or REMOVE operations have been run the SAVE_CONFIG gcode +must be run to make the changes to persistent memory permanent. + +### [stepper_enable] + +The stepper_enable module is automatically loaded. + +#### SET_STEPPER_ENABLE +`SET_STEPPER_ENABLE STEPPER= ENABLE=[0|1]`: Enable or +disable only the given stepper. This is a diagnostic and debugging +tool and must be used with care. Disabling an axis motor does not +reset the homing information. Manually moving a disabled stepper may +cause the machine to operate the motor outside of safe limits. This +can lead to damage to axis components, hot ends, and print surface. + +### [temperature_fan] + +The following command is available when a +[temperature_fan config section](Config_Reference.md#temperature_fan) +is enabled. + +#### SET_TEMPERATURE_FAN_TARGET +`SET_TEMPERATURE_FAN_TARGET temperature_fan= +[target=] [min_speed=] +[max_speed=]`: Sets the target temperature for a +temperature_fan. If a target is not supplied, it is set to the +specified temperature in the config file. If speeds are not supplied, +no change is applied. + +### [tmcXXXX] + +The following commands are available when any of the +[tmcXXXX config sections](Config_Reference.md#tmc-stepper-driver-configuration) +are enabled. + +#### DUMP_TMC +`DUMP_TMC STEPPER=`: This command will read the TMC driver +registers and report their values. + +#### INIT_TMC +`INIT_TMC STEPPER=`: This command will initialize the TMC +registers. Needed to re-enable the driver if power to the chip is +turned off then back on. + +#### SET_TMC_CURRENT +`SET_TMC_CURRENT STEPPER= CURRENT= HOLDCURRENT=`: +This will adjust the run and hold currents of the TMC driver. +(HOLDCURRENT is not applicable to tmc2660 drivers.) + +#### SET_TMC_FIELD +`SET_TMC_FIELD STEPPER= FIELD= VALUE=`: This will +alter the value of the specified register field of the TMC driver. +This command is intended for low-level diagnostics and debugging only +because changing the fields during run-time can lead to undesired and +potentially dangerous behavior of your printer. Permanent changes +should be made using the printer configuration file instead. No sanity +checks are performed for the given values. + +### [toolhead] + +The toolhead module is automatically loaded. + +#### SET_VELOCITY_LIMIT +`SET_VELOCITY_LIMIT [VELOCITY=] [ACCEL=] +[ACCEL_TO_DECEL=] [SQUARE_CORNER_VELOCITY=]`: Modify the +printer's velocity limits. + +### [tuning_tower] + +The tuning_tower module is automatically loaded. + +#### TUNING_TOWER +`TUNING_TOWER COMMAND= PARAMETER= START= +[SKIP=] [FACTOR= [BAND=]] | [STEP_DELTA= +STEP_HEIGHT=]`: A tool for tuning a parameter on each Z height +during a print. The tool will run the given `COMMAND` with the given +`PARAMETER` assigned to a value that varies with `Z` according to a +formula. Use `FACTOR` if you will use a ruler or calipers to measure +the Z height of the optimum value, or `STEP_DELTA` and `STEP_HEIGHT` +if the tuning tower model has bands of discrete values as is common +with temperature towers. If `SKIP=` is specified, the tuning +process doesn't begin until Z height `` is reached, and below +that the value will be set to `START`; in this case, the `z_height` +used in the formulas below is actually `max(z - skip, 0)`. There are +three possible combinations of options: +- `FACTOR`: The value changes at a rate of `factor` per millimeter. + The formula used is: `value = start + factor * z_height`. You can + plug the optimum Z height directly into the formula to determine the + optimum parameter value. +- `FACTOR` and `BAND`: The value changes at an average rate of + `factor` per millimeter, but in discrete bands where the adjustment + will only be made every `BAND` millimeters of Z height. + The formula used is: + `value = start + factor * ((floor(z_height / band) + .5) * band)`. +- `STEP_DELTA` and `STEP_HEIGHT`: The value changes by `STEP_DELTA` + every `STEP_HEIGHT` millimeters. The formula used is: + `value = start + step_delta * floor(z_height / step_height)`. + You can simply count bands or read tuning tower labels to determine + the optimum value. + +### [virtual_sdcard] + +Klipper supports the following standard G-Code commands if the [virtual_sdcard config section](Config_Reference.md#virtual_sdcard) is enabled: - List SD card: `M20` @@ -63,805 +1098,23 @@ enabled: - Set SD position: `M26 S` - Report SD print status: `M27` -In addition, the following extended commands are availble when the +In addition, the following extended commands are available when the "virtual_sdcard" config section is enabled. -- Load a file and start SD print: `SDCARD_PRINT_FILE FILENAME=` -- Unload file and clear SD state: `SDCARD_RESET_FILE` -### G-Code arcs +#### SDCARD_PRINT_FILE +`SDCARD_PRINT_FILE FILENAME=`: Load a file and start SD +print. -The following standard G-Code commands are available if a -[gcode_arcs config section](Config_Reference.md#gcode_arcs) is -enabled: -- Controlled Arc Move (G2 or G3): `G2 [X] [Y] [Z] - [E] [F] I J` +#### SDCARD_RESET_FILE +`SDCARD_RESET_FILE`: Unload file and clear SD state. -### G-Code firmware retraction - -The following standard G-Code commands are available if a -[firmware_retraction config section](Config_Reference.md#firmware_retraction) -is enabled: -- Retract: `G10` -- Unretract: `G11` - -### G-Code display commands - -The following standard G-Code commands are available if a -[display config section](Config_Reference.md#display) is enabled: -- Display Message: `M117 ` -- Set build percentage: `M73 P` - -### Other available G-Code commands - -The following standard G-Code commands are currently available, but -using them is not recommended: -- Get Endstop Status: `M119` (Use QUERY_ENDSTOPS instead.) - -## Extended G-Code Commands - -Klipper uses "extended" G-Code commands for general configuration and -status. These extended commands all follow a similar format - they -start with a command name and may be followed by one or more -parameters. For example: `SET_SERVO SERVO=myservo ANGLE=5.3`. In this -document, the commands and parameters are shown in uppercase, however -they are not case sensitive. (So, "SET_SERVO" and "set_servo" both run -the same command.) - -The following standard commands are supported: -- `QUERY_ENDSTOPS`: Probe the axis endstops and report if they are - "triggered" or in an "open" state. This command is typically used to - verify that an endstop is working correctly. -- `QUERY_ADC [NAME=] [PULLUP=]`: Report the last - analog value received for a configured analog pin. If NAME is not - provided, the list of available adc names are reported. If PULLUP is - provided (as a value in Ohms), the raw analog value along with the - equivalent resistance given that pullup is reported. -- `GET_POSITION`: Return information on the current location of the - toolhead. -- `SET_GCODE_OFFSET [X=|X_ADJUST=] - [Y=|Y_ADJUST=] [Z=|Z_ADJUST=] - [MOVE=1 [MOVE_SPEED=]]`: Set a positional offset to apply to - future G-Code commands. This is commonly used to virtually change - the Z bed offset or to set nozzle XY offsets when switching - extruders. For example, if "SET_GCODE_OFFSET Z=0.2" is sent, then - future G-Code moves will have 0.2mm added to their Z height. If the - X_ADJUST style parameters are used, then the adjustment will be - added to any existing offset (eg, "SET_GCODE_OFFSET Z=-0.2" followed - by "SET_GCODE_OFFSET Z_ADJUST=0.3" would result in a total Z offset - of 0.1). If "MOVE=1" is specified then a toolhead move will be - issued to apply the given offset (otherwise the offset will take - effect on the next absolute G-Code move that specifies the given - axis). If "MOVE_SPEED" is specified then the toolhead move will be - performed with the given speed (in mm/s); otherwise the toolhead - move will use the last specified G-Code speed. -- `SAVE_GCODE_STATE [NAME=]`: Save the current - g-code coordinate parsing state. Saving and restoring the g-code - state is useful in scripts and macros. This command saves the - current g-code absolute coordinate mode (G90/G91), absolute extrude - mode (M82/M83), origin (G92), offset (SET_GCODE_OFFSET), speed - override (M220), extruder override (M221), move speed, current XYZ - position, and relative extruder "E" position. If NAME is provided it - allows one to name the saved state to the given string. If NAME is - not provided it defaults to "default". -- `RESTORE_GCODE_STATE [NAME=] - [MOVE=1 [MOVE_SPEED=]]`: Restore a state previously saved via - SAVE_GCODE_STATE. If "MOVE=1" is specified then a toolhead move will - be issued to move back to the previous XYZ position. If "MOVE_SPEED" - is specified then the toolhead move will be performed with the given - speed (in mm/s); otherwise the toolhead move will use the restored - g-code speed. -- `PID_CALIBRATE HEATER= TARGET= - [WRITE_FILE=1]`: Perform a PID calibration test. The specified - heater will be enabled until the specified target temperature is - reached, and then the heater will be turned off and on for several - cycles. If the WRITE_FILE parameter is enabled, then the file - /tmp/heattest.txt will be created with a log of all temperature - samples taken during the test. -- `TURN_OFF_HEATERS`: Turn off all heaters. -- `TEMPERATURE_WAIT SENSOR= [MINIMUM=] [MAXIMUM=]`: - Wait until the given temperature sensor is at or above the supplied - MINIMUM and/or at or below the supplied MAXIMUM. -- `SET_VELOCITY_LIMIT [VELOCITY=] [ACCEL=] - [ACCEL_TO_DECEL=] [SQUARE_CORNER_VELOCITY=]`: Modify - the printer's velocity limits. -- `SET_HEATER_TEMPERATURE HEATER= [TARGET=]`: - Sets the target temperature for a heater. If a target temperature is - not supplied, the target is 0. -- `ACTIVATE_EXTRUDER EXTRUDER=`: In a printer with - multiple extruders this command is used to change the active - extruder. -- `SET_PRESSURE_ADVANCE [EXTRUDER=] [ADVANCE=] - [SMOOTH_TIME=]`: Set pressure advance - parameters. If EXTRUDER is not specified, it defaults to the active - extruder. -- `SET_EXTRUDER_STEP_DISTANCE [EXTRUDER=] - [DISTANCE=]`: Set a new value for the provided extruder's - "step distance". The "step distance" is - `rotation_distance/(full_steps_per_rotation*microsteps)`. Value is - not retained on Klipper reset. Use with caution, small changes can - result in excessive pressure between extruder and hot end. Do proper - calibration steps with filament before use. If 'DISTANCE' value is - not included command will return current step distance. -- `SYNC_STEPPER_TO_EXTRUDER STEPPER= [EXTRUDER=]`: This - command will cause the given extruder STEPPER (as specified in an - [extruder](Config_Reference#extruder) or - [extruder stepper](Config_Reference#extruder_stepper) config - section) to become synchronized to the given EXTRUDER. If EXTRUDER - is an empty string then the stepper will not be synchronized to an - extruder. -- `SET_STEPPER_ENABLE STEPPER= ENABLE=[0|1]`: Enable or - disable only the given stepper. This is a diagnostic and debugging - tool and must be used with care. Disabling an axis motor does not - reset the homing information. Manually moving a disabled stepper may - cause the machine to operate the motor outside of safe limits. This - can lead to damage to axis components, hot ends, and print surface. -- `STEPPER_BUZZ STEPPER=`: Move the given stepper forward - one mm and then backward one mm, repeated 10 times. This is a - diagnostic tool to help verify stepper connectivity. -- `MANUAL_PROBE [SPEED=]`: Run a helper script useful for - measuring the height of the nozzle at a given location. If SPEED is - specified, it sets the speed of TESTZ commands (the default is - 5mm/s). During a manual probe, the following additional commands are - available: - - `ACCEPT`: This command accepts the current Z position and - concludes the manual probing tool. - - `ABORT`: This command terminates the manual probing tool. - - `TESTZ Z=`: This command moves the nozzle up or down by the - amount specified in "value". For example, `TESTZ Z=-.1` would move - the nozzle down .1mm while `TESTZ Z=.1` would move the nozzle up - .1mm. The value may also be `+`, `-`, `++`, or `--` to move the - nozzle up or down an amount relative to previous attempts. -- `Z_ENDSTOP_CALIBRATE [SPEED=]`: Run a helper script useful - for calibrating a Z position_endstop config setting. See the - MANUAL_PROBE command for details on the parameters and the - additional commands available while the tool is active. -- `Z_OFFSET_APPLY_ENDSTOP`: Take the current Z Gcode offset (aka, - babystepping), and subtract it from the stepper_z endstop_position. - This acts to take a frequently used babystepping value, and "make - it permanent". Requires a `SAVE_CONFIG` to take effect. -- `TUNING_TOWER COMMAND= PARAMETER= START= [SKIP=] - [FACTOR= [BAND=]] | [STEP_DELTA= STEP_HEIGHT=]`: - A tool for tuning a parameter on each Z height during a print. - The tool will run the given `COMMAND` with the given `PARAMETER` - assigned to a value that varies with `Z` according to a formula. Use `FACTOR` - if you will use a ruler or calipers to measure the Z height of the optimum - value, or `STEP_DELTA` and `STEP_HEIGHT` if the tuning tower model has bands - of discrete values as is common with temperature towers. If `SKIP=` - is specified, the tuning process doesn't begin until Z height `` is - reached, and below that the value will be set to `START`; in this case, the - `z_height` used in the formulas below is actually `max(z - skip, 0)`. - There are three possible combinations of options: - - `FACTOR`: The value changes at a rate of `factor` per millimeter. - The formula used is - `value = start + factor * z_height`. - You can plug the optimum Z height directly into the formula to - determine the optimum parameter value. - - `FACTOR` and `BAND`: The value changes at an average rate of `factor` per - millimeter, but in discrete bands where the adjustment will only be made - every `BAND` millimeters of Z height. - The formula used is - `value = start + factor * ((floor(z_height / band) + .5) * band)`. - - `STEP_DELTA` and `STEP_HEIGHT`: The value changes by `STEP_DELTA` every - `STEP_HEIGHT` millimeters. The formula used is - `value = start + step_delta * floor(z_height / step_height)`. - You can simply count bands or read tuning tower labels to determine the - optimum value. -- `SET_DISPLAY_GROUP [DISPLAY=] GROUP=`: Set the - active display group of an lcd display. This allows to define - multiple display data groups in the config, - e.g. `[display_data ]` and switch between them - using this extended gcode command. If DISPLAY is not specified it - defaults to "display" (the primary display). -- `SET_IDLE_TIMEOUT [TIMEOUT=]`: Allows the user to set the - idle timeout (in seconds). -- `RESTART`: This will cause the host software to reload its config - and perform an internal reset. This command will not clear error - state from the micro-controller (see FIRMWARE_RESTART) nor will it - load new software (see - [the FAQ](FAQ.md#how-do-i-upgrade-to-the-latest-software)). -- `FIRMWARE_RESTART`: This is similar to a RESTART command, but it - also clears any error state from the micro-controller. -- `SAVE_CONFIG`: This command will overwrite the main printer config - file and restart the host software. This command is used in - conjunction with other calibration commands to store the results of - calibration tests. -- `STATUS`: Report the Klipper host software status. -- `HELP`: Report the list of available extended G-Code commands. - -### G-Code Macro Commands - -The following command is available when a -[gcode_macro config section](Config_Reference.md#gcode_macro) is -enabled (also see the -[command templates guide](Command_Templates.md)): -- `SET_GCODE_VARIABLE MACRO= VARIABLE= - VALUE=`: This command allows one to change the value of a - gcode_macro variable at run-time. The provided VALUE is parsed as a - Python literal. - -### Custom Pin Commands - -The following command is available when an -[output_pin config section](Config_Reference.md#output_pin) is -enabled: -- `SET_PIN PIN=config_name VALUE= CYCLE_TIME=` - -Note: Hardware PWM does not currently support the CYCLE_TIME parameter -and will use the cycle time defined in the config. - -### Manually Controlled Fans Commands - -The following command is available when a -[fan_generic config section](Config_Reference.md#fan_generic) is -enabled: -- `SET_FAN_SPEED FAN=config_name SPEED=` This command sets - the speed of a fan. must be between 0.0 and 1.0. - -### Neopixel and Dotstar Commands - -The following command is available when a -[neopixel config section](Config_Reference.md#neopixel) or -[dotstar config section](Config_Reference.md#dotstar) is enabled: -- `SET_LED LED= RED= GREEN= BLUE= - WHITE= [INDEX=] [TRANSMIT=0] [SYNC=1]`: This sets the LED - output. Each color `` must be between 0.0 and 1.0. The WHITE - option is only valid on RGBW LEDs. If multiple LED chips are - daisy-chained then one may specify INDEX to alter the color of just - the given chip (1 for the first chip, 2 for the second, etc.). If - INDEX is not provided then all LEDs in the daisy-chain will be set - to the provided color. If TRANSMIT=0 is specified then the color - change will only be made on the next SET_LED command that does not - specify TRANSMIT=0; this may be useful in combination with the INDEX - parameter to batch multiple updates in a daisy-chain. By default, the - SET_LED command will sync it's changes with other ongoing gcode commands. - This can lead to undesirable behavior if LEDs are being set while the - printer is not printing as it will reset the idle timeout. If careful - timing is not needed, the optional SYNC=0 parameter can be specified to - apply the changes instantly and not reset the idle timeout. - -### Servo Commands - -The following commands are available when a -[servo config section](Config_Reference.md#servo) is enabled: -- `SET_SERVO SERVO=config_name [ANGLE= | WIDTH=]`: - Set the servo position to the given angle (in degrees) or pulse - width (in seconds). Use `WIDTH=0` to disable the servo output. - -### Manual stepper Commands - -The following command is available when a -[manual_stepper config section](Config_Reference.md#manual_stepper) is -enabled: -- `MANUAL_STEPPER STEPPER=config_name [ENABLE=[0|1]] - [SET_POSITION=] [SPEED=] [ACCEL=] - [MOVE= [STOP_ON_ENDSTOP=[1|2|-1|-2]] [SYNC=0]]`: This command - will alter the state of the stepper. Use the ENABLE parameter to - enable/disable the stepper. Use the SET_POSITION parameter to force - the stepper to think it is at the given position. Use the MOVE - parameter to request a movement to the given position. If SPEED - and/or ACCEL is specified then the given values will be used instead - of the defaults specified in the config file. If an ACCEL of zero is - specified then no acceleration will be performed. If - STOP_ON_ENDSTOP=1 is specified then the move will end early should - the endstop report as triggered (use STOP_ON_ENDSTOP=2 to complete - the move without error even if the endstop does not trigger, use -1 - or -2 to stop when the endstop reports not triggered). Normally - future G-Code commands will be scheduled to run after the stepper - move completes, however if a manual stepper move uses SYNC=0 then - future G-Code movement commands may run in parallel with the stepper - movement. - -### Probe - -The following commands are available when a -[probe config section](Config_Reference.md#probe) is enabled (also see -the [probe calibrate guide](Probe_Calibrate.md)): -- `PROBE [PROBE_SPEED=] [LIFT_SPEED=] [SAMPLES=] - [SAMPLE_RETRACT_DIST=] [SAMPLES_TOLERANCE=] - [SAMPLES_TOLERANCE_RETRIES=] - [SAMPLES_RESULT=median|average]`: Move the nozzle downwards until - the probe triggers. If any of the optional parameters are provided - they override their equivalent setting in the - [probe config section](Config_Reference.md#probe). -- `QUERY_PROBE`: Report the current status of the probe ("triggered" - or "open"). -- `PROBE_ACCURACY [PROBE_SPEED=] [SAMPLES=] - [SAMPLE_RETRACT_DIST=]`: Calculate the maximum, minimum, - average, median, and standard deviation of multiple probe - samples. By default, 10 SAMPLES are taken. Otherwise the optional - parameters default to their equivalent setting in the probe config - section. -- `PROBE_CALIBRATE [SPEED=] [=]`: Run a - helper script useful for calibrating the probe's z_offset. See the - PROBE command for details on the optional probe parameters. See - the MANUAL_PROBE command for details on the SPEED parameter and the - additional commands available while the tool is active. Please note, - the PROBE_CALIBRATE command uses the speed variable - to move in XY direction as well as Z. -- `Z_OFFSET_APPLY_PROBE`: Take the current Z Gcode offset (aka, - babystepping), and subtract if from the probe's z_offset. - This acts to take a frequently used babystepping value, and "make - it permanent". Requires a `SAVE_CONFIG` to take effect. - -### BLTouch - -The following command is available when a -[bltouch config section](Config_Reference.md#bltouch) is enabled (also -see the [BL-Touch guide](BLTouch.md)): -- `BLTOUCH_DEBUG COMMAND=`: This sends a command to the - BLTouch. It may be useful for debugging. Available commands are: - `pin_down`, `touch_mode`, `pin_up`, `self_test`, `reset`, - (*1): `set_5V_output_mode`, `set_OD_output_mode`, `output_mode_store` - - *** Note that the commands marked by (*1) are solely supported - by a BL-Touch V3.0 or V3.1(+) - -- `BLTOUCH_STORE MODE=`: This stores an output mode in the - EEPROM of a BLTouch V3.1 Available output_modes are: `5V`, `OD` - -### Delta Calibration +### [z_tilt] The following commands are available when the -[delta_calibrate config section](Config_Reference.md#linear-delta-kinematics) -is enabled (also see the [delta calibrate guide](Delta_Calibrate.md)): -- `DELTA_CALIBRATE [METHOD=manual] [=]`: This - command will probe seven points on the bed and recommend updated - endstop positions, tower angles, and radius. See the PROBE command - for details on the optional probe parameters. If METHOD=manual is - specified then the manual probing tool is activated - see the - MANUAL_PROBE command above for details on the additional commands - available while this tool is active. -- `DELTA_ANALYZE`: This command is used during enhanced delta - calibration. See [Delta Calibrate](Delta_Calibrate.md) for details. +[z_tilt config section](Config_Reference.md#z_tilt) is enabled. -### Bed Tilt - -The following commands are available when the -[bed_tilt config section](Config_Reference.md#bed_tilt) is enabled: -- `BED_TILT_CALIBRATE [METHOD=manual] [=]`: - This command will probe the points specified in the config and then - recommend updated x and y tilt adjustments. See the PROBE command - for details on the optional probe parameters. If METHOD=manual is - specified then the manual probing tool is activated - see the - MANUAL_PROBE command above for details on the additional commands - available while this tool is active. - -### Mesh Bed Leveling - -The following commands are available when the -[bed_mesh config section](Config_Reference.md#bed_mesh) is enabled -(also see the [bed mesh guide](Bed_Mesh.md)): -- `BED_MESH_CALIBRATE [METHOD=manual] [=] - [=]`: - This command probes the bed using generated points specified by the - parameters in the config. After probing, a mesh is generated and - z-movement is adjusted according to the mesh. See the PROBE command - for details on the optional probe parameters. If METHOD=manual is - specified then the manual probing tool is activated - see the - MANUAL_PROBE command above for details on the additional commands - available while this tool is active. -- `BED_MESH_OUTPUT PGP=[<0:1>]`: This command outputs the current probed - z values and current mesh values to the terminal. If PGP=1 is specified - the X, Y coordinates generated by bed_mesh, along with their associated - indices, will be output to the terminal. -- `BED_MESH_MAP`: Like to BED_MESH_OUTPUT, this command prints the current - state of the mesh to the terminal. Instead of printing the values in a - human readable format, the state is serialized in json format. This allows - octoprint plugins to easily capture the data and generate height maps - approximating the bed's surface. -- `BED_MESH_CLEAR`: This command clears the mesh and removes all - z adjustment. It is recommended to put this in your end-gcode. -- `BED_MESH_PROFILE LOAD= SAVE= REMOVE=`: This - command provides profile management for mesh state. LOAD will - restore the mesh state from the profile matching the supplied name. - SAVE will save the current mesh state to a profile matching the - supplied name. Remove will delete the profile matching the - supplied name from persistent memory. Note that after SAVE or - REMOVE operations have been run the SAVE_CONFIG gcode must be run - to make the changes to peristent memory permanent. -- `BED_MESH_OFFSET [X=] [Y=]`: Applies X and/or Y - offsets to the mesh lookup. This is useful for printers with - independent extruders, as an offset is necessary to produce - correct Z adjustment after a tool change. - -### Bed Screws Helper - -The following commands are available when the -[bed_screws config section](Config_Reference.md#bed_screws) is enabled -(also see the -[manual level guide](Manual_Level.md#adjusting-bed-leveling-screws)): -- `BED_SCREWS_ADJUST`: This command will invoke the bed screws - adjustment tool. It will command the nozzle to different locations - (as defined in the config file) and allow one to make adjustments to - the bed screws so that the bed is a constant distance from the - nozzle. - -### Bed Screws Tilt Adjust Helper - -The following commands are available when the -[screws_tilt_adjust config section](Config_Reference.md#screws_tilt_adjust) -is enabled (also see the -[manual level guide](Manual_Level.md#adjusting-bed-leveling-screws-using-the-bed-probe)): -- `SCREWS_TILT_CALCULATE [DIRECTION=CW|CCW] [=]`: - This command will invoke the bed screws adjustment tool. It will command the - nozzle to different locations (as defined in the config file) - probing the z height and calculate the number of knob turns to - adjust the bed level. If DIRECTION is specified, the knob turns will all - be in the same direction, clockwise (CW) or counterclockwise (CCW). - See the PROBE command for details on the optional probe parameters. - IMPORTANT: You MUST always do a G28 before using this command. - -### Z Tilt - -The following commands are available when the -[z_tilt config section](Config_Reference.md#z_tilt) is enabled: -- `Z_TILT_ADJUST [=]`: This command will probe - the points specified in the config and then make independent - adjustments to each Z stepper to compensate for tilt. See the PROBE - command for details on the optional probe parameters. - -### Dual Carriages - -The following command is available when the -[dual_carriage config section](Config_Reference.md#dual_carriage) is -enabled: -- `SET_DUAL_CARRIAGE CARRIAGE=[0|1]`: This command will set the active - carriage. It is typically invoked from the activate_gcode and - deactivate_gcode fields in a multiple extruder configuration. - -### TMC stepper drivers - -The following commands are available when any of the -[tmcXXXX config sections](Config_Reference.md#tmc-stepper-driver-configuration) -are enabled: -- `DUMP_TMC STEPPER=`: This command will read the TMC driver - registers and report their values. -- `INIT_TMC STEPPER=`: This command will intitialize the TMC - registers. Needed to re-enable the driver if power to the chip is - turned off then back on. -- `SET_TMC_CURRENT STEPPER= CURRENT= HOLDCURRENT=`: - This will adjust the run and hold currents of the TMC driver. - (HOLDCURRENT is not applicable to tmc2660 drivers.) -- `SET_TMC_FIELD STEPPER= FIELD= VALUE=`: This - will alter the value of the specified register field of the TMC - driver. This command is intended for low-level diagnostics and - debugging only because changing the fields during run-time can lead - to undesired and potentially dangerous behavior of your printer. - Permanent changes should be made using the printer configuration - file instead. No sanity checks are performed for the given values. - -### Endstop adjustments by stepper phase - -The following commands are available when an -[endstop_phase config section](Config_Reference.md#endstop_phase) is -enabled (also see the [endstop phase guide](Endstop_Phase.md)): -- `ENDSTOP_PHASE_CALIBRATE [STEPPER=]`: If no STEPPER - parameter is provided then this command will reports statistics on - endstop stepper phases during past homing operations. When a STEPPER - parameter is provided it arranges for the given endstop phase - setting to be written to the config file (in conjunction with the - SAVE_CONFIG command). - -### Force movement - -The following commands are available when the -[force_move config section](Config_Reference.md#force_move) is -enabled: -- `FORCE_MOVE STEPPER= DISTANCE= VELOCITY= - [ACCEL=]`: This command will forcibly move the given stepper - the given distance (in mm) at the given constant velocity (in - mm/s). If ACCEL is specified and is greater than zero, then the - given acceleration (in mm/s^2) will be used; otherwise no - acceleration is performed. No boundary checks are performed; no - kinematic updates are made; other parallel steppers on an axis will - not be moved. Use caution as an incorrect command could cause - damage! Using this command will almost certainly place the low-level - kinematics in an incorrect state; issue a G28 afterwards to reset - the kinematics. This command is intended for low-level diagnostics - and debugging. -- `SET_KINEMATIC_POSITION [X=] [Y=] [Z=]`: Force - the low-level kinematic code to believe the toolhead is at the given - cartesian position. This is a diagnostic and debugging command; use - SET_GCODE_OFFSET and/or G92 for regular axis transformations. If an - axis is not specified then it will default to the position that the - head was last commanded to. Setting an incorrect or invalid position - may lead to internal software errors. This command may invalidate - future boundary checks; issue a G28 afterwards to reset the - kinematics. - -### SDcard loop - -When the [sdcard_loop config section](Config_Reference.md#sdcard_loop) -is enabled, the following extended commands are available: -- `SDCARD_LOOP_BEGIN COUNT=`: Begin a looped section in the SD - print. A count of 0 indicates that the section should be looped - indefinately. -- `SDCARD_LOOP_END`: End a looped section in the SD print. -- `SDCARD_LOOP_DESIST`: Complete existing loops without further - iterations. - -### Send message (respond) to host - -The following commands are availabe when the -[respond config section](Config_Reference.md#respond) is enabled. -- `M118 `: echo the message prepended with the configured - default prefix (or `echo: ` if no prefix is configured). -- `RESPOND MSG=""`: echo the message prepended with the - configured default prefix (or `echo: ` if no prefix is configured). -- `RESPOND TYPE=echo MSG=""`: echo the message prepended with - `echo: `. -- `RESPOND TYPE=command MSG=""`: echo the message prepended - with `// `. Octopint can be configured to respond to these messages - (e.g. `RESPOND TYPE=command MSG=action:pause`). -- `RESPOND TYPE=error MSG=""`: echo the message prepended - with `!! `. -- `RESPOND PREFIX= MSG=""`: echo the message - prepended with ``. (The `PREFIX` parameter will take - priority over the `TYPE` parameter) - -### Pause Resume - -The following commands are available when the -[pause_resume config section](Config_Reference.md#pause_resume) is -enabled: -- `PAUSE`: Pauses the current print. The current position is captured - for restoration upon resume. -- `RESUME [VELOCITY=]`: Resumes the print from a pause, first - restoring the previously captured position. The VELOCITY parameter - determines the speed at which the tool should return to the original - captured position. -- `CLEAR_PAUSE`: Clears the current paused state without resuming the - print. This is useful if one decides to cancel a print after a - PAUSE. It is recommended to add this to your start gcode to make - sure the paused state is fresh for each print. -- `CANCEL_PRINT`: Cancels the current print. - -### Filament Sensor - -The following command is available when the -[filament_switch_sensor or filament_motion_sensor config section](Config_Reference.md#filament_switch_sensor) -is enabled. -- `QUERY_FILAMENT_SENSOR SENSOR=`: Queries the current - status of the filament sensor. The data displayed on the terminal - will depend on the sensor type defined in the confguration. -- `SET_FILAMENT_SENSOR SENSOR= ENABLE=[0|1]`: Sets the - filament sensor on/off. If ENABLE is set to 0, the filament sensor - will be disabled, if set to 1 it is enabled. - -### Firmware Retraction - -The following commands are available when the -[firmware_retraction config section](Config_Reference.md#firmware_retraction) -is enabled. These commands allow you to utilise the firmware -retraction feature available in many slicers, to reduce stringing -during non-extrusion moves from one part of the print to another. -Appropriately configuring pressure advance reduces the length of -retraction required. -- `SET_RETRACTION [RETRACT_LENGTH=] [RETRACT_SPEED=] - [UNRETRACT_EXTRA_LENGTH=] [UNRETRACT_SPEED=]`: Adjust the - parameters used by firmware retraction. RETRACT_LENGTH determines - the length of filament to retract and unretract. The speed of - retraction is adjusted via RETRACT_SPEED, and is typically set - relatively high. The speed of unretraction is adjusted via - UNRETRACT_SPEED, and is not particularly critical, although often - lower than RETRACT_SPEED. In some cases it is useful to add a small - amount of additional length on unretraction, and this is set via - UNRETRACT_EXTRA_LENGTH. SET_RETRACTION is commonly set as part of - slicer per-filament configuration, as different filaments require - different parameter settings. -- `GET_RETRACTION`: Queries the current parameters used by firmware - retraction and displays them on the terminal. -- `G10`: Retracts the extruder using the currently configured - parameters. -- `G11`: Unretracts the extruder using the currently configured - parameters. - -### Skew Correction - -The following commands are available when the -[skew_correction config section](Config_Reference.md#skew_correction) -is enabled (also see the [Skew Correction](Skew_Correction.md) guide): -- `SET_SKEW [XY=] [XZ=] - [YZ=] [CLEAR=<0|1>]`: Configures the [skew_correction] - module with measurements (in mm) taken from a calibration print. - One may enter measurements for any combination of planes, planes not - entered will retain their current value. If `CLEAR=1` is entered - then all skew correction will be disabled. -- `GET_CURRENT_SKEW`: Reports the current printer skew for each plane - in both radians and degrees. The skew is calculated based on - parameters provided via the `SET_SKEW` gcode. -- `CALC_MEASURED_SKEW [AC=] [BD=] - [AD=]`: Calculates and reports the skew (in radians and - degrees) based on a measured print. This can be useful for - determining the printer's current skew after correction has been - applied. It may also be useful before correction is applied to - determine if skew correction is necessary. See [Skew Correction](Skew_Correction.md) - for details on skew calibration objects and measurements. -- `SKEW_PROFILE [LOAD=] [SAVE=] [REMOVE=]`: Profile - management for skew_correction. LOAD will restore skew state from - the profile matching the supplied name. SAVE will save the current - skew state to a profile matching the supplied name. Remove will - delete the profile matching the supplied name from persistent - memory. Note that after SAVE or REMOVE operations have been run the - SAVE_CONFIG gcode must be run to make the changes to peristent - memory permanent. - -### Delayed GCode - -The following command is enabled if a -[delayed_gcode config section](Config_Reference.md#delayed_gcode) has -been enabled (also see the -[template guide](Command_Templates.md#delayed-gcodes)): -- `UPDATE_DELAYED_GCODE [ID=] [DURATION=]`: Updates the - delay duration for the identified [delayed_gcode] and starts the timer - for gcode execution. A value of 0 will cancel a pending delayed gcode - from executing. - -### Save Variables - -The following command is enabled if a -[save_variables config section](Config_Reference.md#save_variables) -has been enabled: -- `SAVE_VARIABLE VARIABLE= VALUE=`: Saves the variable to - disk so that it can be used across restarts. All stored variables - are loaded into the `printer.save_variables.variables` dict at - startup and can be used in gcode macros. The provided VALUE is - parsed as a Python literal. - -### Resonance compensation - -The following command is enabled if an -[input_shaper config section](Config_Reference.md#input_shaper) has -been enabled (also see the -[resonance compensation guide](Resonance_Compensation.md)): -- `SET_INPUT_SHAPER [SHAPER_FREQ_X=] - [SHAPER_FREQ_Y=] - [DAMPING_RATIO_X=] - [DAMPING_RATIO_Y=] [SHAPER_TYPE=] - [SHAPER_TYPE_X=] [SHAPER_TYPE_Y=]`: - Modify input shaper parameters. Note that SHAPER_TYPE parameter - resets input shaper for both X and Y axes even if different shaper - types have been configured in [input_shaper] section. SHAPER_TYPE - cannot be used together with either of SHAPER_TYPE_X and - SHAPER_TYPE_Y parameters. See - [config reference](Config_Reference.md#input_shaper) for more - details on each of these parameters. - -### Temperature Fan Commands - -The following command is available when a -[temperature_fan config section](Config_Reference.md#temperature_fan) -is enabled: -- `SET_TEMPERATURE_FAN_TARGET temperature_fan= - [target=] [min_speed=] [max_speed=]`: Sets the target temperature for a - temperature_fan. If a target is not supplied, it is set to the - specified temperature in the config file. If speeds are not supplied, no change is applied. - -### Adxl345 Accelerometer Commands - -The following commands are available when an -[adxl345 config section](Config_Reference.md#adxl345) is enabled: -- `ACCELEROMETER_MEASURE [CHIP=] [NAME=]`: Starts - accelerometer measurements at the requested number of samples per - second. If CHIP is not specified it defaults to "adxl345". The - command works in a start-stop mode: when executed for the first - time, it starts the measurements, next execution stops them. The - results of measurements are written to a file named - `/tmp/adxl345--.csv` where `` is the name of the - accelerometer chip (`my_chip_name` from `[adxl345 my_chip_name]`) - and `` is the optional NAME parameter. If NAME is not - specified it defaults to the current time in "YYYYMMDD_HHMMSS" - format. If the accelerometer does not have a name in its config - section (simply `[adxl345]`) then `` part of the name is not - generated. -- `ACCELEROMETER_QUERY [CHIP=] [RATE=]`: queries - accelerometer for the current value. If CHIP is not specified it - defaults to "adxl345". If RATE is not specified, the default value - is used. This command is useful to test the connection to the - ADXL345 accelerometer: one of the returned values should be a - free-fall acceleration (+/- some noise of the chip). -- `ACCELEROMETER_DEBUG_READ [CHIP=] REG=`: queries - ADXL345 register (e.g. 44 or 0x2C). Can be useful for - debugging purposes. -- `ACCELEROMETER_DEBUG_WRITE [CHIP=] REG= VAL=`: - writes raw into a register . Both and - can be a decimal or a hexadecimal integer. Use with care, - and refer to ADXL345 data sheet for the reference. - -### Resonance Testing Commands - -The following commands are available when a -[resonance_tester config section](Config_Reference.md#resonance_tester) -is enabled (also see the -[measuring resonances guide](Measuring_Resonances.md)): -- `MEASURE_AXES_NOISE`: Measures and outputs the noise for all axes of - all enabled accelerometer chips. -- `TEST_RESONANCES AXIS= OUTPUT= - [NAME=] [FREQ_START=] [FREQ_END=] - [HZ_PER_SEC=] [INPUT_SHAPING=[<0:1>]]`: Runs the resonance - test in all configured probe points for the requested - and measures the acceleration using the accelerometer chips configured - for the respective axis. can either be X or Y, or specify an - arbitrary direction as `AXIS=dx,dy`, where dx and dy are floating point - numbers defining a direction vector (e.g. `AXIS=X`, `AXIS=Y`, or - `AXIS=1,-1` to define a diagonal direction). Note that `AXIS=dx,dy` and - `AXIS=-dx,-dy` is equivalent. If `INPUT_SHAPING=0` or not set (default), - disables input shaping for the resonance testing, because it is not valid - to run the resonance testing with the input shaper enabled. - `OUTPUT` parameter is a comma-separated list of which outputs will be - written. If `raw_data` is requested, then the raw accelerometer data - is written into a file or a series of files - `/tmp/raw_data__[_].csv` with (`_` part of - the name generated only if more than 1 probe point is configured). - If `resonances` is specified, the frequency response is calculated - (across all probe points) and written into - `/tmp/resonances__.csv` file. If unset, OUTPUT defaults - to `resonances`, and NAME defaults to the current time in - "YYYYMMDD_HHMMSS" format. -- `SHAPER_CALIBRATE [AXIS=] [NAME=] - [FREQ_START=] [FREQ_END=] - [HZ_PER_SEC=] [MAX_SMOOTHING=]`: - Similarly to `TEST_RESONANCES`, runs the resonance test as configured, - and tries to find the optimal parameters for the input shaper for the - requested axis (or both X and Y axes if `AXIS` parameter is unset). - If `MAX_SMOOTHING` is unset, its value is taken from `[resonance_tester]` - section, with the default being unset. See the - [Max smoothing](Measuring_Resonances.md#max-smoothing) of the measuring - resonances guide for more information on the use of this feature. - The results of the tuning are printed to the console, and the frequency - responses and the different input shapers values are written to a CSV - file(s) `/tmp/calibration_data__.csv`. Unless specified, NAME - defaults to the current time in "YYYYMMDD_HHMMSS" format. Note that - the suggested input shaper parameters can be persisted in the config - by issuing `SAVE_CONFIG` command. - -### Palette 2 Commands - -The following command is available when the -[palette2 config section](Config_Reference.md#palette2) -is enabled: -- `PALETTE_CONNECT`: This command initializes the connection with - the Palette 2. -- `PALETTE_DISCONNECT`: This command disconnects from the Palette 2. -- `PALETTE_CLEAR`: This command instructs the Palette 2 to clear all of the - input and output paths of filament. -- `PALETTE_CUT`: This command instructs the Palette 2 to cut the filament - currently loaded in the splice core. -- `PALETTE_SMART_LOAD`: This command start the smart load sequence on the - Palette 2. Filament is loaded automatically by extruding it the distance - calibrated on the device for the printer, and instructs the Palette 2 - once the loading has been completed. This command is the same as pressing - **Smart Load** directly on the Palette 2 screen after the filament load - is complete. - -Palette prints work by embedding special OCodes (Omega Codes) -in the GCode file: -- `O1`...`O32`: These codes are read from the GCode stream and processed - by this module and passed to the Palette 2 device. - -### Filament Width Sensor Commands - -The following command is available when the -[tsl1401cl filament width sensor config section](Config_Reference.md#tsl1401cl_filament_width_sensor) -or [hall filament width sensor config section](Config_Reference.md#hall_filament_width_sensor) -is enabled (also see [TSLl401CL Filament Width Sensor](TSL1401CL_Filament_Width_Sensor.md) -and [Hall Filament Width Sensor](Hall_Filament_Width_Sensor.md)): - -- `QUERY_FILAMENT_WIDTH` - Return the current measured filament width -- `RESET_FILAMENT_WIDTH_SENSOR` - Clear all sensor readings. Helpful after - filament change -- `DISABLE_FILAMENT_WIDTH_SENSOR` - Turn off the filament width sensor and - stop using it for flow control -- `ENABLE_FILAMENT_WIDTH_SENSOR` - Turn on the filament width sensor and - start using it for flow control - -### Hall Filament Width Sensor Commands - -The following command is available when the -[hall filament width sensor config section](Config_Reference.md#hall_filament_width_sensor) -is enabled: - -- `QUERY_RAW_FILAMENT_WIDTH` - Return the current ADC channel readings and - RAW sensor value for calibration points -- `ENABLE_FILAMENT_WIDTH_LOG` - Turn on diameter logging -- `DISABLE_FILAMENT_WIDTH_LOG` - Turn off diameter logging +#### Z_TILT_ADJUST +`Z_TILT_ADJUST [=]`: This command will probe +the points specified in the config and then make independent +adjustments to each Z stepper to compensate for tilt. See the PROBE +command for details on the optional probe parameters. diff --git a/docs/Hall_Filament_Width_Sensor.md b/docs/Hall_Filament_Width_Sensor.md index 978d6450..680a1a4f 100644 --- a/docs/Hall_Filament_Width_Sensor.md +++ b/docs/Hall_Filament_Width_Sensor.md @@ -11,7 +11,7 @@ an assembly video is also available on [Youtube](https://www.youtube.com/watch?v To use Hall filament width sensor, read [Config Reference](Config_Reference.md#hall_filament_width_sensor) and -[G-Code documentation](G-Codes.md#Hall_Filament_Width_Sensor_Commands). +[G-Code documentation](G-Codes.md#hall_filament_width_sensor). ## How does it work? diff --git a/docs/Measuring_Resonances.md b/docs/Measuring_Resonances.md index 6be076b7..655a6494 100644 --- a/docs/Measuring_Resonances.md +++ b/docs/Measuring_Resonances.md @@ -473,10 +473,11 @@ ignoring any errors for `SET_INPUT_SHAPER` command. For `TEST_RESONANCES` command, specify the desired test axis. The raw data will be written into `/tmp` directory on the RPi. -The raw data can also be obtained by running the command `ACCELEROMETER_MEASURE` -command twice during some normal printer activity - first to start the -measurements, and then to stop them and write the output file. Refer to -[G-Codes](G-Codes.md#adxl345-accelerometer-commands) for more details. +The raw data can also be obtained by running the command +`ACCELEROMETER_MEASURE` command twice during some normal printer +activity - first to start the measurements, and then to stop them and +write the output file. Refer to [G-Codes](G-Codes.md#adxl345) for more +details. The data can be processed later by the following scripts: `scripts/graph_accelerometer.py` and `scripts/calibrate_shaper.py`. Both diff --git a/docs/Probe_Calibrate.md b/docs/Probe_Calibrate.md index 9bede889..ed3964e6 100644 --- a/docs/Probe_Calibrate.md +++ b/docs/Probe_Calibrate.md @@ -129,12 +129,12 @@ typical bed leveling procedures. It may be possible to tune the probe speed and/or probe start height to improve the repeatability of the probe. The `PROBE_ACCURACY` command allows one to run tests with different parameters to see their impact - see the -[G-Codes document](G-Codes.md) for further details. If the probe -generally obtains repeatable results but has an occasional outlier, -then it may be possible to account for that by using multiple samples -on each probe - read the description of the probe `samples` config -parameters in the [config reference](Config_Reference.md#probe) for -more details. +[G-Codes document](G-Codes.md#probe_accuracy) for further details. If +the probe generally obtains repeatable results but has an occasional +outlier, then it may be possible to account for that by using multiple +samples on each probe - read the description of the probe `samples` +config parameters in the [config reference](Config_Reference.md#probe) +for more details. If new probe speed, samples count, or other settings are needed, then update the printer.cfg file and issue a `RESTART` command. If so, it diff --git a/docs/TMC_Drivers.md b/docs/TMC_Drivers.md index 581fe2b2..8f85af53 100644 --- a/docs/TMC_Drivers.md +++ b/docs/TMC_Drivers.md @@ -45,7 +45,7 @@ leave a stepper idle sufficiently long. If one wishes to reduce current to motors during print start routines, then consider issuing -[SET_TMC_CURRENT](G-Codes.md#tmc-stepper-drivers) commands in a +[SET_TMC_CURRENT](G-Codes.md#set_tmc_current) commands in a [START_PRINT macro](Slicers.md#klipper-gcode_macro) to adjust the current before and after normal printing moves. @@ -410,10 +410,10 @@ restrictions: ## Querying and diagnosing driver settings -The `[DUMP_TMC command](G-Codes.md#tmc-stepper-drivers) is a useful -tool when configuring and diagnosing the drivers. It will report all -fields configured by Klipper as well as all fields that can be queried -from the driver. +The `[DUMP_TMC command](G-Codes.md#dump_tmc) is a useful tool when +configuring and diagnosing the drivers. It will report all fields +configured by Klipper as well as all fields that can be queried from +the driver. All of the reported fields are defined in the Trinamic datasheet for each driver. These datasheets can be found on the @@ -429,7 +429,7 @@ Klipper supports configuring many low-level driver fields using has the full list of fields available for each type of driver. In addition, almost all fields can be modified at run-time using the -[SET_TMC_FIELD command](G-Codes.md#tmc-stepper-drivers). +[SET_TMC_FIELD command](G-Codes.md#set_tmc_field). Each of these fields is defined in the Trinamic datasheet for each driver. These datasheets can be found on the diff --git a/docs/TSL1401CL_Filament_Width_Sensor.md b/docs/TSL1401CL_Filament_Width_Sensor.md index a0dccb92..a788069f 100644 --- a/docs/TSL1401CL_Filament_Width_Sensor.md +++ b/docs/TSL1401CL_Filament_Width_Sensor.md @@ -7,7 +7,7 @@ designs at [Thingiverse](https://www.thingiverse.com/search?q=filament%20width%2 To use a sensor array as a filament width sensor, read [Config Reference](Config_Reference.md#tsl1401cl_filament_width_sensor) and -[G-Code documentation](G-Codes.md#Filament_Width_Sensor_Commands). +[G-Code documentation](G-Codes.md#hall_filament_width_sensor). ## How does it work? From 30be45c1ae5631467018d716fd67d132e73f9bcf Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 1 Feb 2022 12:11:22 -0500 Subject: [PATCH 040/211] docs: Fix link in G-Codes.md Signed-off-by: Kevin O'Connor --- docs/G-Codes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 6b903342..b0c0d770 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -42,7 +42,7 @@ Klipper's goal is to support the G-Code commands produced by common 3rd party software (eg, OctoPrint, Printrun, Slic3r, Cura, etc.) in their standard configurations. It is not a goal to support every possible G-Code command. Instead, Klipper prefers human readable -["extended G-Code commands"](#extended-g-code-commands). +["extended G-Code commands"](#additional-commands). If one requires a less common G-Code command then it may be possible to implement it with a custom From 427f4b456ef64dd3571661a7df3d8a34a0ec9c90 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 1 Feb 2022 12:19:23 -0500 Subject: [PATCH 041/211] docs: Fix unescaped angle brackets in G-Codes.md Signed-off-by: Kevin O'Connor --- docs/G-Codes.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index b0c0d770..6dc5df8b 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -94,13 +94,13 @@ acceleration (+/- some noise of the chip). #### ACCELEROMETER_DEBUG_READ `ACCELEROMETER_DEBUG_READ [CHIP=] REG=`: -queries ADXL345 register (e.g. 44 or 0x2C). Can be useful +queries ADXL345 register "register" (e.g. 44 or 0x2C). Can be useful for debugging purposes. #### ACCELEROMETER_DEBUG_WRITE -`ACCELEROMETER_DEBUG_WRITE [CHIP=] REG= -VAL=`: Writes raw into a register . Both - and can be a decimal or a hexadecimal integer. Use +`ACCELEROMETER_DEBUG_WRITE [CHIP=] REG= +VAL=`: Writes raw "value" into a register "register". Both +"value" and "register" can be a decimal or a hexadecimal integer. Use with care, and refer to ADXL345 data sheet for the reference. ### [bed_mesh] @@ -326,7 +326,7 @@ enabled. #### SET_FAN_SPEED `SET_FAN_SPEED FAN=config_name SPEED=` This command sets the -speed of a fan. must be between 0.0 and 1.0. +speed of a fan. "speed" must be between 0.0 and 1.0. ### [firmware_retraction] @@ -832,9 +832,9 @@ all enabled accelerometer chips. `TEST_RESONANCES AXIS= OUTPUT= [NAME=] [FREQ_START=] [FREQ_END=] [HZ_PER_SEC=] [INPUT_SHAPING=[<0:1>]]`: Runs the resonance -test in all configured probe points for the requested and +test in all configured probe points for the requested "axis" and measures the acceleration using the accelerometer chips configured for -the respective axis. can either be X or Y, or specify an +the respective axis. "axis" can either be X or Y, or specify an arbitrary direction as `AXIS=dx,dy`, where dx and dy are floating point numbers defining a direction vector (e.g. `AXIS=X`, `AXIS=Y`, or `AXIS=1,-1` to define a diagonal direction). Note that `AXIS=dx,dy` From 0143199175cd69d34ed1e832cf94dfbbd467de2a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 3 Feb 2022 17:23:34 -0500 Subject: [PATCH 042/211] Makefile: Improve handling of board symbolic link creation Running "make" directly after a "make distclean" can lead to a corrupt out/board symbolic link. Rework the make rules so that the board symbolic link is created in a new make instance that has the updated definition of CONFIG_BOARD_DIRECTORY. Signed-off-by: Kevin O'Connor --- Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index af74951a..1bdcd155 100644 --- a/Makefile +++ b/Makefile @@ -85,17 +85,21 @@ $(OUT)compile_time_request.o: $(patsubst %.c, $(OUT)src/%.o.ctr,$(src-y)) ./scri ################ Auto generation of "board/" include file link -$(OUT)board-link: $(KCONFIG_CONFIG) +create-board-link: @echo " Creating symbolic link $(OUT)board" $(Q)mkdir -p $(addprefix $(OUT), $(dirs-y)) - $(Q)echo "#$(CONFIG_BOARD_DIRECTORY)" > $@.temp - $(Q)if ! cmp -s $@.temp $@; then rm -f $(OUT)*.d $(patsubst %,$(OUT)%/*.d,$(dirs-y)) ; mv $@.temp $@ ; fi + $(Q)rm -f $(OUT)*.d $(patsubst %,$(OUT)%/*.d,$(dirs-y)) $(Q)rm -f $(OUT)board $(Q)ln -sf $(CURDIR)/src/$(CONFIG_BOARD_DIRECTORY) $(OUT)board $(Q)mkdir -p $(OUT)board-generic $(Q)rm -f $(OUT)board-generic/board $(Q)ln -sf $(CURDIR)/src/generic $(OUT)board-generic/board +# Hack to rebuild OUT directory and reload make dependencies on Kconfig change +$(OUT)board-link: $(KCONFIG_CONFIG) + $(Q)mkdir -p $(OUT) + $(Q)echo "# Makefile board-link rule" > $@ + $(Q)$(MAKE) create-board-link include $(OUT)board-link ################ Kconfig rules @@ -114,7 +118,7 @@ menuconfig: ################ Generic rules # Make definitions -.PHONY : all clean distclean olddefconfig menuconfig FORCE +.PHONY : all clean distclean olddefconfig menuconfig create-board-link FORCE .DELETE_ON_ERROR: all: $(target-y) From 54646c77dc1b659614e9a8e27909da4b08ac8cee Mon Sep 17 00:00:00 2001 From: cbc02009 <39525900+cbc02009@users.noreply.github.com> Date: Sun, 6 Feb 2022 12:15:35 -0500 Subject: [PATCH 043/211] bme280: fix integer handling for python3 in bme280.py (#5237) Singed-off-by: Christopher Conroy --- klippy/extras/bme280.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/klippy/extras/bme280.py b/klippy/extras/bme280.py index f6a17179..0cd9f392 100644 --- a/klippy/extras/bme280.py +++ b/klippy/extras/bme280.py @@ -437,7 +437,7 @@ class BME280: else: factor = 0 while duration_ms > 0x3F: - duration_ms /= 4 + duration_ms //= 4 factor += 1 duration_reg = duration_ms + (factor * 64) From 9174c0241e970db23384fdafab2403bc05adc946 Mon Sep 17 00:00:00 2001 From: adelyser <12093019+adelyser@users.noreply.github.com> Date: Sun, 6 Feb 2022 16:29:53 -0700 Subject: [PATCH 044/211] stm32: Fix ADC on stm32h7 (#5239) Don't reset the ADC peripheral if the clock is already enabled. Fixes #5236 Signed-off-by: Aaron DeLyser --- src/stm32/stm32h7_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/stm32/stm32h7_adc.c b/src/stm32/stm32h7_adc.c index 792a3335..2733b24f 100644 --- a/src/stm32/stm32h7_adc.c +++ b/src/stm32/stm32h7_adc.c @@ -114,7 +114,9 @@ gpio_adc_setup(uint32_t pin) ADC_TypeDef *adc; if (chan >= 40){ adc = ADC3; - enable_pclock(ADC3_BASE); + if (!is_enabled_pclock(ADC3_BASE)) { + enable_pclock(ADC3_BASE); + } MODIFY_REG(ADC3_COMMON->CCR, ADC_CCR_CKMODE_Msk, 0b11 << ADC_CCR_CKMODE_Pos); } else if (chan >= 20){ From 6cd1e794f7352d8c18fa2e2b8adf49c8e41ceba9 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 6 Feb 2022 22:33:09 -0500 Subject: [PATCH 045/211] logextract: Breakup shutdown parsing into classes Separate out message parsing into individual classes. This should make the code a little eaiser to understand. Signed-off-by: Kevin O'Connor --- scripts/logextract.py | 367 +++++++++++++++++++++++++----------------- 1 file changed, 216 insertions(+), 151 deletions(-) diff --git a/scripts/logextract.py b/scripts/logextract.py index 5d86cdce..937c68ec 100755 --- a/scripts/logextract.py +++ b/scripts/logextract.py @@ -148,22 +148,69 @@ class TMCUartHelper: # Shutdown extraction ###################################################################### -stats_seq_s = r" send_seq=(?P[0-9]+) receive_seq=(?P[0-9]+) " +def add_high_bits(val, ref, mask): + half = (mask + 1) // 2 + return ref + ((val - (ref & mask) + half) & mask) - half + count_s = r"(?P[0-9]+)" time_s = r"(?P