From 09e32d1b8454b64b8571a15b95b27a8f9412a777 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 5 Sep 2017 21:15:24 -0400 Subject: [PATCH] mcu: Provide some further help on common MCU shutdown errors Signed-off-by: Kevin O'Connor --- klippy/klippy.py | 3 +-- klippy/mcu.py | 30 ++++++++++++++++++++++++++++-- src/adccmds.c | 2 +- src/basecmd.c | 2 +- src/stepper.c | 2 +- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/klippy/klippy.py b/klippy/klippy.py index ae4ea656..60bb9359 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -242,8 +242,7 @@ class Printer: def note_shutdown(self, msg): if self.state_message == message_ready: self.need_dump_debug = True - self.state_message = "Firmware shutdown: %s%s" % ( - msg, message_shutdown) + self.state_message = "%s%s" % (msg, message_shutdown) self.gcode.set_printer_ready(False) def note_mcu_error(self, msg): self.state_message = "%s%s" % (msg, message_restart) diff --git a/klippy/mcu.py b/klippy/mcu.py index 7724e63e..c0fc8f6d 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -475,13 +475,16 @@ class MCU: if self.is_shutdown: return self.is_shutdown = True - self._shutdown_msg = params['#msg'] + self._shutdown_msg = msg = params['#msg'] logging.info("%s: %s" % (params['#name'], self._shutdown_msg)) pst = self._print_start_time logging.info("Clock last synchronized at %.6f (%d)" % ( pst, int(pst * self._mcu_freq))) self.serial.dump_debug() - self._printer.note_shutdown(self._shutdown_msg) + prefix = "MCU shutdown: " + if params['#name'] == 'is_shutdown': + prefix = "Previous MCU shutdown: " + self._printer.note_shutdown(prefix + msg + error_help(msg)) # Connection phase def _check_restart(self, reason): start_reason = self._printer.get_start_args().get("start_reason") @@ -742,5 +745,28 @@ class MCU: def __del__(self): self.disconnect() +Common_MCU_errors = { + ("Timer too close", "No next step", "Missed scheduling of next "): """ +This is generally indicative of an intermittent +communication failure.""", + ("ADC out of range",): """ +This generally occurs when a heater temperature exceeds +it's configured min_temp or max_temp.""", + ("Rescheduled timer in the past", "Stepper too far in past"): """ +This generally occurs when the micro-controller has been +requested to step at a rate higher than it is capable of +obtaining.""", + ("Command request",): """ +This generally occurs in response to an M112 G-Code command +or in response to an internal error in the host software.""", +} + +def error_help(msg): + for prefixes, help_msg in Common_MCU_errors.items(): + for prefix in prefixes: + if msg.startswith(prefix): + return help_msg + return "" + def add_printer_objects(printer, config): printer.add_object('mcu', MCU(printer, config.getsection('mcu'))) diff --git a/src/adccmds.c b/src/adccmds.c index 55900ab1..d95ad282 100644 --- a/src/adccmds.c +++ b/src/adccmds.c @@ -43,7 +43,7 @@ analog_in_event(struct timer *timer) return SF_RESCHEDULE; } if (a->value < a->min_value || a->value > a->max_value) - shutdown("adc out of range"); + shutdown("ADC out of range"); sched_wake_task(&analog_wake); a->next_begin_time += a->rest_time; a->timer.waketime = a->next_begin_time; diff --git a/src/basecmd.c b/src/basecmd.c index b5ff738a..08dc6ec2 100644 --- a/src/basecmd.c +++ b/src/basecmd.c @@ -297,7 +297,7 @@ stats_update(uint32_t start, uint32_t cur) void command_emergency_stop(uint32_t *args) { - shutdown("command request"); + shutdown("Command request"); } DECL_COMMAND_FLAGS(command_emergency_stop, HF_IN_SHUTDOWN, "emergency_stop"); diff --git a/src/stepper.c b/src/stepper.c index d849387a..521e0ab8 100644 --- a/src/stepper.c +++ b/src/stepper.c @@ -79,7 +79,7 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time) if (unlikely(timer_is_before(s->next_step_time, min_next_time))) { if ((int32_t)(s->next_step_time - min_next_time) < (int32_t)(-timer_from_us(1000))) - shutdown("stepper too far in past"); + shutdown("Stepper too far in past"); s->time.waketime = min_next_time; } else { s->time.waketime = s->next_step_time;