Commit Graph

305 Commits

Author SHA1 Message Date
Kevin O'Connor
e96a944f33 mcu: It is not necessary to export an is_shutdown() method
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-18 12:18:18 -04:00
Kevin O'Connor
0d0d3917c9 motion_report: Simplify shutdown_clock tracking
Determine which mcu raised the shutdown from the shutdown details
report.  Also, pass shutdown_clock via that details report.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-18 12:18:18 -04:00
Kevin O'Connor
bc27bd9a13 mcu: Move shutdown debugging to "klippy:analyze_shutdown" event
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-18 12:18:18 -04:00
Kevin O'Connor
a43846c277 mcu: Reorganize wrapper methods in main mcu class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
95f263fa59 mcu: Directly register "mcu_identify" handler in each helper class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
de73e41d0f mcu: Add new MCURestartHelper helper class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
64c155121e mcu: Add new MCUConfigHelper helper class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
1bb674d0b8 mcu: Add new MCUStatsHelper() helper class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
1668d6d7c6 mcu: Separate low-level connection handling to new MCUConnectHelper class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
b086349a9f mcu: Setup debugging estimated_print_time() in constructor
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
1e18f32914 mcu: Move registration of "starting" message to _post_attach_setup_shutdown()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
fcd9cefb3f mcu: Add _check_restart_on_xxx() helper methods
Breakout each of the possible restart cases into its own internal
method.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
ce55d41166 mcu: Split _mcu_identify() into separate methods
Split up the _mcu_identify() into several internal methods separated
by functionality.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
07466411ac mcu: Remove max_stepper_error config parameter
Use a regular code constant - MAX_STEPCOMPRESS_ERROR in stepper.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-10-03 12:28:38 -04:00
Kevin O'Connor
3bed65f10f motion_queuing: Move remaining steppersync logic from mcu module
Move the last parts of the steppersync logic into the motion_queuing
module.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-09-12 22:41:30 -04:00
Kevin O'Connor
3aadda6fb3 mcu: Disable waiting in send_wait_ack() if in debugging mode
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-22 16:53:34 -04:00
Kevin O'Connor
864c78f24a motion_queueing: Add flush_steppersync()
Move the mcu.flush_moves() code to motion_queuing.flush_steppersync().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-11 19:43:35 -04:00
Kevin O'Connor
c09ca4cf5a motion_queuing: Add register_flush_callback()
Move register_flush_callback() from mcu.py code to motion_queuing
module.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-11 19:43:34 -04:00
Kevin O'Connor
6f685e9e01 motion_queuing: Add allocate_stepcompress() call
Allocate the low-level C stepcompress object in the motion_queuing
module.  This simplifies the mcu.py code as it no longer needs to
track the stepqueues for the steppersync object.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-11 19:43:34 -04:00
Kevin O'Connor
128226fe8a motion_queuing: Add allocate_steppersync() call
Allocate the low-level C steppersync object from the motion_queuing
module.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-08-11 19:43:34 -04:00
Timofey Titovets
39d01158ba serialhdl: name the threads per mcu
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-08-01 12:42:53 -04:00
Kevin O'Connor
697c6e8d28 mcu: Avoid altering self.TIMEOUT_TIME in RetryAsyncCommand
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-07-11 10:56:03 -04:00
Timofey Titovets
37ddab223f mcu: allow disable send retries
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
2025-07-11 10:46:57 -04:00
Kevin O'Connor
42faa962fc mcu: Decrease mcu.max_nominal_duration() to 3 seconds from 5
This allows the mcu to utilize faster internal speeds.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-04-28 19:28:52 -04:00
Kevin O'Connor
cc919a5f8d mcu: Add new min_schedule_time() and max_nominal_duration() helpers
Add a function that returns the minimum amount of time the host needs
to reserve for messages to be sent from host to micro-controller.

Add a function that returns the maximum amount of time (in seconds)
that all micro-controllers should be able to schedule future timers
at.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-04-28 19:28:52 -04:00
Kevin O'Connor
2db2ef82f2 canbus_stats: Periodically report canbus interface statistics
Add support for a new get_canbus_status command to canserial.c .

