Skip to content

Commit

Permalink
Add reset before flash to BootCommander
Browse files Browse the repository at this point in the history
  • Loading branch information
benlye committed Apr 4, 2021
1 parent d3a324b commit 072ef9a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions octoprint_firmwareupdater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ def get_settings_defaults(self):
"avrdude_disableverify": False,
"avrdude_commandline": "{avrdude} -v -q -p {mcu} -c {programmer} -P {port} -D -C {conffile} -b {baudrate} {disableverify} -U flash:w:{firmware}:i",
"bootcmdr_path": None,
"bootcmdr_preflashreset": True,
"bootcmdr_commandline": "{bootcommander} -d={port} -b={baudrate} {firmware}",
"bootcmdr_baudrate": 115200,
"bootcmdr_command_timeout": 30,
Expand Down
39 changes: 39 additions & 0 deletions octoprint_firmwareupdater/methods/bootcmdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def _flash_bootcmdr(self, firmware=None, printer_port=None, **kwargs):

self._logger.info(u"Running '{}' in {}".format(bootcmdr_command, working_dir))
self._console_logger.info(bootcmdr_command)

if self.get_profile_setting_boolean("bootcmdr_preflashreset"):
self._send_status("progress", subtype="boardreset")
self._logger.info(u"Attempting to reset the board")
if not _reset_board(self, printer_port, bootcmdr_baudrate):
raise FlashException("Reset failed")

try:
starttime = time.time()
connecting = False
Expand Down Expand Up @@ -109,6 +116,38 @@ def _flash_bootcmdr(self, firmware=None, printer_port=None, **kwargs):
self._send_status("flasherror")
return False

def _reset_board(self, printer_port=None, baudrate=None):
assert(printer_port is not None)
assert(baudrate is not None)

self._logger.info(u"Resetting printer at '{port}'".format(port=printer_port))

# Configure the port
try:
os.system('stty -F ' + printer_port + ' speed ' + str(baudrate) + ' -echo > /dev/null')
except:
self._logger.exception(u"Error configuring serial port.")
self._send_status("flasherror", message="Board reset failed")
return False

# Smoothie reset command
try:
os.system('echo reset >> ' + printer_port)
except:
self._logger.exception(u"Error sending Smoothie 'reset' command.")
self._send_status("flasherror", message="Board reset failed")
return False

# Marlin reset command
try:
os.system('echo M997 >> ' + printer_port)
except:
self._logger.exception(u"Error sending Marlin 'M997' command.")
self._send_status("flasherror", message="Board reset failed")
return False

return True

class FlashException(Exception):
def __init__(self, reason, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)
Expand Down
5 changes: 4 additions & 1 deletion octoprint_firmwareupdater/static/js/firmwareupdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ $(function() {
self.configBootCmdrBaudRate = ko.observable();
self.configBootCmdrCommandLine = ko.observable();
self.configBootCmdrCommandTimeout = ko.observable();
self.configBootCmdrResetBeforeFlash = ko.observable();

// Observables for BootCommander UI messages
self.bootCmdrPathBroken = ko.observable(false);
Expand Down Expand Up @@ -725,7 +726,7 @@ $(function() {
break;
}
case "backdoor": {
message = gettext("Trying bootloader backdoor...");
message = gettext("Trying bootloader backdoor - (reset the board if this takes too long)...");
break;
}
case "startingflash": {
Expand Down Expand Up @@ -858,6 +859,7 @@ $(function() {
self.configBootCmdrBaudRate(self.getProfileSetting("bootcmdr_baudrate"));
self.configBootCmdrCommandLine(self.getProfileSetting("bootcmdr_commandline"));
self.configBootCmdrCommandTimeout(self.getProfileSetting("bootcmdr_command_timeout"));
self.configBootCmdrResetBeforeFlash(self.getProfileSetting("bootcmdr_preflashreset"));

// Load the bossac settings
self.configBossacPath(self.getProfileSetting("bossac_path"));
Expand Down Expand Up @@ -978,6 +980,7 @@ $(function() {
profiles[index]["bootcmdr_baudrate"] = self.configBootCmdrBaudRate();
profiles[index]["bootcmdr_commandline"] = self.configBootCmdrCommandLine();
profiles[index]["bootcmdr_command_timeout"] = self.configBootCmdrCommandTimeout();
profiles[index]["bootcmdr_preflashreset"] = self.configBootCmdrResetBeforeFlash();

// Bossac settings
profiles[index]["bossac_path"] = self.configBossacPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@

<!-- Advanced BootCommander options -->
<div data-bind="visible: showBootCmdrConfig">
<div class="control-group">
<label class="control-label">{{ _('Reset before flashing') }}</label>
<div class="controls">
<div class="input">
<input type="checkbox" data-bind="checked: configBootCmdrResetBeforeFlash">
</div>
<span class="help-block">{{ _('If checked the board will be reset before a firmware update is attempted to ensure that the bootloader is active when BootCommander is run.') }}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Command timeout') }}</label>
<div class="controls">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-FirmwareUpdater"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.11.0b2"
plugin_version = "1.11.0b3"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 072ef9a

Please sign in to comment.