X-Git-Url: https://robinkrens.nl/gitweb/?a=blobdiff_plain;f=flasher%2Fflasher.py;h=055bce3d921409acdb2a9d5571c89739055b7468;hb=5ef1572a84e6e6c7207ada35c0f17f2268fde26f;hp=c38881533794cdda0d1085c05ac05c2f2eb3f739;hpb=5a926ba21f47182057a38e3a62d44cec22e9d373;p=renesas-ra-flasher 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 = '