mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 01:40:14 +01:00
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
This commit is contained in:
@@ -12,55 +12,58 @@ python3 run-tests --target wipy --device 192.168.1.1 ../cc3200/tools/smoke.py
|
||||
pin_map = [23, 24, 11, 12, 13, 14, 15, 16, 17, 22, 28, 10, 9, 8, 7, 6, 30, 31, 3, 0, 4, 5]
|
||||
test_bytes = os.urandom(1024)
|
||||
|
||||
def test_pin_read (pull):
|
||||
|
||||
def test_pin_read(pull):
|
||||
# enable the pull resistor on all pins, then read the value
|
||||
for p in pin_map:
|
||||
pin = Pin('GP' + str(p), mode=Pin.IN, pull=pull)
|
||||
pin = Pin("GP" + str(p), mode=Pin.IN, pull=pull)
|
||||
# read the pin value
|
||||
print(pin())
|
||||
|
||||
def test_pin_shorts (pull):
|
||||
|
||||
def test_pin_shorts(pull):
|
||||
if pull == Pin.PULL_UP:
|
||||
pull_inverted = Pin.PULL_DOWN
|
||||
else:
|
||||
pull_inverted = Pin.PULL_UP
|
||||
# enable all pulls of the specified type
|
||||
for p in pin_map:
|
||||
pin = Pin('GP' + str(p), mode=Pin.IN, pull=pull_inverted)
|
||||
pin = Pin("GP" + str(p), mode=Pin.IN, pull=pull_inverted)
|
||||
# then change the pull one pin at a time and read its value
|
||||
i = 0
|
||||
while i < len(pin_map):
|
||||
pin = Pin('GP' + str(pin_map[i]), mode=Pin.IN, pull=pull)
|
||||
Pin('GP' + str(pin_map[i - 1]), mode=Pin.IN, pull=pull_inverted)
|
||||
pin = Pin("GP" + str(pin_map[i]), mode=Pin.IN, pull=pull)
|
||||
Pin("GP" + str(pin_map[i - 1]), mode=Pin.IN, pull=pull_inverted)
|
||||
i += 1
|
||||
# read the pin value
|
||||
print(pin())
|
||||
|
||||
|
||||
test_pin_read(Pin.PULL_UP)
|
||||
test_pin_read(Pin.PULL_DOWN)
|
||||
test_pin_shorts(Pin.PULL_UP)
|
||||
test_pin_shorts(Pin.PULL_DOWN)
|
||||
|
||||
# create a test directory
|
||||
os.mkdir('/flash/test')
|
||||
os.chdir('/flash/test')
|
||||
os.mkdir("/flash/test")
|
||||
os.chdir("/flash/test")
|
||||
print(os.getcwd())
|
||||
# create a new file
|
||||
f = open('test.txt', 'w')
|
||||
f = open("test.txt", "w")
|
||||
n_w = f.write(test_bytes)
|
||||
print(n_w == len(test_bytes))
|
||||
f.close()
|
||||
f = open('test.txt', 'r')
|
||||
r = bytes(f.read(), 'ascii')
|
||||
f = open("test.txt", "r")
|
||||
r = bytes(f.read(), "ascii")
|
||||
# check that we can write and read it correctly
|
||||
print(r == test_bytes)
|
||||
f.close()
|
||||
os.remove('test.txt')
|
||||
os.chdir('..')
|
||||
os.rmdir('test')
|
||||
os.remove("test.txt")
|
||||
os.chdir("..")
|
||||
os.rmdir("test")
|
||||
|
||||
ls = os.listdir()
|
||||
print('test' not in ls)
|
||||
print("test" not in ls)
|
||||
print(ls)
|
||||
|
||||
# test the real time clock
|
||||
@@ -72,5 +75,4 @@ time1 = rtc.now()
|
||||
time.sleep_ms(1000)
|
||||
time2 = rtc.now()
|
||||
print(time2[5] - time1[5] == 1)
|
||||
print(time2[6] - time1[6] < 5000) # microseconds
|
||||
|
||||
print(time2[6] - time1[6] < 5000) # microseconds
|
||||
|
||||
@@ -19,7 +19,7 @@ import subprocess
|
||||
|
||||
|
||||
def print_exception(e):
|
||||
print ('Exception: {}, on line {}'.format(e, sys.exc_info()[-1].tb_lineno))
|
||||
print("Exception: {}, on line {}".format(e, sys.exc_info()[-1].tb_lineno))
|
||||
|
||||
|
||||
def execute(command):
|
||||
@@ -29,7 +29,7 @@ def execute(command):
|
||||
# Poll process for new output until finished
|
||||
while True:
|
||||
nextline = process.stdout.readline()
|
||||
if nextline == '' and process.poll() != None:
|
||||
if nextline == "" and process.poll() != None:
|
||||
break
|
||||
sys.stdout.write(nextline)
|
||||
sys.stdout.flush()
|
||||
@@ -43,25 +43,58 @@ def execute(command):
|
||||
else:
|
||||
raise ProcessException(command, exitCode, output)
|
||||
|
||||
|
||||
def main():
|
||||
cmd_parser = argparse.ArgumentParser(description='Flash the WiPy and optionally run a small test on it.')
|
||||
cmd_parser.add_argument('-u', '--uniflash', default=None, help='the path to the uniflash cli executable')
|
||||
cmd_parser.add_argument('-c', '--config', default=None, help='the path to the uniflash config file')
|
||||
cmd_parser.add_argument('-p', '--port', default=8, help='the com serial port')
|
||||
cmd_parser.add_argument('-s', '--servicepack', default=None, help='the path to the servicepack file')
|
||||
cmd_parser = argparse.ArgumentParser(
|
||||
description="Flash the WiPy and optionally run a small test on it."
|
||||
)
|
||||
cmd_parser.add_argument(
|
||||
"-u", "--uniflash", default=None, help="the path to the uniflash cli executable"
|
||||
)
|
||||
cmd_parser.add_argument(
|
||||
"-c", "--config", default=None, help="the path to the uniflash config file"
|
||||
)
|
||||
cmd_parser.add_argument("-p", "--port", default=8, help="the com serial port")
|
||||
cmd_parser.add_argument(
|
||||
"-s", "--servicepack", default=None, help="the path to the servicepack file"
|
||||
)
|
||||
args = cmd_parser.parse_args()
|
||||
|
||||
output = ""
|
||||
com_port = 'com=' + str(args.port)
|
||||
servicepack_path = 'spPath=' + args.servicepack
|
||||
com_port = "com=" + str(args.port)
|
||||
servicepack_path = "spPath=" + args.servicepack
|
||||
|
||||
try:
|
||||
if args.uniflash == None or args.config == None:
|
||||
raise ValueError('uniflash path and config path are mandatory')
|
||||
raise ValueError("uniflash path and config path are mandatory")
|
||||
if args.servicepack == None:
|
||||
output += execute([args.uniflash, '-config', args.config, '-setOptions', com_port, '-operations', 'format', 'program'])
|
||||
output += execute(
|
||||
[
|
||||
args.uniflash,
|
||||
"-config",
|
||||
args.config,
|
||||
"-setOptions",
|
||||
com_port,
|
||||
"-operations",
|
||||
"format",
|
||||
"program",
|
||||
]
|
||||
)
|
||||
else:
|
||||
output += execute([args.uniflash, '-config', args.config, '-setOptions', com_port, servicepack_path, '-operations', 'format', 'servicePackUpdate', 'program'])
|
||||
output += execute(
|
||||
[
|
||||
args.uniflash,
|
||||
"-config",
|
||||
args.config,
|
||||
"-setOptions",
|
||||
com_port,
|
||||
servicepack_path,
|
||||
"-operations",
|
||||
"format",
|
||||
"servicePackUpdate",
|
||||
"program",
|
||||
]
|
||||
)
|
||||
except Exception as e:
|
||||
print_exception(e)
|
||||
output = ""
|
||||
@@ -77,5 +110,6 @@ def main():
|
||||
print("======================================")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -23,12 +23,12 @@ from telnetlib import Telnet
|
||||
|
||||
|
||||
def print_exception(e):
|
||||
print ('Exception: {}, on line {}'.format(e, sys.exc_info()[-1].tb_lineno))
|
||||
print("Exception: {}, on line {}".format(e, sys.exc_info()[-1].tb_lineno))
|
||||
|
||||
|
||||
def ftp_directory_exists(ftpobj, directory_name):
|
||||
filelist = []
|
||||
ftpobj.retrlines('LIST',filelist.append)
|
||||
ftpobj.retrlines("LIST", filelist.append)
|
||||
for f in filelist:
|
||||
if f.split()[-1] == directory_name:
|
||||
return True
|
||||
@@ -37,34 +37,34 @@ def ftp_directory_exists(ftpobj, directory_name):
|
||||
|
||||
def transfer_file(args):
|
||||
with FTP(args.ip, timeout=20) as ftp:
|
||||
print ('FTP connection established')
|
||||
print("FTP connection established")
|
||||
|
||||
if '230' in ftp.login(args.user, args.password):
|
||||
print ('Login successful')
|
||||
if "230" in ftp.login(args.user, args.password):
|
||||
print("Login successful")
|
||||
|
||||
if '250' in ftp.cwd('/flash'):
|
||||
if not ftp_directory_exists(ftp, 'sys'):
|
||||
print ('/flash/sys directory does not exist')
|
||||
if not '550' in ftp.mkd('sys'):
|
||||
print ('/flash/sys directory created')
|
||||
if "250" in ftp.cwd("/flash"):
|
||||
if not ftp_directory_exists(ftp, "sys"):
|
||||
print("/flash/sys directory does not exist")
|
||||
if not "550" in ftp.mkd("sys"):
|
||||
print("/flash/sys directory created")
|
||||
else:
|
||||
print ('Error: cannot create /flash/sys directory')
|
||||
print("Error: cannot create /flash/sys directory")
|
||||
return False
|
||||
if '250' in ftp.cwd('sys'):
|
||||
print ("Entered '/flash/sys' directory")
|
||||
if "250" in ftp.cwd("sys"):
|
||||
print("Entered '/flash/sys' directory")
|
||||
with open(args.file, "rb") as fwfile:
|
||||
print ('Firmware image found, initiating transfer...')
|
||||
if '226' in ftp.storbinary("STOR " + 'mcuimg.bin', fwfile, 512):
|
||||
print ('File transfer complete')
|
||||
print("Firmware image found, initiating transfer...")
|
||||
if "226" in ftp.storbinary("STOR " + "mcuimg.bin", fwfile, 512):
|
||||
print("File transfer complete")
|
||||
return True
|
||||
else:
|
||||
print ('Error: file transfer failed')
|
||||
print("Error: file transfer failed")
|
||||
else:
|
||||
print ('Error: cannot enter /flash/sys directory')
|
||||
print("Error: cannot enter /flash/sys directory")
|
||||
else:
|
||||
print ('Error: cannot enter /flash directory')
|
||||
print("Error: cannot enter /flash directory")
|
||||
else:
|
||||
print ('Error: ftp login failed')
|
||||
print("Error: ftp login failed")
|
||||
|
||||
return False
|
||||
|
||||
@@ -76,20 +76,24 @@ def reset_board(args):
|
||||
tn = Telnet(args.ip, timeout=5)
|
||||
print("Connected via Telnet, trying to login now")
|
||||
|
||||
if b'Login as:' in tn.read_until(b"Login as:", timeout=5):
|
||||
tn.write(bytes(args.user, 'ascii') + b"\r\n")
|
||||
if b"Login as:" in tn.read_until(b"Login as:", timeout=5):
|
||||
tn.write(bytes(args.user, "ascii") + b"\r\n")
|
||||
|
||||
if b'Password:' in tn.read_until(b"Password:", timeout=5):
|
||||
if b"Password:" in tn.read_until(b"Password:", timeout=5):
|
||||
# needed because of internal implementation details of the WiPy's telnet server
|
||||
time.sleep(0.2)
|
||||
tn.write(bytes(args.password, 'ascii') + b"\r\n")
|
||||
tn.write(bytes(args.password, "ascii") + b"\r\n")
|
||||
|
||||
if b'Type "help()" for more information.' in tn.read_until(b'Type "help()" for more information.', timeout=5):
|
||||
if b'Type "help()" for more information.' in tn.read_until(
|
||||
b'Type "help()" for more information.', timeout=5
|
||||
):
|
||||
print("Telnet login succeeded")
|
||||
tn.write(b'\r\x03\x03') # ctrl-C twice: interrupt any running program
|
||||
tn.write(b"\r\x03\x03") # ctrl-C twice: interrupt any running program
|
||||
time.sleep(1)
|
||||
tn.write(b'\r\x02') # ctrl-B: enter friendly REPL
|
||||
if b'Type "help()" for more information.' in tn.read_until(b'Type "help()" for more information.', timeout=5):
|
||||
tn.write(b"\r\x02") # ctrl-B: enter friendly REPL
|
||||
if b'Type "help()" for more information.' in tn.read_until(
|
||||
b'Type "help()" for more information.', timeout=5
|
||||
):
|
||||
tn.write(b"import machine\r\n")
|
||||
tn.write(b"machine.reset()\r\n")
|
||||
time.sleep(2)
|
||||
@@ -112,9 +116,9 @@ def reset_board(args):
|
||||
|
||||
def verify_update(args):
|
||||
success = False
|
||||
firmware_tag = ''
|
||||
firmware_tag = ""
|
||||
|
||||
def find_tag (tag):
|
||||
def find_tag(tag):
|
||||
if tag in firmware_tag:
|
||||
print("Verification passed")
|
||||
return True
|
||||
@@ -135,21 +139,26 @@ def verify_update(args):
|
||||
print("Timeout while connecting via telnet, retrying...")
|
||||
retries += 1
|
||||
else:
|
||||
print('Error: Telnet connection timed out!')
|
||||
print("Error: Telnet connection timed out!")
|
||||
return False
|
||||
|
||||
try:
|
||||
firmware_tag = tn.read_until (b'with CC3200')
|
||||
tag_file_path = args.file.rstrip('mcuimg.bin') + 'genhdr/mpversion.h'
|
||||
|
||||
firmware_tag = tn.read_until(b"with CC3200")
|
||||
tag_file_path = args.file.rstrip("mcuimg.bin") + "genhdr/mpversion.h"
|
||||
|
||||
if args.tag is not None:
|
||||
success = find_tag(bytes(args.tag, 'ascii'))
|
||||
success = find_tag(bytes(args.tag, "ascii"))
|
||||
else:
|
||||
with open(tag_file_path) as tag_file:
|
||||
for line in tag_file:
|
||||
bline = bytes(line, 'ascii')
|
||||
if b'MICROPY_GIT_HASH' in bline:
|
||||
bline = bline.lstrip(b'#define MICROPY_GIT_HASH ').replace(b'"', b'').replace(b'\r', b'').replace(b'\n', b'')
|
||||
bline = bytes(line, "ascii")
|
||||
if b"MICROPY_GIT_HASH" in bline:
|
||||
bline = (
|
||||
bline.lstrip(b"#define MICROPY_GIT_HASH ")
|
||||
.replace(b'"', b"")
|
||||
.replace(b"\r", b"")
|
||||
.replace(b"\n", b"")
|
||||
)
|
||||
success = find_tag(bline)
|
||||
break
|
||||
|
||||
@@ -164,24 +173,28 @@ def verify_update(args):
|
||||
|
||||
|
||||
def main():
|
||||
cmd_parser = argparse.ArgumentParser(description='Update the WiPy firmware with the specified image file')
|
||||
cmd_parser.add_argument('-f', '--file', default=None, help='the path of the firmware file')
|
||||
cmd_parser.add_argument('-u', '--user', default='micro', help='the username')
|
||||
cmd_parser.add_argument('-p', '--password', default='python', help='the login password')
|
||||
cmd_parser.add_argument('--ip', default='192.168.1.1', help='the ip address of the WiPy')
|
||||
cmd_parser.add_argument('--verify', action='store_true', help='verify that the update succeeded')
|
||||
cmd_parser.add_argument('-t', '--tag', default=None, help='git tag of the firmware image')
|
||||
cmd_parser = argparse.ArgumentParser(
|
||||
description="Update the WiPy firmware with the specified image file"
|
||||
)
|
||||
cmd_parser.add_argument("-f", "--file", default=None, help="the path of the firmware file")
|
||||
cmd_parser.add_argument("-u", "--user", default="micro", help="the username")
|
||||
cmd_parser.add_argument("-p", "--password", default="python", help="the login password")
|
||||
cmd_parser.add_argument("--ip", default="192.168.1.1", help="the ip address of the WiPy")
|
||||
cmd_parser.add_argument(
|
||||
"--verify", action="store_true", help="verify that the update succeeded"
|
||||
)
|
||||
cmd_parser.add_argument("-t", "--tag", default=None, help="git tag of the firmware image")
|
||||
args = cmd_parser.parse_args()
|
||||
|
||||
result = 1
|
||||
|
||||
try:
|
||||
if args.file is None:
|
||||
raise ValueError('the image file path must be specified')
|
||||
raise ValueError("the image file path must be specified")
|
||||
if transfer_file(args):
|
||||
if reset_board(args):
|
||||
if args.verify:
|
||||
print ('Waiting for the WiFi connection to come up again...')
|
||||
print("Waiting for the WiFi connection to come up again...")
|
||||
# this time is to allow the system's wireless network card to
|
||||
# connect to the WiPy again.
|
||||
time.sleep(5)
|
||||
|
||||
Reference in New Issue
Block a user