This protocol variant is designed for newer STC89 series chips with BSL
version 7.x.x. The new firmware uses framing
with 16-bit checksum.
This protocol variant is currently untested because I don't have any
hardware at hand.
Addresses #50, #40.
Catch unknown error types in the first stage (connect/initialize).
Sometimes we unfortunately see unexpected exceptions, for instance
pyserial might throw termios.error. See #39 for more details.
With the introduction of real abstract classes, it is not possible
anymore to instantiate StcBaseProtocol. Instead, extract some of the
code for autodetection into the new class StcAutoProtocol and use
that for autodetection.
Sometimes instead of DTR line some custom way (e.g SoC gpio line)
may be used to reset the device. This commit implements
automated power-cycling using a a custom shell command that can
be specified via -r option
Signed-off-by: Andrew Andrianov <andrew@ncrmnt.org>
The STC15W4 series have an additional USB BSL mode which kind of wraps
the serial protocol. It just uses basic USB control transfers. This
adds support for this mode, based on the existing STC15 code. pyusb is
required as an additional dependency. The new protocol mode is called
"usb15". There are some shortcomings, for instance timing of erase
and programming operations is problematic and right now only delays
are used. Also, only a single USB-ISP device is supported and the
first one found is always used.
Flash programming and setting options has been mildly tested on an
STC15W4K56S4 MCU.
The model of the target MCU and its protocol is detected using model ID provided in the first packet (status packet) from the MCU.
Tested working models include,
IAP15F2K61S2 (BSL version: 7.1.4S, protocol: stc15)
STC15F104W (BSL version: 7.1.4Q, protocol: stc15)
TC11F02E (BSL version: 6.5K, protocol: stc12)
STC10F04XE (BSL version: 6.5J, protocol: stc12)
STC12C5A16S2 (BSL version: 6.2I, protocol: stc12)
STC12C5608AD (BSL version: 6.0G, protocol: stc12)
STC12C2052 (BSL version: 5.8D, protocol: stc12a)
STC90C52RC (BSL version: 4.3C, protocol: stc89)
STC89C52RC (BSL version: 4.3C, protocol: stc89)
STC89C54RD+ (BSL version: 4.3C, protocol: stc89)
STC15F104E (BSL version: 6.7Q, protocol: stc15a)
STC15F104E uses a different status packet protocol than other MCUs; it waits for an ACK packet before sending out the status packet. Another problem is that STC15F104E shares the same model magic with STC15F104W. Fortunately, these two models can be differentiated by their BSL version numbers.
This is inspired by Arduino. Directly before connect, DTR is asserted
for 0.5 seconds and then deasserted again. With a small external
circuit, the MCU can be power-cycled with this control signal.
In case the MCU draws very little power, it may even be possible to
supply power directly from the DTR pin.
Add Intel HEX support with the help of the IHex library. IHex needed
some modifications to make it work with Python 3.
Intel HEX files are autodetected, based on file extension (.hex,
.ihx or .ihex).
Split up single script into a package with multiple modules.
Also add a setuptools control file. With this, stcgal can be
installed like any other program. It's still possible to launch
from the sources directly. stcgal.py has been converted into a
simple launcher.
v2: fix imports