Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check and warn if mcu frequency differs from configured frequency #6519

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions klippy/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def __init__(self, printer):
self.printer = printer
self.autosave = None
self.deprecated = {}
self.runtime_warnings = []
self.deprecate_warnings = []
self.status_raw_config = {}
self.status_save_pending = {}
self.status_settings = {}
Expand Down Expand Up @@ -314,6 +316,11 @@ def log_config(self, config):
"======================="]
self.printer.set_rollover_info("config", "\n".join(lines))
# Status reporting
def runtime_warning(self, msg):
logging.warn(msg)
res = {'type': 'runtime_warning', 'message': msg}
self.runtime_warnings.append(res)
self.status_warnings = self.runtime_warnings + self.deprecate_warnings
def deprecate(self, section, option, value=None, msg=None):
self.deprecated[(section, option, value)] = msg
def _build_status(self, config):
Expand All @@ -325,7 +332,7 @@ def _build_status(self, config):
self.status_settings = {}
for (section, option), value in config.access_tracking.items():
self.status_settings.setdefault(section, {})[option] = value
self.status_warnings = []
self.deprecate_warnings = []
for (section, option, value), msg in self.deprecated.items():
if value is None:
res = {'type': 'deprecated_option'}
Expand All @@ -334,7 +341,8 @@ def _build_status(self, config):
res['message'] = msg
res['section'] = section
res['option'] = option
self.status_warnings.append(res)
self.deprecate_warnings.append(res)
self.status_warnings = self.runtime_warnings + self.deprecate_warnings
def get_status(self, eventtime):
return {'config': self.status_raw_config,
'settings': self.status_settings,
Expand Down
16 changes: 16 additions & 0 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ def __init__(self, config, clocksync):
printer.register_event_handler("klippy:connect", self._connect)
printer.register_event_handler("klippy:shutdown", self._shutdown)
printer.register_event_handler("klippy:disconnect", self._disconnect)
printer.register_event_handler("klippy:ready", self._ready)
# Serial callbacks
def _handle_mcu_stats(self, params):
count = params['count']
Expand Down Expand Up @@ -799,6 +800,21 @@ def _mcu_identify(self):
self.register_response(self._handle_shutdown, 'shutdown')
self.register_response(self._handle_shutdown, 'is_shutdown')
self.register_response(self._handle_mcu_stats, 'stats')
def _ready(self):
if self.is_fileoutput():
return
# Check that reported mcu frequency is in range
mcu_freq = self._mcu_freq
systime = self._reactor.monotonic()
get_clock = self._clocksync.get_clock
calc_freq = get_clock(systime + 1) - get_clock(systime)
mcu_freq_mhz = int(mcu_freq / 1000000. + 0.5)
calc_freq_mhz = int(calc_freq / 1000000. + 0.5)
if mcu_freq_mhz != calc_freq_mhz:
pconfig = self._printer.lookup_object('configfile')
msg = ("MCU '%s' configured for %dMhz but running at %dMhz!"
% (self._name, mcu_freq_mhz, calc_freq_mhz))
pconfig.runtime_warning(msg)
# Config creation helpers
def setup_pin(self, pin_type, pin_params):
pcs = {'endstop': MCU_endstop,
Expand Down
Loading