Core dump when MCU is powered off twice

Basic Information:

Printer Model: Ender-3 Pro
MCU / Printerboard: Creality v4.2.7
Host / SBC: Raspberry Pi 3 Model B running arch
klippy.log

Starting Klippy...
Args: ['/data/klipper/klipper/klippy/klippy.py', '/data/klipper/printers/ender3/config/printer.cfg', '-I', '/data/klipper/printers/ender3/klippy_tty', '-a', '/data/klipper/printers/ender3/klippy_uds', '-l', '/data/log/klipper/klipper-ender3.log']
Git version: 'v0.12.0-189-ge0cbd7b5'
Branch: master
Remote: origin
Tracked URL: https://github.com/Klipper3d/klipper.git
CPU: 4 core ARMv7 Processor rev 4 (v7l)
Python: '3.12.3 (main, Apr 27 2024, 17:17:26) [GCC 12.1.0]'
Start printer at Thu May 16 12:22:59 2024 (1715854980.0 4143.9)
===== Config file =====
(...snip...)
=======================
Extruder max_extrude_ratio=0.266081
mcu 'mcu': Starting serial connect
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0'
webhooks client 3037281808: New connection
webhooks client 3037281808: Client info {'program': 'Moonraker', 'version': 'v0.8.0-358-gfca0cf3'}
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0'

(...switching power ON...)

Loaded MCU 'mcu' 112 commands (v0.12.0-189-ge0cbd7b5 / gcc: (Arch Repository) 13.2.0 binutils: (GNU Binutils) 2.42)
MCU 'mcu' config: ADC_MAX=4095 BUS_PINS_i2c1=PB6,PB7 BUS_PINS_i2c1a=PB8,PB9 BUS_PINS_i2c2=PB10,PB11 BUS_PINS_spi1=PA6,PA7,PA5 BUS_PINS_spi1a=PB4,PB5,PB3 BUS_PINS_spi2=PB14,PB15,PB13 BUS_PINS_spi3=PB4,PB5,PB3 CLOCK_FREQ=72000000 MCU=stm32f103xe PWM_MAX=255 RECEIVE_WINDOW=192 RESERVE_PINS_serial=PA10,PA9 SERIAL_BAUD=250000 STATS_SUMSQ_BASE=256 STEPPER_BOTH_EDGE=1
Sending MCU 'mcu' printer configuration...
Configured MCU 'mcu' (1024 moves)
bed_mesh: generated points
Index |  Tool Adjusted  |   Probe
  0   | (43.0, 11.0)    | (0.0, 4.0)
(...snip...)
  24  | (248.0, 235.0)  | (205.0, 228.0)
Starting heater checks for heater_bed
Starting heater checks for extruder
Stats 4169.4: gcodein=0  mcu: mcu_awake=0.000 mcu_task_avg=0.000000 mcu_task_stddev=0.000000 bytes_write=2069 bytes_read=4437 bytes_retransmit=9 bytes_invalid=0 send_seq=145 receive_seq=142 retransmit_seq=2 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=1685 upcoming_bytes=106 freq=72000705 heater_bed: target=0 temp=20.7 pwm=0.000  pi_soc: temp=58.0 sysload=0.82 cputime=4.815 memavail=812532 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.0 pwm=0.000
webhooks: registering remote method 'shutdown_machine' for connection id: 3037281808
webhooks: registering remote method 'reboot_machine' for connection id: 3037281808
webhooks: registering remote method 'pause_job_queue' for connection id: 3037281808
webhooks: registering remote method 'start_job_queue' for connection id: 3037281808
webhooks: registering remote method 'set_device_power' for connection id: 3037281808
Stats 4170.4: gcodein=0  mcu: mcu_awake=0.000 mcu_task_avg=0.000000 mcu_task_stddev=0.000000 bytes_write=4046 bytes_read=4753 bytes_retransmit=9 bytes_invalid=0 send_seq=182 receive_seq=182 retransmit_seq=2 srtt=0.004 rttvar=0.001 rto=0.025 ready_bytes=0 upcoming_bytes=0 freq=72000858 heater_bed: target=0 temp=20.8 pwm=0.000  pi_soc: temp=58.0 sysload=0.82 cputime=4.865 memavail=812228 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000
(...snip...)
Stats 4180.4: gcodein=0  mcu: mcu_awake=0.001 mcu_task_avg=0.000015 mcu_task_stddev=0.000010 bytes_write=4106 bytes_read=5933 bytes_retransmit=9 bytes_invalid=0 send_seq=192 receive_seq=192 retransmit_seq=2 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=0 freq=72001545 heater_bed: target=0 temp=20.7 pwm=0.000  pi_soc: temp=56.4 sysload=0.77 cputime=5.264 memavail=813200 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000

(...switching power OFF...)

b'Got EOF when reading from device'
Stats 4181.4: gcodein=0  mcu: mcu_awake=0.001 mcu_task_avg=0.000015 mcu_task_stddev=0.000010 bytes_write=4106 bytes_read=5948 bytes_retransmit=9 bytes_invalid=0 send_seq=192 receive_seq=192 retransmit_seq=2 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=11 freq=72001545 heater_bed: target=0 temp=18.6 pwm=0.000  pi_soc: temp=56.4 sysload=0.77 cputime=5.302 memavail=812848 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000
Stats 4182.4: gcodein=0  mcu: mcu_awake=0.001 mcu_task_avg=0.000015 mcu_task_stddev=0.000010 bytes_write=4106 bytes_read=5948 bytes_retransmit=9 bytes_invalid=0 send_seq=192 receive_seq=192 retransmit_seq=2 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=12 freq=72001545 heater_bed: target=0 temp=18.6 pwm=0.000  pi_soc: temp=56.4 sysload=0.77 cputime=5.333 memavail=811684 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000
Stats 4183.4: gcodein=0  mcu: mcu_awake=0.001 mcu_task_avg=0.000015 mcu_task_stddev=0.000010 bytes_write=4106 bytes_read=5948 bytes_retransmit=9 bytes_invalid=0 send_seq=192 receive_seq=192 retransmit_seq=2 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=13 freq=72001545 heater_bed: target=0 temp=18.6 pwm=0.000  pi_soc: temp=56.4 sysload=0.77 cputime=5.366 memavail=811684 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000
Stats 4184.4: gcodein=0  mcu: mcu_awake=0.001 mcu_task_avg=0.000015 mcu_task_stddev=0.000010 bytes_write=4106 bytes_read=5948 bytes_retransmit=9 bytes_invalid=0 send_seq=192 receive_seq=192 retransmit_seq=2 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=14 freq=72001545 heater_bed: target=0 temp=18.6 pwm=0.000  pi_soc: temp=56.4 sysload=0.87 cputime=5.397 memavail=812196 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000
Timeout with MCU 'mcu' (eventtime=4185.367193)
Transition to shutdown state: Lost communication with MCU 'mcu'
Dumping gcode input 0 blocks
Dumping 20 requests for client 3037281808
Received 4169.392833: b'{"id": 2807614656, "method": "objects/subscribe", "params": {"objects": {"webhooks": null}, "response_template": {"method": "process_status_update"}}}'
Received 4169.396740: b'{"id": 2807614728, "method": "gcode/subscribe_output", "params": {"response_template": {"method": "process_gcode_response"}}}'
Received 4169.400153: b'{"id": 2807615424, "method": "list_endpoints", "params": {}}'
Received 4169.407942: b'{"id": 2807619632, "method": "objects/subscribe", "params": {"objects": {"webhooks": null, "print_stats": null}, "response_template": {"method": "process_status_update"}}}'
Received 4169.592461: b'{"id": 2807621432, "method": "info", "params": {}}'
Received 4169.648771: b'{"id": 2807623160, "method": "objects/list", "params": {}}'
Received 4169.652461: b'{"id": 2807614728, "method": "objects/query", "params": {"objects": {"configfile": null}}}'
Received 4169.904380: b'{"id": 2807620208, "method": "register_remote_method", "params": {"response_template": {"method": "shutdown_machine"}, "remote_method": "shutdown_machine"}}'
Received 4169.906969: b'{"id": 2807447720, "method": "register_remote_method", "params": {"response_template": {"method": "reboot_machine"}, "remote_method": "reboot_machine"}}'
Received 4169.912745: b'{"id": 2807447720, "method": "register_remote_method", "params": {"response_template": {"method": "pause_job_queue"}, "remote_method": "pause_job_queue"}}'
Received 4169.918806: b'{"id": 2807447720, "method": "register_remote_method", "params": {"response_template": {"method": "start_job_queue"}, "remote_method": "start_job_queue"}}'
Received 4169.922038: b'{"id": 2807447720, "method": "register_remote_method", "params": {"response_template": {"method": "set_device_power"}, "remote_method": "set_device_power"}}'
Received 4169.929516: b'{"id": 2807623472, "method": "objects/query", "params": {"objects": {"heaters": null}}}'
Received 4169.931840: b'{"id": 2807623160, "method": "objects/query", "params": {"objects": {"heaters": null}}}'
Received 4170.149500: b'{"id": 2807622440, "method": "objects/subscribe", "params": {"objects": {"webhooks": null, "print_stats": null, "heater_bed": null, "temperature_sensor pi_soc": null, "extruder": null}, "response_template": {"method": "process_status_update"}}}'
Received 4170.401737: b'{"id": 2807622944, "method": "objects/subscribe", "params": {"objects": {"webhooks": null, "print_stats": null, "heater_bed": null, "temperature_sensor pi_soc": null, "extruder": null}, "response_template": {"method": "process_status_update"}}}'
Received 4171.706002: b'{"id": 2798805280, "method": "info", "params": {}}'
Received 4171.707627: b'{"id": 2807623616, "method": "objects/list", "params": {}}'
Received 4171.905094: b'{"id": 2807621672, "method": "objects/subscribe", "params": {"objects": {"gcode": null, "webhooks": null, "configfile": null, "mcu": null, "gcode_move": null, "probe": null, "bed_mesh": null, "screws_tilt_adjust": null, "heaters": null, "heater_bed": null, "fan": null, "display_status": null, "pwm_cycle_time BEEPER": null, "pause_resume": null, "idle_timeout": null, "gcode_macro stay_on": null, "gcode_macro allow_off": null, "gcode_macro START_PRINT": null, "gcode_macro END_PRINT": null, "gcode_macro PAUSE": null, "gcode_macro RESUME": null, "gcode_macro CANCEL_PRINT": null, "gcode_macro UNLOAD_FILAMENT": null, "gcode_macro LOAD_FILAMENT": null, "gcode_macro SET_FLOW": null, "gcode_macro M300": null, "gcode_macro BEEP": null, "gcode_macro BED_MESH_CALIBRATE_AREA": null, "gcode_macro PRIME_EXTRUDER": null, "print_stats": null, "virtual_sdcard": null, "gcode_macro POWER_ON": null, "gcode_macro POWER_OFF": null, "gcode_macro LED_ON": null, "gcode_macro LED_OFF": null, "gcode_macro REPORT": null, "temperature_host pi_soc": null, "temperature_sensor pi_soc": null, "stepper_enable": null, "motion_report": null, "query_endstops": null, "system_stats": null, "manual_probe": null, "toolhead": null, "extruder": null}, "response_template": {"method": "process_status_update"}}}'
Received 4172.464046: b'{"id": 2807623184, "method": "gcode/help", "params": {}}'
gcode state: absolute_coord=True absolute_extrude=True base_position=[0.0, 0.0, 0.0, 0.0] last_position=[0.0, 0.0, 0.0, 0.0] homing_position=[0.0, 0.0, 0.0, 0.0] speed_factor=0.016666666666666666 extrude_factor=1.0 speed=25.0
Reactor garbage collection: (4171.874275336, 0.0, 0.0)
Stats 4185.4: gcodein=0  mcu: mcu_awake=0.001 mcu_task_avg=0.000015 mcu_task_stddev=0.000010 bytes_write=4106 bytes_read=5948 bytes_retransmit=9 bytes_invalid=0 send_seq=192 receive_seq=192 retransmit_seq=2 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=15 freq=72001545 heater_bed: target=0 temp=18.6 pwm=0.000  pi_soc: temp=55.8 sysload=0.87 cputime=5.431 memavail=812196 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000
(...snip...)
Stats 4194.4: gcodein=0  mcu: mcu_awake=0.001 mcu_task_avg=0.000015 mcu_task_stddev=0.000010 bytes_write=4106 bytes_read=5948 bytes_retransmit=9 bytes_invalid=0 send_seq=192 receive_seq=192 retransmit_seq=2 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=25 freq=72001545 heater_bed: target=0 temp=18.6 pwm=0.000  pi_soc: temp=56.9 sysload=0.74 cputime=5.740 memavail=813156 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000

