Skip to content

Commit

Permalink
RAFlasher: add SCI (UART) method
Browse files Browse the repository at this point in the history
  • Loading branch information
robinkrens committed Mar 19, 2024
1 parent 9691f18 commit 999998c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions raflash/RAConnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


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
Expand All @@ -34,7 +34,7 @@ def __init__(self, vendor_id, product_id):
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()
Expand All @@ -47,8 +47,9 @@ def find_port(self):

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:
Expand Down
8 changes: 6 additions & 2 deletions raflash/RAFlasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 999998c

Please sign in to comment.