Add new canbus_stats.py module that will periodically query canbus
mcus for connection status information.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2025-02-02 18:43:34 -05:00
Kevin O'Connor
f0a7797712 mcu: Only warn about mcu clock frequency if drift is more than 1%
This reduces the chance of spurious MCU clock configuration warnings.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-10-26 22:07:45 -04:00
Kevin O'Connor
d89722056b mcu: Rename setup_minmax() to setup_adc_sample()
Rename this method so that it is more distinct from the the common
temperature setup_minmax() method.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-06-21 15:32:30 -04:00
Kevin O'Connor
4ac283cc0e error_mcu: Move shutdown error message formatting to new error_mcu.py module
Create a new module to help format verbose mcu error messages.  Move
the shutdown message formatting to this module.  This moves the error
formatting out of the background thread and out of the critical
shutdown code path.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-06-21 15:32:30 -04:00
Kevin O'Connor
11f04ba1ba configfile: Allow getchoice() to take a list
If a list is passed to getchoice(), seamlessly convert it to a dict.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-06-17 13:49:05 -04:00
Kevin O'Connor
17c645f000 msgproto: Support multi-byte command and response ids
Update the msgproto.py code so that it can support message ids that
are larger than a single byte.  (The host C code in
klippy/chelper/msgblock.c already supports multi-byte ids.)

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-06-10 12:27:12 -04:00
Kevin O'Connor
37482178b5 mcu: Raise an error on a failed home_wait() call
Raise a printer.command_error exception if a home_wait() call fails.
This makes it easier to support future types of homing errors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-05-21 20:16:31 -04:00
Kevin O'Connor
fa5fa74761 mcu: Separate trdispatch handling from MCU_endstop class
Create a new TriggerDispatch class to track the low-level handling of
the trdispatch mechanism.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-04-09 16:32:43 -04:00
Kamil Domański
01c7befacb klippy: remove a few unused variable assignments (#6504)
Signed-off-by: Kamil Domański <kamil@domanski.co>
2024-04-05 17:43:43 -04:00
Kevin O'Connor
0291a1554c configfile: Add support for reporting runtime_warnings via the API server
Add a new runtime_warning() method that will add a 'runtime_warning'
type message to the printer.configfile.warnings object.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-03-13 21:44:32 -04:00
Kevin O'Connor
d99d1a8463 mcu: Write a warning to the log if an incorrect mcu frequency is detected
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-03-13 21:44:32 -04:00
Kevin O'Connor
43a9685c58 mcu: Remove support for set_pwm() cycle_time parameter
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-23 20:04:03 -05:00
Kevin O'Connor
7abafb575b mcu: Remove support for "static" pins
Update static_digital_output.py to directly configure static digital
pins.  There are no other users of "static" pins, so remove that
support from mcu.py, replicape.py, and sx1509.py.  This simplifies the
low-level pin handling code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-23 20:04:03 -05:00
Kevin O'Connor
83d0d2f19b mcu: Add send_wait_ack() support to CommandWrapper
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-19 11:55:15 -05:00
Kevin O'Connor
1ea9f3aa35 mcu: Increase trsync_state reporting during multi-mcu homing
The current code has the mcu report a trsync_state message every 10ms
and expects a time extension within 25ms.  However, this means that if
a single mcu->host report is lost then 20ms would elapse until the
next report, which would allow for only a 5ms round-trip time before a
timeout error is reported.

Increase the trsync_state timing so that a message is sent every
7.5ms.  This increases the total number of messages per second sent
from mcu to host to 133 (from 100).  With this change, a single lost
message would still allow for up to a 10ms round-trip time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-16 14:19:11 -05:00
Kevin O'Connor
dab39c02cd mcu: Stagger trsync reporting time during multi-mcu homing
When multiple MCUs are involved in homing, stagger the scheduling of
the trsync_state report messages from each mcu.  Staggering helps
spread the bandwidth, helps reduce locking contention in the host, and
reduces the chance that intermittent latency could result in a
communication timeout.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-16 14:19:11 -05:00
Francois Chagnon
d7f6348ae6 toolhead: Keep stepcompress move history relative to current time (#6439)
Expire history relative to current time rather than last move in history queue

Signed-off-by: Francois Chagnon <fc@francoischagnon.net>
2023-12-30 11:34:21 -05:00
Kevin O'Connor
1e5f688b53 mcu: Add support for registering callbacks during move queue flush
Support notification callbacks each time the mcu move queue is
flushed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-16 15:42:39 -05:00
Kevin O'Connor
e9bf2d4c5c mcu: Enhance RetryAsyncCommand to handle low-level retransmits
The RetryAsyncCommand code needs to ensure that any response messages
are not from a previous (unrelated) query.  To do that it compares the
'#sent_time' from potential responses to ensure they are not from a
previous session.  However, if there are any low-level serial
retransmits then the low-level code sets the '#sent_time' to zero (to
indicate that the query send time is not strictly known).  That could
result in a valid response not being accepted by RetryAsyncCommand.

If a low-level connection is experiencing a small amount of periodic
retransmits it could result in multiple high-level retry attempts
failing to the point that there is a user-facing error.  This could
result in "Timeout on wait for 'tmcuart_response' response" errors.

Fix by accepting responses even if there is a low-level retransmit
once the code can confirm that there can be no previous query still in
progress.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-09-21 14:52:55 -04:00
Kevin O'Connor
d881171739 mcu: Move lookup_command_tag() to CommandWrapper class
Use mcu.lookup_command().get_command_tag() instead of
mcu.lookup_command_tag().  This improves error reporting on a protocol
mismatch.  It also enables support for a msgtag that is negative.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-02-22 11:34:36 -05:00
Kevin O'Connor
69dcda1696 mcu: Code movement in mcu.py
This is code movement and comment updates only - no code changes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-02-22 11:34:31 -05:00
Kevin O'Connor
4395ae96a7 serialhdl: Add a get_serialqueue() method
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-01-06 11:59:35 -05:00
Kevin O'Connor
751bff7d38 mcu: Delay reset signaling for usb to canbus bridge nodes
An mcu device acting as an "mcu bridge" should only be reset after
other normal devices are reset - otherwise the bridge wont be able to
pass along the reset message to the downstream mcus.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-07-29 11:40:54 -04:00
Kevin O'Connor
faea45e60f mcu: Add checks to ensure pin max_duration doesn't overflow 32bit counter
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-11-22 10:11:09 -05:00
Kevin O'Connor
d1e13b7e12 mcu: Verify start value equal to shutdown value when using max duration
The mcu can only enforce the max duration if the start value is the
same as the shutdown value, so verify that before configuing the mcu.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-11-22 10:08:56 -05:00