Skip to content

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

Merged
merged 5 commits into from
Apr 13, 2017
Merged

Conversation

screamerbg
Copy link
Contributor

@screamerbg screamerbg commented Mar 30, 2017

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:

$ mbed compile -t <toolchain> -m <mcu|DETECT> -f|--flash

Example output:

Total Static RAM memory (data + bss): 22732 bytes
Total RAM memory (data + bss + heap + stack): 22732 bytes
Total Flash memory (text + data + misc): 30266 bytes

Image: .\BUILD\NUCLEO_F429ZI\ARM\mbed-os-example-blinky.bin
[mbed] Detected "NUCLEO_F429ZI" connected to "E:" and using com port "COM6"
        1 file(s) copied.

…reset) the target after successful compile
@screamerbg screamerbg changed the title New Feature: Flash Target New Feature: Flash Target Board Mar 30, 2017
Copy link
Contributor

@theotherjimmy theotherjimmy left a 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.")
Copy link
Contributor

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:
Copy link
Contributor

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')
Copy link
Contributor

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.

Copy link
Contributor

@theotherjimmy theotherjimmy left a 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.

@screamerbg
Copy link
Contributor Author

@theotherjimmy Thanks for your comments. All of them make sense (and now addressed) 👍

Copy link
Contributor

@bridadan bridadan left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

@screamerbg screamerbg Mar 30, 2017

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.

Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor Author

@screamerbg screamerbg Mar 30, 2017

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?

Copy link
Contributor

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):
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@@ -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):
Copy link
Contributor

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.

@screamerbg screamerbg merged commit ae86dc3 into ARMmbed:master Apr 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants