From 999998c58b7147fb1cdbd9a30ac001cc88142370 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Tue, 19 Mar 2024 23:59:36 +0100 Subject: [PATCH] RAFlasher: add SCI (UART) method --- raflash/RAConnect.py | 9 +++++---- raflash/RAFlasher.py | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/raflash/RAConnect.py b/raflash/RAConnect.py index d2f47bf..44bc50b 100644 --- a/raflash/RAConnect.py +++ b/raflash/RAConnect.py @@ -25,7 +25,7 @@ MAX_TRANSFER_SIZE = 2048 + 6 # include header and footer class RAConnect: - def __init__(self, vendor_id, product_id): + def __init__(self, vendor_id, product_id, port=None): self.vendor_id = vendor_id self.product_id = product_id self.max_tries = 20 @@ -34,7 +34,7 @@ class RAConnect: self.chip_layout = [] self.sel_area = 0 # default to Area 0 - self.find_device() + self.find_device(port) status_conn = self.inquire_connection() if not status_conn: self.confirm_connection() @@ -47,8 +47,9 @@ class RAConnect: return None - def find_device(self): - port = self.find_port() + def find_device(self, port): + if port is None: + port = self.find_port() try: self.dev = serial.Serial(port, 9600) except Exception as err: diff --git a/raflash/RAFlasher.py b/raflash/RAFlasher.py index 077b976..f7f4190 100644 --- a/raflash/RAFlasher.py +++ b/raflash/RAFlasher.py @@ -207,22 +207,26 @@ def main(): write_parser.add_argument("--start_address", type=hex_type, default='0x0000', help="Start address") write_parser.add_argument("--size", type=hex_type, default=None, help="Size in bytes") write_parser.add_argument("--verify", action="store_true", help="Verify after writing") + write_parser.add_argument("--port", type=str, default=None, help="Port location") write_parser.add_argument("file_name", type=str, help="File name") read_parser = subparsers.add_parser("read", help="Read data from flash") read_parser.add_argument("--start_address", type=hex_type, default='0x0000', help="Start address") read_parser.add_argument("--size", type=hex_type, default=None, help="Size in bytes") + read_parser.add_argument("--port", type=str, default=None, help="Port location") read_parser.add_argument("file_name", type=str, help="File name") erase_parser = subparsers.add_parser("erase", help="Erase sectors") erase_parser.add_argument("--start_address", default='0x0000', type=hex_type, help="Start address") erase_parser.add_argument("--size", type=hex_type, help="Size") + erase_parser.add_argument("--port", type=str, default=None, help="Port location") - subparsers.add_parser("info", help="Show flasher information") + info_parser = subparsers.add_parser("info", help="Show flasher information") + info_parser.add_argument("--port", type=str, default=None, help="Port location") args = parser.parse_args() if args.command in commands: - dev = RAConnect(VENDOR_ID, PRODUCT_ID) + dev = RAConnect(VENDOR_ID, PRODUCT_ID, args.port) area_cfg = get_area_info(dev) dev.set_chip_layout(area_cfg) commands[args.command](dev, args) -- 2.7.4