From: Robin Krens Date: Sat, 10 Feb 2024 11:59:17 +0000 (+0100) Subject: flasher.py: minor packet construct corrections X-Git-Tag: v0.0.1~55 X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=275d988eccd1d8b3408ecf8aa39687c17d9278a5;p=renesas-ra-flasher flasher.py: minor packet construct corrections --- diff --git a/flasher.py b/flasher.py index 1ffe9ae..c388815 100644 --- a/flasher.py +++ b/flasher.py @@ -9,6 +9,9 @@ BAU_CMD = 0x34 SIG_CMD = 0x3A ARE_CMD = 0x3B +OK_READ_RES = 0x15 +OK_WRITE_RES = 0x13 + LOW_PULSE = 0x00 GENERIC_CODE = 0x55 BOOT_CODE = 0xC3 @@ -20,17 +23,17 @@ TESTID = [ "0xCC", "0xCD", "0xCE", "0xCF" ] -def calc_sum(data): +def calc_sum(cmd, data): data_len = len(data) lnh = data_len + 1 & 0xFF00 lnl = data_len + 1 & 0x00FF - res = lnh + lnl + res = lnh + lnl + cmd for i in range(data_len): if isinstance(data[i], str): res += int(data[i], 16) else: res += ord(data[i]) - res = ~(res) & 0xFF # two's complement + res = ~(res - 1) & 0xFF # two's complement return (lnh, lnl, res) @@ -44,42 +47,40 @@ def format_command(cmd, data): else: byte_data = bytes([int(x, 16) for x in data]) - LNH, LNL, SUM = calc_sum(data) + LNH, LNL, SUM = calc_sum(int(cmd), data) ETX = 0x03 fmt_header = '= 1024): raise Exception(f'Data packet too large, data length is {DATA_LEN} (>1024)') - LNH, LNL, SUM = calc_sum(data) + LNH, LNL, SUM = calc_sum(int(res), data) DAT = bytes([int(x, 16) for x in data]) - RES = 0x13 + RES = res ETX = 0x03 fmt_header = '