aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/mcu.py
Commit message (Collapse)AuthorAgeFilesLines
* mcu: Only warn about mcu clock frequency if drift is more than 1%Kevin O'Connor2024-10-261-1/+2
| | | | | | This reduces the chance of spurious MCU clock configuration warnings. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Rename setup_minmax() to setup_adc_sample()Kevin O'Connor2024-06-211-2/+2
| | | | | | | 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>
* error_mcu: Move shutdown error message formatting to new error_mcu.py moduleKevin O'Connor2024-06-211-34/+7
| | | | | | | | | 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>
* configfile: Allow getchoice() to take a listKevin O'Connor2024-06-171-2/+1
| | | | | | If a list is passed to getchoice(), seamlessly convert it to a dict. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* msgproto: Support multi-byte command and response idsKevin O'Connor2024-06-101-1/+1
| | | | | | | | 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>
* mcu: Raise an error on a failed home_wait() callKevin O'Connor2024-05-211-8/+10
| | | | | | | 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>
* mcu: Separate trdispatch handling from MCU_endstop classKevin O'Connor2024-04-091-37/+60
| | | | | | | Create a new TriggerDispatch class to track the low-level handling of the trdispatch mechanism. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: remove a few unused variable assignments (#6504)Kamil Domański2024-04-051-1/+0
| | | Signed-off-by: Kamil Domański <kamil@domanski.co>
* configfile: Add support for reporting runtime_warnings via the API serverKevin O'Connor2024-03-131-2/+4
| | | | | | | 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>
* mcu: Write a warning to the log if an incorrect mcu frequency is detectedKevin O'Connor2024-03-131-0/+14
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Remove support for set_pwm() cycle_time parameterKevin O'Connor2024-01-231-28/+9
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Remove support for "static" pinsKevin O'Connor2024-01-231-24/+2
| | | | | | | | | 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>
* mcu: Add send_wait_ack() support to CommandWrapperKevin O'Connor2024-01-191-0/+3
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Increase trsync_state reporting during multi-mcu homingKevin O'Connor2024-01-161-2/+2
| | | | | | | | | | | | | | | 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>
* mcu: Stagger trsync reporting time during multi-mcu homingKevin O'Connor2024-01-161-5/+10
| | | | | | | | | | 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>
* toolhead: Keep stepcompress move history relative to current time (#6439)Francois Chagnon2023-12-301-2/+5
| | | | | Expire history relative to current time rather than last move in history queue Signed-off-by: Francois Chagnon <fc@francoischagnon.net>
* mcu: Add support for registering callbacks during move queue flushKevin O'Connor2023-12-161-11/+17
| | | | | | | Support notification callbacks each time the mcu move queue is flushed. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Enhance RetryAsyncCommand to handle low-level retransmitsKevin O'Connor2023-09-211-2/+4
| | | | | | | | | | | | | | | | | | | | | 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>
* mcu: Move lookup_command_tag() to CommandWrapper classKevin O'Connor2023-02-221-8/+11
| | | | | | | | 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>
* mcu: Code movement in mcu.pyKevin O'Connor2023-02-221-73/+88
| | | | | | This is code movement and comment updates only - no code changes. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Add a get_serialqueue() methodKevin O'Connor2023-01-061-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Delay reset signaling for usb to canbus bridge nodesKevin O'Connor2022-07-291-2/+13
| | | | | | | | 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>
* mcu: Add checks to ensure pin max_duration doesn't overflow 32bit counterKevin O'Connor2021-11-221-7/+15
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Verify start value equal to shutdown value when using max durationKevin O'Connor2021-11-221-0/+6
| | | | | | | 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>
* mcu: Make a minor change to the protocol to require mcu updateKevin O'Connor2021-11-061-1/+1
| | | | | | | | Commit 9ecddd1b fixed a serious error (introduced in 7d95a004). Force a protocol version change so users are aware of the need to update the mcu code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* pins: Remove support for deprecated pin_map optionKevin O'Connor2021-11-021-4/+0
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Convert to Python3 string encodingKevin O'Connor2021-10-011-1/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* configfile: Add support for reporting deprecated optionsKevin O'Connor2021-09-161-0/+1
| | | | | | | Add a new printer.configfile.warnings with a list of config features that are deprecated. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Support multi-mcu homingKevin O'Connor2021-08-281-12/+31
| | | | | | | Support endstops and probes attached to a different micro-controller than their associated steppers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Return time of trigger from home_wait()Kevin O'Connor2021-08-171-1/+11
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* stepper: Query the stepper mcu position during startupKevin O'Connor2021-08-061-1/+1
| | | | | | | | Try to keep the host mcu_position synchronized with the micro-controller by querying during startup and after every homing event. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Support returning the mcu reported shutdown timeKevin O'Connor2021-07-291-0/+6
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Set reqclock on trsync_start commandsKevin O'Connor2021-07-091-2/+3
| | | | | | | | Set the reqclock on trsync commands to ensure those commands do not cause 32-bit timer rollover errors. Otherwise, it may result in "Timer too close" errors. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* homing: Check for failures during multi-endstop homingKevin O'Connor2021-06-091-1/+3
| | | | | | If any endstop reports a failure, then stop homing on all endstops. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Enable trdispatch infrastructure during homingKevin O'Connor2021-06-091-66/+138
| | | | | | | | | Separate out trsync handling from endstop handling in mcu.py code. Enable the low-level trdispatch C code. This is in preparation for multi-mcu homing. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* trsync: Introduce new "trigger synchronization" supportKevin O'Connor2021-06-091-30/+37
| | | | | | | Separate out the stepper stopping code from endstop.c into its own trsync.c code file. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Raise config_error (not protocol error) on pin enumeration errorsKevin O'Connor2021-06-091-11/+20
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Support prepending a warn_prefix to error and log messagesKevin O'Connor2021-06-091-1/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Report known software versions on a protocol error during connectionKevin O'Connor2021-05-021-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* endstop: Report trigger time in endstop_query responseKevin O'Connor2021-04-301-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* stepper: Remove min_stop_interval from mcu codeKevin O'Connor2021-04-301-1/+1
| | | | | | | Now that the host never uses a min_stop_interval, remove it from the mcu code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Update hints for "Timer too close" and "No next step" errorsKevin O'Connor2021-03-191-1/+6
| | | | | | | In practice, these errors are usually due to problems on the host computer instead of problems with communication. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Add support for connecting to devices on a CAN busKevin O'Connor2021-03-131-6/+19
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* tmc2130: Verify SPI register writesKevin O'Connor2021-03-101-4/+10
| | | | | | | | The tmc2130 (and tmc5160) will respond back with the value written during the next SPI command. Use this feature to verify that the value written matches the value sent. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Update callers to decide serial fd typeKevin O'Connor2021-03-021-17/+17
| | | | | | | | Don't try to detect a "real serial port" in serialhdl.py. Instead, have the callers invoke either connect_uart(), connect_file(), or connect_pipe(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Raise a command_error on a command timeout eventKevin O'Connor2021-02-271-4/+6
| | | | | | | | Raise a printer.command_error() instead of an mcu.error() if a query command does not succeed. That error is less likely to result in an unhandled exception error. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* buildcommands: Extend number of available mcu messages from 96 to 128Kevin O'Connor2021-02-181-2/+2
| | | | | | | | | | | Some internal code treats the message ids as encoded "variable length quantities", while other internal code assumes the message id is always one byte long. Continue using this scheme, but convert the VLQ users to use the name "msgtag" while the 1-byte users use "msgid". Increase the number of available msgids from 96 to 127 - the higher values get encoded as negative "msgtags". Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* msgproto: Avoid peeking into the msgproto class membersKevin O'Connor2021-02-181-7/+10
| | | | | | | Update callers to only use exported methods of the msgproto objects. This makes it easier to make internal changes to the code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Add a get_status() callback with micro-controller info and statsKevin O'Connor2021-01-191-6/+16
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* heaters: Always register heater pin as a pwm pinKevin O'Connor2020-12-151-2/+0
| | | | | | | There's no need to sometimes register the pin as a 'digital_out' pin instead of as a 'pwm' pin. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>