(...Switching power ON...)

Unable to issue reset command on MCU 'mcu'
webhooks client 3037281808: Disconnected
Restarting printer
Start printer at Thu May 16 12:23:52 2024 (1715855032.5 4196.4)
===== Config file =====
(...snip...)
=======================
Extruder max_extrude_ratio=0.266081
mcu 'mcu': Starting serial connect
webhooks client 3027825816: New connection
webhooks client 3027825816: Client info {'program': 'Moonraker', 'version': 'v0.8.0-358-gfca0cf3'}
Loaded MCU 'mcu' 112 commands (v0.12.0-189-ge0cbd7b5 / gcc: (Arch Repository) 13.2.0 binutils: (GNU Binutils) 2.42)
MCU 'mcu' config: ADC_MAX=4095 BUS_PINS_i2c1=PB6,PB7 BUS_PINS_i2c1a=PB8,PB9 BUS_PINS_i2c2=PB10,PB11 BUS_PINS_spi1=PA6,PA7,PA5 BUS_PINS_spi1a=PB4,PB5,PB3 BUS_PINS_spi2=PB14,PB15,PB13 BUS_PINS_spi3=PB4,PB5,PB3 CLOCK_FREQ=72000000 MCU=stm32f103xe PWM_MAX=255 RECEIVE_WINDOW=192 RESERVE_PINS_serial=PA10,PA9 SERIAL_BAUD=250000 STATS_SUMSQ_BASE=256 STEPPER_BOTH_EDGE=1
Sending MCU 'mcu' printer configuration...
Configured MCU 'mcu' (1024 moves)
bed_mesh: generated points
Index |  Tool Adjusted  |   Probe
  0   | (43.0, 11.0)    | (0.0, 4.0)
(...snip...)
  24  | (248.0, 235.0)  | (205.0, 228.0)
