-
Notifications
You must be signed in to change notification settings - Fork 179
New Feature: Flash Target Board #466
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
Conversation
…reset) the target after successful compile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits.
mbed/mbed.py
Outdated
elif len(targets) > 1: | ||
error("Multiple targets were detected.\nOnly 1 target board should be connected to your system.") | ||
elif len(targets) == 0: | ||
error("No targets were detected.\nPlease make sure a target board is connected to this system.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On linux, it's not enough to connect the target board to the system. You must also mount the fake file system of the board somewhere. Should we mention this in the error message?
mbed/mbed.py
Outdated
@@ -2221,6 +2231,23 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False, | |||
+ (['-v'] if verbose else []) | |||
+ args, | |||
env=env) | |||
|
|||
if flash: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before trying to flash, should you also check that the return code of the compile job indicates success?
mbed/mbed.py
Outdated
if flash: | ||
fw_name = artifact_name if artifact_name else program.name | ||
fw_fbase = os.path.join(build_path, fw_name) | ||
fw_file = fw_fbase + ('.hex' if os.path.exists(fw_fbase+'.hex') else '.bin') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only check that the .hex
file exists. I think you should check for .bin
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that any of my aforementioned nits should block this PR.
@theotherjimmy Thanks for your comments. All of them make sense (and now addressed) 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I mentioned a few optional usability notes below.
try: | ||
from mbed_host_tests.host_tests_toolbox import flash_dev, reset_dev | ||
except (IOError, ImportError, OSError): | ||
error("The '-f/--flash' option requires that the 'mbed-greentea' python module is installed.\nYou can install mbed-ls by running 'pip install mbed-greentea'.", 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really part of the mbed-host-tests
module, not mbed-greentea
. mbed-greentea
will correctly bring in this dependency though. So it's ok to leave this as is I think, but just thought I'd mention it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The developer never installs mbed-host-tests manually, neither is familiar with this module. Generally we would like to point developer at installing mbed-greentea as foundation of mbed OS testing, not specifically mbed-host-tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
error("The '-f/--flash' option requires that the 'mbed-greentea' python module is installed.\nYou can install mbed-ls by running 'pip install mbed-greentea'.", 1) | ||
|
||
if not flash_dev(detected['msd'], fw_file, program_cycle_s=2): | ||
error("Unable to flash the target board connected to your system.", 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might also prompt the user to check for a FAIL.TXT
on the board for more information. Not necessary though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not have that check that in htrun instead, and have the top flash_dev() function handle it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, also a possibility. Like I said, not necessary and should't block this PR.
@@ -1447,6 +1440,22 @@ def ignore_build_dir(self): | |||
except IOError: | |||
error("Unable to write build ignore file in \"%s\"" % os.path.join(build_path, '.mbedignore'), 1) | |||
|
|||
def detect_target(self, info=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a valid case where you have multiple platforms plugged in, but all of them are different. This could be supported by supplying an optional target name to this function. Shouldn't be too hard to implement:
def detect_target(self, target_name=None, info=None):
targets = self.get_detected_targets()
if target_name:
targets = [t for t in targets if t['name'].upper() == target_name.upper()]
...
(^Note that actual code is totally untested, but the idea should be sound)
But this can always be added in another PR. @screamerbg totally up to you on the priority of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the use case for detecting multiple targets? Also what if I have multiple targets of the same kind mixed with different ones?
I guess I'm missing the point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say I have a LPC1768, a K64F, and an NRF51_DK plugged into my machine. I could run mbed compile -m NRF51_DK ... --flash
and mbed CLI could correctly figure out which board to flash. Can be useful when developing for multiple platforms, but maybe not important as of right now.
Also what if I have multiple targets of the same kind mixed with different ones?
In this case it would have to error like you do above since there are multiple boards (for example, 2 LPC1768s plugged in. You don't know which one to flash just by using the target name).
I'm afraid I'm hindering this PR more than I'm helping it with this comment. I'm happy to submit the change I mentioned above as a PR after this is merged for more discussion.
…ly caused by an old interface firmware
@@ -1447,6 +1440,22 @@ def ignore_build_dir(self): | |||
except IOError: | |||
error("Unable to write build ignore file in \"%s\"" % os.path.join(build_path, '.mbedignore'), 1) | |||
|
|||
def detect_target(self, info=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say I have a LPC1768, a K64F, and an NRF51_DK plugged into my machine. I could run mbed compile -m NRF51_DK ... --flash
and mbed CLI could correctly figure out which board to flash. Can be useful when developing for multiple platforms, but maybe not important as of right now.
Also what if I have multiple targets of the same kind mixed with different ones?
In this case it would have to error like you do above since there are multiple boards (for example, 2 LPC1768s plugged in. You don't know which one to flash just by using the target name).
I'm afraid I'm hindering this PR more than I'm helping it with this comment. I'm happy to submit the change I mentioned above as a PR after this is merged for more discussion.
Added feature support for -f/--flash to
mbed compile
to flash (and reset) connected target board after successful compile.The implementation uses greentea/htrun framework and therefore relies on the same routines as testing.
To use:
Example output: