I am making my own custom 3D printer and using the STM32 NUCLEO-G474RE development board (having the G474 MCU), am using the Raspi 4B 4GB as my host. I used KIAUH to install Klipper (v0.13.0-433), Moonraker (v0.9.3-130) and Mainsail (v2.16.0).
I am also able to successfully flash the Klipper firmware onto the board using the st-flash command using the on-board ST-Link (for some reason it fails if I try to flash using KIAUH, probably because I’m not trying to put my device into DFU mode, but don’t need that anyways). The Klipper Firmware Configuration for the same has been shown in the image below :-
(I even tried using Internal clock as Clock reference and 115200 as my baud rate but that didn’t work either.)
So after configuring my printer.cfg file(attached below) :-
#===========================================================
# NUCLEO-G474RE + TMC2209 (STEP/DIR only) + Multi-axis
#===========================================================
[include mainsail.cfg]
[mcu]
serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
#serial: /dev/ttyUSB0
baud: 250000
#baud: 115200
restart_method: command
[virtual_sdcard]
path: /home/delta-zero/printer_data/gcodes
on_error_gcode: CANCEL_PRINT
#-----------------------------------------------------------
# Printer setup
#-----------------------------------------------------------
[printer]
kinematics: corexy
max_velocity: 300
max_accel: 3000
square_corner_velocity: 5.0
max_z_velocity: 15
max_z_accel: 200
#===========================================================
# STEPPERS (TMC2209 in STEP/DIR mode only)
# - X/Y steppers on GPIO port A
# - Z steppers on GPIO port B + C
# - Extruders on GPIO port C
#===========================================================
#------------------- X Axis (dual motors) ------------------
[stepper_x]
step_pin: PA4
dir_pin: !PA5
# Optical X-min endstop
endstop_pin: ^PC14
position_endstop: 0
position_min: 0
position_max: 300
microsteps: 16
rotation_distance: 40 # tune for your mechanics
homing_speed: 50
[stepper_x1]
# Second X motor (mirrored belt)
step_pin: PA6
dir_pin: !PA7
rotation_distance: 40
microsteps: 16
# No separate endstop – follows stepper_x
#------------------- Y Axis (dual motors) ------------------
[stepper_y]
step_pin: PC10
dir_pin: !PC11
# Optical Y-min endstop
endstop_pin: ^PC15
position_endstop: 0
position_min: 0
position_max: 300
microsteps: 16
rotation_distance: 40
homing_speed: 50
[stepper_y1]
# Second Y motor
step_pin: PA11
dir_pin: !PA12
rotation_distance: 40
microsteps: 16
# No separate endstop – follows stepper_y
#------------------- Z Axis (triple motors) ----------------
[stepper_z]
# Z motor 0
step_pin: PB3
dir_pin: !PB4
# Optical Z-min endstop (or could use probe later)
endstop_pin: ^PF0
position_endstop: 0
position_min: 0
position_max: 400
microsteps: 16
rotation_distance: 8
microsteps: 16
[stepper_z1]
# Z motor 1
step_pin: PB5
dir_pin: !PB8
rotation_distance: 8
microsteps: 16
# No endstop; follows Z
[stepper_z2]
# Z motor 2
step_pin: PB9
dir_pin: !PC3
rotation_distance: 8
microsteps: 16
# No endstop; follows Z
#===========================================================
# EXTRUDERS (dual)
# TMC2209 via STEP/DIR only – no enable/uart/spread pins
#===========================================================
#------------------- Extruder 0 ----------------------------
[extruder]
# Stepper
step_pin: PC4
dir_pin: !PC5
microsteps: 16
rotation_distance: 33.5 # typical for 1.75mm direct – tune
nozzle_diameter: 0.4
filament_diameter: 1.75
# Thermal
heater_pin: PB7 # Hotend 0 heater MOSFET
sensor_type: EPCOS 100K B57560G104F # example NTC – change if needed
sensor_pin: PB0 # Extruder 0 sensor 1
min_temp: 0
max_temp: 280
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
#------------------- Extruder 1 ----------------------------
[extruder1]
# Stepper
step_pin: PC6
dir_pin: !PC8
microsteps: 16
rotation_distance: 33.5 # tune as needed
nozzle_diameter: 0.4
filament_diameter: 1.75
# Thermal
heater_pin: PD2 # Hotend 1 heater MOSFET
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PB2 # Extruder 1 sensor 1
min_temp: 0
max_temp: 280
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
#===========================================================
# HEATED BED (1 heater, 6 sensors)
#===========================================================
[heater_bed]
heater_pin: PB6 # Bed heater MOSFET
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA0 # Bed sensor 1 (primary control)
min_temp: 0
max_temp: 120
control: pid
pid_Kp: 60
pid_Ki: 2
pid_Kd: 400
# Additional bed sensors (monitoring only)
[temperature_sensor bed_sense_2]
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA1
[temperature_sensor bed_sense_3]
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA2
[temperature_sensor bed_sense_4]
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA3
[temperature_sensor bed_sense_5]
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC0
[temperature_sensor bed_sense_6]
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC1
# Extra extruder sensors (second thermistor on each hotend)
[temperature_sensor ext0_sense_2]
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PB1 # Extruder 0 second sensor
[temperature_sensor ext1_sense_2]
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC2 # Extruder 1 second sensor
#===========================================================
# ENDSTOPS (5 optical)
# - X_min, Y_min, Z_min wired in stepper sections
# - X_max, Y_max as gcode buttons for monitoring/soft-limits
#===========================================================
# X_min -> PC4 (in [stepper_x])
# Y_min -> PC5 (in [stepper_y])
# Z_min -> PC6 (in [stepper_z])
[gcode_button x_max_endstop]
pin: ^PC12
press_gcode:
M118 X_MAX endstop TRIGGERED
release_gcode:
M118 X_MAX endstop RELEASED
[gcode_button y_max_endstop]
pin: ^PA8
press_gcode:
M118 Y_MAX endstop TRIGGERED
release_gcode:
M118 Y_MAX endstop RELEASED
#===========================================================
# PIEZO Z SENSORS (3)
# - One used as main Z probe
# - Two exposed as gcode buttons for diagnostics
#===========================================================
[probe]
pin: ^PC13 # Piezo 0 digital output
x_offset: 0
y_offset: 0
z_offset: 0.0 # Calibrate
speed: 5
samples: 2
samples_tolerance: 0.02
[gcode_button piezo_1_diag]
pin: ^PA15
press_gcode:
M118 PIEZO_1 TRIGGERED
release_gcode:
M118 PIEZO_1 RELEASED
[gcode_button piezo_2_diag]
pin: ^PB10
press_gcode:
M118 PIEZO_2 TRIGGERED
release_gcode:
M118 PIEZO_2 RELEASED
#===========================================================
# FANS (4 total)
# Grouped on GPIO port C high pins
#===========================================================
# Part cooling fan for tool 0
[fan]
pin: PF1
kick_start_time: 0.2
off_below: 0.1
# Hotend 0 heatsink fan (auto on with extruder temp)
[heater_fan hotend0_fan]
pin: PC9
heater: extruder
kick_start_time: 0.5
fan_speed: 1.0
#===========================================================
# HOMING, SAFE Z, & STATUS
#===========================================================
[safe_z_home]
home_xy_position: 150, 150 # center of bed (adjust to your size)
speed: 60
z_hop: 5
z_hop_speed: 20
[idle_timeout]
timeout: 900
[pause_resume]
[display_status]
#===========================================================
# OPTIONAL: Z TILT (if each Z motor drives a different corner)
# Define points later once mechanics are fixed.
#===========================================================
# [z_tilt]
# z_positions:
# x1 y1
# x2 y2
# x3 y3
# points:
# x1 y1
# x2 y2
# x3 y3
# speed: 50
# horizontal_move_z: 5
I connect my Raspi and STM dev board using a USB-to-UART device. but when Mainsail tries to communicate with the firmware, the firmware doesn’t reply back and Mainsail throws an error like this (referenced from my klippy.log file) :-
mcu ‘mcu’: Starting serial connect
webhooks client 548633187664: New connection
webhooks client 548633187664: Client info {‘program’: ‘Moonraker’, ‘version’: ‘v0.9.3-130-g5b92e52’}
mcu ‘mcu’: Timeout on connect
mcu ‘mcu’: Wait for identify_response
Traceback (most recent call last):
File “/home/delta-zero/klipper/klippy/serialhdl.py”, line 75, in _get_identify_data
params = self.send_with_response(msg, ‘identify_response’)
File “/home/delta-zero/klipper/klippy/serialhdl.py”, line 271, in send_with_response
return src.get_response([cmd], self.default_cmd_queue)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/delta-zero/klipper/klippy/serialhdl.py”, line 331, in get_response
self.serial.raw_send_wait_ack(cmds[-1], minclock, reqclock,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cmd_queue)
^^^^^^^^^^
File “/home/delta-zero/klipper/klippy/serialhdl.py”, line 263, in raw_send_wait_ack
self._error(“Serial connection closed”)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/delta-zero/klipper/klippy/serialhdl.py”, line 68, in _error
raise error(self.warn_prefix + (msg % params))
serialhdl.error: mcu ‘mcu’: Serial connection closed
Now, I have performed various check to verify whether all parameters are correct or not :-
- My TX/RX pins are connected the correct way, Tx→Rx and Rx→Tx.
- I have verified successful flash on the MCU using the STM32CubeProgrammer software.
- I even flashed my own firmware containing a small UART transmit code onto the same board to verify whether there wasn’t a hardware or pin issue.
So I have performed all the basic checks and still haven’t been able to pinpoint the exact problem. Also, there is no existing 3D printer that I could find that uses the same hardware configuration like mine, which makes this even harder. Now after days of debugging the issue I feel the problem could be either :-
- The Klipper firmware build itself has an issue, or
- My printer.cfg file is not upto the mark for my board.
I would be highly obliged if someone could help me out here, thanks!
Update: So I noticed in the Option Bytes setttings for my NUCLEO-G474RE, I had checked the nBOOT0 option, hence setting the nBOOT0 bit to 1. This caused the mcu to boot from system memory and not from flash. I corrected this, but still I am facing the same issue of MCU not communicating with host.
klippy.log (1.2 MB)