Starting heater checks for heater_bed
Starting heater checks for extruder
Stats 4201.4: gcodein=0  mcu: mcu_awake=0.000 mcu_task_avg=0.000000 mcu_task_stddev=0.000000 bytes_write=1950 bytes_read=4375 bytes_retransmit=0 bytes_invalid=0 send_seq=141 receive_seq=138 retransmit_seq=0 srtt=0.005 rttvar=0.002 rto=0.025 ready_bytes=1875 upcoming_bytes=10 freq=72001150 heater_bed: target=0 temp=0.0 pwm=0.000  pi_soc: temp=56.9 sysload=0.76 cputime=8.935 memavail=811692 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=0.0 pwm=0.000
webhooks: registering remote method 'shutdown_machine' for connection id: 3027825816
webhooks: registering remote method 'reboot_machine' for connection id: 3027825816
webhooks: registering remote method 'pause_job_queue' for connection id: 3027825816
webhooks: registering remote method 'start_job_queue' for connection id: 3027825816
webhooks: registering remote method 'set_device_power' for connection id: 3027825816
Stats 4202.4: gcodein=0  mcu: mcu_awake=0.000 mcu_task_avg=0.000000 mcu_task_stddev=0.000000 bytes_write=4062 bytes_read=4716 bytes_retransmit=0 bytes_invalid=0 send_seq=181 receive_seq=181 retransmit_seq=0 srtt=0.005 rttvar=0.002 rto=0.025 ready_bytes=0 upcoming_bytes=0 freq=72001877 heater_bed: target=0 temp=20.7 pwm=0.000  pi_soc: temp=56.9 sysload=0.76 cputime=8.991 memavail=811704 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.0 pwm=0.000
Stats 4203.4: gcodein=0  mcu: mcu_awake=0.000 mcu_task_avg=0.000000 mcu_task_stddev=0.000000 bytes_write=4068 bytes_read=4837 bytes_retransmit=0 bytes_invalid=0 send_seq=182 receive_seq=182 retransmit_seq=0 srtt=0.005 rttvar=0.002 rto=0.025 ready_bytes=0 upcoming_bytes=0 freq=72001277 heater_bed: target=0 temp=20.8 pwm=0.000  pi_soc: temp=56.9 sysload=0.76 cputime=9.031 memavail=811704 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=20.9 pwm=0.000
Stats 4204.4: gcodein=0  mcu: mcu_awake=0.055 mcu_task_avg=0.000195 mcu_task_stddev=0.000398 bytes_write=4074 bytes_read=4960 bytes_retransmit=0 bytes_invalid=0 send_seq=183 receive_seq=183 retransmit_seq=0 srtt=0.005 rttvar=0.001 rto=0.025 ready_bytes=0 upcoming_bytes=0 freq=72002134 heater_bed: target=0 temp=20.7 pwm=0.000  pi_soc: temp=56.4 sysload=0.86 cputime=9.072 memavail=812976 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.0 pwm=0.000
Stats 4205.4: gcodein=0  mcu: mcu_awake=0.055 mcu_task_avg=0.000195 mcu_task_stddev=0.000398 bytes_write=4080 bytes_read=5081 bytes_retransmit=0 bytes_invalid=0 send_seq=184 receive_seq=184 retransmit_seq=0 srtt=0.005 rttvar=0.001 rto=0.025 ready_bytes=0 upcoming_bytes=0 freq=72001743 heater_bed: target=0 temp=20.8 pwm=0.000  pi_soc: temp=56.9 sysload=0.86 cputime=9.118 memavail=812976 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.0 pwm=0.000
Stats 4206.4: gcodein=0  mcu: mcu_awake=0.055 mcu_task_avg=0.000195 mcu_task_stddev=0.000398 bytes_write=4086 bytes_read=5202 bytes_retransmit=0 bytes_invalid=0 send_seq=185 receive_seq=185 retransmit_seq=0 srtt=0.005 rttvar=0.001 rto=0.025 ready_bytes=0 upcoming_bytes=0 freq=72001701 heater_bed: target=0 temp=20.7 pwm=0.000  pi_soc: temp=56.4 sysload=0.86 cputime=9.163 memavail=812752 print_time=0.000 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.0 pwm=0.000

(...Switching power OFF => core dump ...)


Describe your issue:

After updating Klipper yesterday from 5edc7fee to commit e0cbd7b5, I’m getting systematic core dumps the second time the MCU is powered off (via a gpio-controlled relay).

Here is the traceback when that happens:

Fatal Python error: PyGILState_Release: auto-releasing thread-state, but no thread-state for this thread
Python runtime state: initialized

Thread 0xb46cf400 (most recent call first):
  <no Python frame>

Thread 0xb3ece400 (most recent call first):
  File "/data/klipper/klipper/klippy/serialhdl.py", line 39 in _bg_thread
  File "/usr/lib/python3.12/threading.py", line 1010 in run
  File "/usr/lib/python3.12/threading.py", line 1073 in _bootstrap_inner
  File "/usr/lib/python3.12/threading.py", line 1030 in _bootstrap

Thread 0xb5bef400 (most recent call first):
  File "/usr/lib/python3.12/threading.py", line 355 in wait
  File "/usr/lib/python3.12/queue.py", line 171 in get
  File "/data/klipper/klipper/klippy/queuelogger.py", line 34 in _bg_thread
  File "/usr/lib/python3.12/threading.py", line 1010 in run
  File "/usr/lib/python3.12/threading.py", line 1073 in _bootstrap_inner
  File "/usr/lib/python3.12/threading.py", line 1030 in _bootstrap

Thread 0xb6830020 (most recent call first):
  File "/data/klipper/klipper/klippy/reactor.py", line 342 in _dispatch_loop

Extension modules: greenlet._greenlet, _cffi_backend, markupsafe._speedups (total: 3)

I can work around the issue (manually restarting the service or using moonraker’s “bound_services” to do it automatically when switching the GPIO pin), but since this was not happening before, I figured this would not classify as expected behaviour.

The previous version I was using was commit 5edc7fee (last updated around October, 2023) and dit not have that issue.

Let me know if there is any additional info I can provide.

I don’t see any commits that would break anything, but you’re about the 5th Ender 3 users in the past few days with an issue.

Since it can’t find your board, have you tried SSHing into your Pi and running

ls /dev/serial/by-id/*
or
ls /dev/serial/by-path/*

again to see if anything changed? (it shouldn’t have, but that’d be the first step)

No, the serial path did not change (as I mentioned, merely restarting klippy works, but then it coredumps again after the second power off switch - to be clear, if I don’t switch the printer off, everything works like a breeze).

Also, just for reference, the full config (although I doubt it’s related to the issue):

[mcu]
serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
restart_method: command

[virtual_sdcard]
path: /data/klipper/printers/ender3/gcodes

[stepper_x]
step_pin: PB9
dir_pin: PC2
enable_pin: !PC3
microsteps: 16
rotation_distance: 40
endstop_pin: ^PA5
position_endstop: 0
position_max: 248
homing_speed: 50

[stepper_y]
step_pin: PB7
dir_pin: PB8
enable_pin: !PC3
microsteps: 16
rotation_distance: 40
endstop_pin: ^PA6
position_endstop: 0
position_max: 235
homing_speed: 50

[stepper_z]
step_pin: PB5
dir_pin: !PB6
enable_pin: !PC3
microsteps: 16
rotation_distance: 8
endstop_pin: probe:z_virtual_endstop
position_min: -5
position_max: 250

[safe_z_home]
home_xy_position: 160.9,124.9
speed: 100
z_hop: 10
z_hop_speed: 5

[bltouch]
sensor_pin: ^PB1
control_pin: PB0
pin_up_touch_mode_reports_triggered: True
probe_with_touch_mode: True
x_offset: -43
y_offset: -7
z_offset: 2.335
speed: 10
samples: 3
sample_retract_dist: 5.0
lift_speed: 40
samples_tolerance_retries: 3
speed: 10
samples: 2

[bed_mesh]
speed: 100
horizontal_move_z: 5
mesh_min: 0,4
mesh_max: 205,228
probe_count: 5,5
algorithm: bicubic

[screws_tilt_adjust]
screw1: 73,42
screw1_name: front left screw
screw2: 243,42
screw2_name: front right screw
screw3: 243,212
screw3_name: rear right screw
screw4: 73,212
screw4_name: rear left screw
horizontal_move_z: 10
speed: 50
screw_thread: CW-M4

[extruder]
max_extrude_only_distance: 400.0
step_pin: PB3
dir_pin: PB4
enable_pin: !PC3
microsteps: 16
rotation_distance: 33.318
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PA1
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC5
control: pid
pid_kp: 30.480
pid_ki: 2.185
pid_kd: 106.301
min_temp: 0
max_temp: 250
pressure_advance: 0.65

[heater_bed]
heater_pin: PA2
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC4
control: pid
pid_kp: 70.644
pid_ki: 1.330
pid_kd: 937.803
min_temp: 0
max_temp: 130

[fan]
pin: PA0

[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 4000
max_z_velocity: 5
max_z_accel: 100

[input_shaper]
shaper_freq_x: 37.175
shaper_freq_y: 36.452
shaper_type: mzv

[display]
lcd_type: st7920
cs_pin: PB12
sclk_pin: PB13
sid_pin: PB15
encoder_pins: ^PB14, ^PB10
click_pin: ^!PB2

[pwm_cycle_time BEEPER]
pin: PC6
value: 0
shutdown_value: 0
cycle_time: 0.001
scale: 1

[pause_resume]

[display_status]

[idle_timeout]
gcode:
    M84 ; Turn off steppers
    TURN_OFF_HEATERS
    UPDATE_DELAYED_GCODE ID=delayed_printer_off DURATION=300
timeout: 300

[delayed_gcode delayed_printer_off]
initial_duration: 0
gcode:
    {% if printer.idle_timeout.state == "Idle" and printer["gcode_macro stay_on"].stay_on == 0 %}
        { action_respond_info("Idle, powering off") }
        POWER_OFF
    {% endif %}

[gcode_macro stay_on]
variable_stay_on: 0
gcode:
    REPORT MSG="Printer will stay ON"
    SET_GCODE_VARIABLE MACRO=stay_on VARIABLE=stay_on VALUE=1

[gcode_macro allow_off]
gcode:
    REPORT MSG="Printer can now turn OFF automatically"
    SET_GCODE_VARIABLE MACRO=stay_on VARIABLE=stay_on VALUE=0
    {% if printer.idle_timeout.state == "Idle" %}
        UPDATE_DELAYED_GCODE ID=delayed_printer_off DURATION=300
    {% endif %}

[gcode_macro START_PRINT]
gcode:
    {% set bed_temp = params.BED_TEMP | default(60) | float %}
    {% set hotend_temp = params.HOTEND_TEMP | default(215) | float %}
    {% set area_min = params.AREA_MIN | default('unset') %}
    {% set area_max = params.AREA_MAX | default('unset') %}

    REPORT FROM="Start print" MSG="Heating..." BEEPS=1

    ; Set temperatures
    M140 S{bed_temp}
    M104 S{hotend_temp}

    ; Wait for temperatures
    M190 S{bed_temp}
    M109 S{hotend_temp}

    REPORT FROM="Start print" MSG="Homing..."

    ; Home
    G28

    REPORT FROM="Start print" MSG="Probing bed..."

    ; Probe bed
    BED_MESH_CALIBRATE_AREA AREA_MIN={area_min} AREA_MAX={area_max}
    BED_MESH_PROFILE save=print

    ; Reset extruder
    G92 E0

    REPORT FROM="Start print" MSG="Priming..."

    ; Prime extruder
    PRIME_EXTRUDER AREA_MIN={area_min} AREA_MAX={area_max}

    REPORT FROM="Start print" MSG="Printing..."

[gcode_macro END_PRINT]
gcode:
    REPORT FROM="End print" MSG="Finishing..."

    ; Finish moves
    M400

    ; Retract
    G91
    G1 E-2 F2700
    G1 E-2 Z0.2 F2400

    ; Wipe out
    G1 X5 Y5 F3000
    G1 Z10

    ; Present print
    G90
    G1 X0 Y235

    ; Cooldown
    M104 S0
    M140 S0

    ; Disable fan
    M107

    ; Disable steppers except Z
    M84 X Y E

    ; Clear mesh
    BED_MESH_CLEAR

    REPORT FROM="End print" MSG="Done." BEEPS=2

[gcode_macro PAUSE]
rename_existing: PAUSE_BASE
variable_extrude: 1.0
gcode:
    {% set E = printer["gcode_macro PAUSE"].extrude|float %}
    {% set x_park = printer.toolhead.axis_maximum.x|float - 20.0 %}
    {% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %}
    {% set max_z = printer.toolhead.axis_maximum.z|float %}
    {% set act_z = printer.toolhead.position.z|float %}
    {% if act_z < (max_z - 2.0) %}
        {% set z_safe = 2.0 %}
    {% else %}
        {% set z_safe = max_z - act_z %}
    {% endif %}
    PAUSE_BASE
    G91
    {% if printer.extruder.can_extrude|lower == 'true' %}
        G1 E-{E} F2100
    {% else %}
        {action_respond_info("Extruder not hot enough")}
    {% endif %}
    {% if "xyz" in printer.toolhead.homed_axes %}
        G1 Z{z_safe} F900
        G90
        G1 X{x_park} Y{y_park} F6000
    {% else %}
        {action_respond_info("Printer not homed")}
    {% endif %}

[gcode_macro RESUME]
rename_existing: RESUME_BASE
gcode:
    {% set E = printer["gcode_macro PAUSE"].extrude|float %}
    {% if 'VELOCITY' in params|upper %}
        {% set get_params = ('VELOCITY=' + params.VELOCITY)  %}
    {%else %}
        {% set get_params = "" %}
    {% endif %}
    {% if printer.extruder.can_extrude|lower == 'true' %}
        G91
        G1 E{E} F2100
    {% else %}
        {action_respond_info("Extruder not hot enough")}
    {% endif %}
    RESUME_BASE {get_params}

[gcode_macro CANCEL_PRINT]
rename_existing: CANCEL_PRINT_BASE
gcode:
    REPORT FROM="Cancel print" MSG="Cancelling..."

    ; Retract
    G91
    G1 E-2 F2700
    G1 E-2 Z0.2 F2400

    ; Wipe out
    G1 X5 Y5 F3000
    G1 Z10

    ; Present print
    G90
    G1 X0 Y235

    REPORT FROM="Cancel print" MSG="Cancelled." BEEPS=2

    ; Cancel
    TURN_OFF_HEATERS
    CANCEL_PRINT_BASE

[gcode_macro UNLOAD_FILAMENT]
gcode:
    {% set temp = params.TEMP|default(215)|float %}
    {% set length = params.LENGTH|default(350)|float %}
    {% set extrude = params.EXTRUDE|default(10)|float %}

    {% set fastretract = length - 100.0 %}

    REPORT FROM="Unload" MSG="Heating..."

    M109 S{temp}

    REPORT FROM="Unload" MSG="Unloading..."

    M83
    G1 E{extrude} F60
    G1 E-{extrude} F600
    G1 E-100 F300
    G1 E-{fastretract} F600
    M84 E

    REPORT FROM="Unload" MSG="Unload done." BEEPS=1

[gcode_macro LOAD_FILAMENT]
gcode:
    {% set temp = params.TEMP|default(215)|float %}
    {% set length = params.LENGTH|default(350)|float %}
    {% set extrude = params.EXTRUDE|default(10)|float %}

    {% set fastload = length - 100.0 %}

    REPORT FROM="Load" MSG="Heating..."

    M109 S{temp}

    REPORT FROM="Load" MSG="Loading..."

    M83
    G1 E{fastload} F600
    G1 E50 F300
    G1 E30 F150
    G1 E20 F60
    G1 E{extrude} F60
    G1 E-5 F600
    M84 E

    REPORT FROM="Load" MSG="Load done." BEEPS=1

[gcode_macro SET_FLOW]
gcode:
    {% set flow = params.FLOW|default(100)|float %}
    M221 S{flow}

[gcode_macro M300]
gcode:
    {% set S = params.S|default(1000)|int %}
    {% set P = params.P|default(100)|int %}
    ; L varies the PWM on time, close to 0 or 1 the tone gets a bit quieter. 0.5 is a symmetric waveform
    {% set L = 0.5 %}
    {% if S <= 0 %}
        {% set F = 1 %}
        {% set L = 0 %}
    {% elif S >= 10000 %}
        {% set F = 0 %}
    {% else %}
        {% set F = 1/S %}
    {% endif %}

    SET_PIN PIN=BEEPER VALUE={L} CYCLE_TIME={F}
    G4 P{P}
    SET_PIN PIN=BEEPER VALUE=0

[gcode_macro BEEP]
gcode:
    {% set count = params.COUNT|default(1)|int %}
    M300 S4000
    {% if count > 1 %}
        {% for i in range(count - 1) %}
            G4 P100
            M300 S4000
        {% endfor %}
    {% endif %}

[gcode_macro BED_MESH_CALIBRATE_AREA]
gcode:
    ; Parameters:
    ;  AREA_MIN=x0,y0 (defaults to bed_mesh config)
    ;  AREA_MAX=x1,y1 (defaults to bed_mesh config)
    ;  SPACING=50,50
    ;  MIN_POINTS=3,3

    {% set bed_mesh = printer.configfile.config.bed_mesh %}

    {% set mesh_min = bed_mesh.mesh_min %}
    {% set mesh_min_x = mesh_min.split(",")[0] | float %}
    {% set mesh_min_y = mesh_min.split(",")[1] | float %}
    {% set mesh_max = bed_mesh.mesh_max %}
    {% set mesh_max_x = mesh_max.split(",")[0] | float %}
    {% set mesh_max_y = mesh_max.split(",")[1] | float %}

    {% set mesh_count = bed_mesh.probe_count %}
    {% set mesh_count_x = mesh_count.split(",")[0] | int %}
    {% set mesh_count_y = mesh_count.split(",")[1] | int %}

    {% set area_min = params.AREA_MIN | default(mesh_min) %}
    {% if area_min == 'unset' %}
        {% set area_min = mesh_min %}
    {% endif %}
    {% set area_min_x = area_min.split(",")[0] | float %}
    {% set area_min_y = area_min.split(",")[1] | float %}

    {% set area_max = params.AREA_MAX | default(mesh_max) %}
    {% if area_max == 'unset' %}
        {% set area_max = mesh_max %}
    {% endif %}
    {% set area_max_x = area_max.split(",")[0] | float %}
    {% set area_max_y = area_max.split(",")[1] | float %}

    {% set min_points = params.MIN_POINTS | default("3,3") %}
    {% set min_points_x = min_points.split(",")[0] | int %}
    {% set min_points_y = min_points.split(",")[1] | int %}

    {% set spacing = params.SPACING | default("50,50") %}
    {% set spacing_x = spacing.split(",")[0] | int %}
    {% set spacing_y = spacing.split(",")[1] | int %}

    {% if (area_min_x >= area_max_x) or (area_min_y >= area_max_y) %}
        REPORT FROM="Mesh probe area" MSG="Invalid area, using normal calibration"
        BED_MESH_CALIBRATE
    {% else %}
        {% if area_min_x < mesh_min_x %}
            {% set area_min_x = mesh_min_x %}
        {% endif %}

        {% if area_min_y < mesh_min_y %}
            {% set area_min_y = mesh_min_y %}
        {% endif %}

        {% if area_max_x > mesh_max_x %}
            {% set area_max_x = mesh_max_x %}
        {% endif %}

        {% if area_max_y > mesh_max_y %}
            {% set area_max_y = mesh_max_y %}
        {% endif %}

        {% set points_x = (1 + (area_max_x - area_min_x) / spacing_x) | round(0, 'ceil') | int %}
        {% set points_y = (1 + (area_max_y - area_min_y) / spacing_y) | round(0, 'ceil') | int %}

        {% if points_x < min_points_x %}
            {% set points_x = min_points_x %}
        {% endif %}

        {% if points_y < min_points_y %}
            {% set points_y = min_points_y %}
        {% endif %}

        {% set message = "Probing from (%f, %f) to (%f, %f) with %d,%d points" % (area_min_x, area_max_x, area_min_y, area_max_y, points_x, points_y) %}
        REPORT FROM="Mesh probe area" MSG="{message}"
        BED_MESH_CALIBRATE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={points_x},{points_y}
    {% endif %}

[gcode_macro PRIME_EXTRUDER]
gcode:
    ; Parameters
    ;   AREA_MIN=x0,y0 AREA_MAX=x1,y1   printing area
    ;   PRIME_OFFSET=5                  priming distance from area
    ;   PRIME_LENGTH=200                prime total length on the bed
    ;   PRIME_DELTA=0.3                 distance between prime lines
    ;   PRIME_Z=0.2                     prime layer height

    {% set filament_diameter = printer.configfile.config.extruder.filament_diameter | float %}
    {% set pi = 3.1416 %}

    {% set bed_mesh = printer.configfile.config.bed_mesh %}
    {% set mesh_min = bed_mesh.mesh_min %}
    {% set mesh_min_x = mesh_min.split(",")[0] | float %}
    {% set mesh_max = bed_mesh.mesh_max %}

    {% set prime_offset = params.PRIME_OFFSET | default("5") | float %}
    {% set prime_length = params.PRIME_LENGTH | default("200") | float %}
    {% set prime_delta = params.PRIME_DELTA | default("0.3") | float %}
    {% set prime_z = params.PRIME_Z | default("0.3") | float %}

    {% set area_min = params.AREA_MIN | default(mesh_min) %}
    {% if area_min == 'unset' %}
        {% set area_min = mesh_min %}
    {% endif %}
    {% set area_min_x = area_min.split(",")[0] | float %}
    {% set area_min_y = area_min.split(",")[1] | float %}
    
    {% set area_max = params.AREA_MAX | default(mesh_max) %}
    {% if area_max == 'unset' %}
        {% set area_max = mesh_max %}
    {% endif %}
    {% set area_max_x = area_max.split(",")[0] | float %}
    {% set area_max_y = area_max.split(",")[1] | float %}

    {% set prime_x = area_min_x - prime_offset %}
    {% if prime_x < mesh_min_x %}
        {% set prime_x = mesh_min_x %}
    {% endif %}

    {% set prime_dx = prime_delta %}

    {% set prime_y = area_min_y %}
    {% set prime_dy = area_max_y - area_min_y %}
    {% set prime_mdy = -prime_dy %}

    {% set prime_max_lines = (prime_offset / prime_dx) | round(0, 'floor') | int %}
    {% set prime_lines = (prime_length / prime_dy) | round(0, 'ceil') | int %}
    {% if prime_lines > prime_max_lines %}
        {% set prime_lines = prime_max_lines %}
    {% endif %}

    {% set prime_line_extrude = prime_dy / 15.0 | round(5) %}
    
    G90 ; absolute
    G1 Z2.0 F3000 ; move up
    G1 X{prime_x} Y{prime_y} Z2.0 F5000.0 ; move above start position
    G1 Z{prime_z} F1500.0 ; move down
    G91 ; relative

    {% for index in range(0, prime_lines) %}
        {% if index % 2 == 0 %}
            G92 E0 ; reset extruder
            G1 X0 Y{prime_dy} Z0 F1500.0 E{prime_line_extrude} ; extrude line
            G1 X{prime_dx} Y0 Z0 F1500.0 ; move sideways
        {% else %}
            G92 E0 ; reset extruder
            G1 X0 Y{prime_mdy} Z0 F1500.0 E{prime_line_extrude} ; extrude line
            G1 X{prime_dx} Y0 Z0 F1500.0 ; move sideways
        {% endif %}
    {% endfor %}

    G90 ; absolute
    G1 Z2.0 F1500.0 ; move up

    {% if prime_lines % 2 == 0 %}
        G1 X{area_min_x} Y{area_min_y} Z{prime_z} F1500.0 ; move sideways and back down
    {% else %}
        G1 X{area_min_x} Y{area_min_y + prime_dy} Z{prime_z} F1500.0 ; move sideways and back down
    {% endif %}

    G92 E0 ; reset extruder

[gcode_macro POWER_ON]
gcode:
    {action_call_remote_method("set_device_power",
                               device="ender3",
                               state="on")}

[gcode_macro POWER_OFF] 
gcode:
    {action_call_remote_method("set_device_power",
                               device="ender3",
                               state="off")}

[gcode_macro LED_ON]
gcode:
    {action_call_remote_method("set_device_power",
                               device="ender3-led",
                               state="on")}

[gcode_macro LED_OFF]
gcode:
    {action_call_remote_method("set_device_power",
                               device="ender3-led",
                               state="off")}


[gcode_macro REPORT]
gcode:
    {% set msg = params.MSG %}
    {% set src = params.FROM | default("") %}
    {% set beeps = params.BEEPS | default(0) | int %}

    M117 {msg}
    
    {% if src == "" %}
        { action_respond_info(msg) }
    {% else %}
        {% set respond = "%s: %s" % (src, msg) %}
        { action_respond_info(respond) }
    {% endif %}
    
    {% if beeps > 0 %}
        BEEP COUNT={beeps}
    {% endif %}

[temperature_sensor pi_soc]
sensor_type: temperature_host
sensor_path: /sys/class/thermal/thermal_zone0/temp
min_temp: 20
max_temp: 90

Unfortunately, it’s very difficult to track down issues like this. It usually is indicative of something in the underlying operating system (as typically Python processes don’t core dump). Sometimes reinstalling the OS or changing sdcards can help.

If you do think it is due to a regression in the Klipper software and you are comfortable with software development tools, you could try performing a git bisect session to identify the commit that introduces the regression (you should be able to find guides online discussing how to use git bisect).

-Kevin

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.