From: Robin Krens Date: Sat, 10 Feb 2024 13:38:10 +0000 (+0100) Subject: flasher.py: initial unpacking X-Git-Tag: v0.0.1~53 X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=e3f9ceea84c52e5dbbccde147151efa8e10fa054;p=renesas-ra-flasher flasher.py: initial unpacking --- diff --git a/flasher/flasher.py b/flasher/flasher.py index c388815..055bce3 100644 --- a/flasher/flasher.py +++ b/flasher/flasher.py @@ -1,5 +1,23 @@ +# Copyright (C) Robin Krens - 2024 +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + import struct +# Commands send to boot firmware INQ_CMD = 0x00 ERA_CMD = 0x12 WRI_CMD = 0x13 @@ -9,9 +27,27 @@ BAU_CMD = 0x34 SIG_CMD = 0x3A ARE_CMD = 0x3B -OK_READ_RES = 0x15 -OK_WRITE_RES = 0x13 - +# These are combined with send command, for example +# STATUS_OK | ERA_CMD == 0x12 +# STATUS_ERR | ERA_CMD = 0x92 +STATUS_OK = 0x00 +STATUS_ERR = 0x80 + +# Error codes +ERR_UNSU = 0xC +ERR_PCKT = 0xC1 +ERR_CHKS = 0xC2 +ERR_FLOW = 0xC3 +ERR_ADDR = 0xD0 +ERR_BAUD = 0xD4 +ERR_PROT = 0xDA +ERR_ID = 0xDB +ERR_SERI = 0xDC +ERR_ERA = 0xE1 +ERR_WRI = 0xE2 +ERR_SEQ = 0xE7 + +# used for init sequence LOW_PULSE = 0x00 GENERIC_CODE = 0x55 BOOT_CODE = 0xC3 @@ -71,10 +107,32 @@ def format_data(res, data): pack = struct.pack(fmt, SOD, LNH, LNL, RES, DAT, SUM, ETX) print(fmt, pack, len(pack)) -cmd = format_command(INQ_CMD, "") +# packet received from mcu +def unpack_header(data): + header = data[0:4] + fmt_header = '