-
Notifications
You must be signed in to change notification settings - Fork 10
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
Atmel support and fixes #18
base: master
Are you sure you want to change the base?
Changes from 7 commits
bb50d5c
3e0105d
c63fcf6
1213330
0de66d5
617e752
7e63157
3f6c72f
f3d5298
75a41d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include README.md LICENSE | ||
recursive-include bin * |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
mbed SDK | ||
Copyright (c) 2011-2015 ARM Limited | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
"""! @package binary_files | ||
binary files for mbed-flasher | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
mbed SDK | ||
Copyright (c) 2011-2015 ARM Limited | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
"""! @package binary_files | ||
binary files for mbed-flasher | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import subprocess | ||
import logging | ||
import tempfile | ||
import platform | ||
|
||
|
||
class FlasherAtmelAt(object): | ||
|
@@ -52,18 +53,18 @@ def get_supported_targets(): | |
|
||
@staticmethod | ||
def set_atprogram_exe(exe): | ||
FlasherAtmelAt.logger = logging.getLogger('mbed-flasher') | ||
if exe is None: | ||
path = '' | ||
if os.path.exists('C:\\Program File\\Atmel\\'): | ||
if os.path.exists('C:\\Program Files\\Atmel\\'): | ||
path = 'C:\\Program Files\\Atmel\\' | ||
elif os.path.exists('C:\\Program File (x86)\\Atmel\\'): | ||
elif os.path.exists('C:\\Program Files (x86)\\Atmel\\'): | ||
path = 'C:\\Program Files (x86)\\Atmel\\' | ||
if path: | ||
for dirpath, subdirs, files in os.walk(path): | ||
for x in files: | ||
if x.find("atprogram.exe") != -1: | ||
FlasherAtmelAt.exe = os.path.join(dirpath, x) | ||
print FlasherAtmelAt.exe | ||
if not FlasherAtmelAt.exe: | ||
for ospath in os.environ['PATH'].split(os.pathsep): | ||
if ospath.find('Atmel') != -1: | ||
|
@@ -73,22 +74,50 @@ def set_atprogram_exe(exe): | |
FlasherAtmelAt.exe = exe | ||
|
||
FlasherAtmelAt.logger.debug("atprogram location: %s", FlasherAtmelAt.exe) | ||
|
||
|
||
@staticmethod | ||
def set_edbg_exe(exe): | ||
FlasherAtmelAt.logger = logging.getLogger('mbed-flasher') | ||
if exe is None: | ||
if platform.system() == 'Windows': | ||
FlasherAtmelAt.exe = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', '..', 'bin', 'edbg', 'edbg.exe')) | ||
elif platform.system() == 'Linux': | ||
if os.uname()[4].startswith("arm"): | ||
FlasherAtmelAt.exe = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', '..', 'bin', 'edbg', 'edbg_raspbian')) | ||
else: | ||
FlasherAtmelAt.exe = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', '..', 'bin', 'edbg', 'edbg_ubuntu')) | ||
elif platform.system() == 'Darwin': | ||
print "Support for OS X is missing" | ||
FlasherAtmelAt.exe = None | ||
|
||
@staticmethod | ||
def get_available_devices(): | ||
"""list available devices | ||
""" | ||
FlasherAtmelAt.logger = logging.getLogger('mbed-flasher') | ||
if platform.system() == 'Windows': | ||
FlasherAtmelAt.set_atprogram_exe(FlasherAtmelAt.exe) | ||
if not FlasherAtmelAt.exe: | ||
FlasherAtmelAt.set_edbg_exe(FlasherAtmelAt.exe) | ||
if str(FlasherAtmelAt.exe).find('atprogram.exe') != -1: | ||
cmd = [FlasherAtmelAt.exe, "list"] | ||
lookup = 'edbg\W+(.*)' | ||
else: | ||
cmd = [FlasherAtmelAt.exe, "--list"] | ||
lookup = '(\S.*) - Atmel.*' | ||
else: | ||
FlasherAtmelAt.set_edbg_exe(FlasherAtmelAt.exe) | ||
cmd = [FlasherAtmelAt.exe, "--list"] | ||
lookup = '(\S.*) - Atmel.*' | ||
if not FlasherAtmelAt.exe: | ||
return [] | ||
FlasherAtmelAt.set_atprogram_exe(FlasherAtmelAt.exe) | ||
cmd = FlasherAtmelAt.exe + " list" | ||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
stdout, stderr = proc.communicate() | ||
connected_devices = [] | ||
if proc.returncode == 0: | ||
lines = stdout.splitlines() | ||
for line in lines: | ||
ret = FlasherAtmelAt.find(line, 'edbg\W+(.*)') | ||
ret = FlasherAtmelAt.find_match(line, lookup) | ||
if ret: | ||
connected_devices.append({ | ||
"platform_name": "SAM4E", | ||
|
@@ -101,38 +130,28 @@ def get_available_devices(): | |
return connected_devices | ||
|
||
# actual flash procedure | ||
def flash(self, source, target): | ||
def flash(self, source, target, pyocd=None): | ||
"""flash device | ||
:param sn: device serial number to be flashed | ||
:param binary: binary file to be flash | ||
:return: 0 when flashing success | ||
""" | ||
with tempfile.TemporaryFile() as temp: | ||
temp.write(source) | ||
temp.close() | ||
temp.name | ||
# actual flash procedure | ||
|
||
cmd = self.exe+" -t edbg -i SWD -d atsam4e16e -s "+target['target_id']+" -v -cl 10mhz program --verify -f "+temp.name | ||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
stdout, stderr = proc.communicate() | ||
FlasherAtmelAt.logger.debug(stdout) | ||
FlasherAtmelAt.logger.debug(stderr) | ||
return proc.returncode | ||
|
||
@staticmethod | ||
def lookupExe(alternatives): | ||
"""lookup existing exe | ||
:param alternatives: exes | ||
:return: founded exe | ||
""" | ||
for exe in alternatives: | ||
if os.path.exists(exe): | ||
return exe | ||
return None | ||
if str(self.exe).find('atprogram.exe') != -1: | ||
cmd = [self.exe, "-t", "edbg", "-i", "SWD", "-d", "atsam4e16e", "-s", target['target_id'], "-v", "-cl", "10mhz", "program", "--verify", "-f", source] | ||
else: | ||
if platform.system() == 'Windows': | ||
cmd = [self.exe, "-bpv", "-t", "atmel_cm4", "-s", target['target_id'],"-f", source] | ||
else: | ||
cmd = ['sudo', self.exe, "-bpv", "-t", "atmel_cm4", "-s", target['target_id'],"-f", source] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably shouldn't execute using sudo inside the flasher There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least it did not work on my setup without sudo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree to @kuggenhoffen There might not even be a I believe this is once again a case for some udev rule writing rehearsal |
||
FlasherAtmelAt.logger.debug(cmd) | ||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
stdout, stderr = proc.communicate() | ||
FlasherAtmelAt.logger.debug(stdout) | ||
FlasherAtmelAt.logger.debug(stderr) | ||
return proc.returncode | ||
|
||
@staticmethod | ||
def find(line, lookup): | ||
def find_match(line, lookup): | ||
"""find with regexp | ||
:param line: | ||
:param lookup: | ||
|
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 there is SAM4E hard coded here?
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.
platform_name has to be given when flashing and for SAM4E target_id length is max 20. if we do not have the separation of K64F and SAM4E prefix support stops working. i.e. giving a prefix 02 that would flash all devices that start with 02 would go to either ATMEL flash or Mbed flash.