Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
b070346e70 |
20
README.md
20
README.md
@ -25,14 +25,14 @@ stcgal should fully support STC 89/90/10/11/12/15 series MCUs.
|
|||||||
|
|
||||||
So far, stcgal was tested with the following MCU models:
|
So far, stcgal was tested with the following MCU models:
|
||||||
|
|
||||||
* STC89C52RC (BSL version: 4.3C/6.6C)
|
* STC89C52RC (BSL version: 4.3C)
|
||||||
* STC90C52RC (BSL version: 4.3C)
|
* STC90C52RC (BSL version: 4.3C)
|
||||||
* STC89C54RD+ (BSL version: 4.3C)
|
* STC89C54RD+ (BSL version: 4.3C)
|
||||||
* STC12C2052 (BSL version: 5.8D)
|
* STC12C2052 (BSL version: 5.8D)
|
||||||
* STC12C2052AD (BSL version: 5.8D)
|
* STC12C2052AD (BSL version: 5.8D)
|
||||||
* STC12C5608AD (BSL version: 6.0G)
|
* STC12C5608AD (BSL version: 6.0G)
|
||||||
* STC12C5A16S2 (BSL version: 6.2I)
|
* STC12C5A16S2 (BSL version: 6.2I)
|
||||||
* STC12C5A60S2 (BSL version: 6.2I/7.1I)
|
* STC12C5A60S2 (BSL version: 6.2I)
|
||||||
* STC11F02E (BSL version: 6.5K)
|
* STC11F02E (BSL version: 6.5K)
|
||||||
* STC10F04XE (BSL version: 6.5J)
|
* STC10F04XE (BSL version: 6.5J)
|
||||||
* STC11F08XE (BSL version: 6.5M)
|
* STC11F08XE (BSL version: 6.5M)
|
||||||
@ -111,18 +111,18 @@ Most importantly, ```-p``` sets the serial port to be used for programming.
|
|||||||
### Protocols
|
### Protocols
|
||||||
|
|
||||||
STC MCUs use a variety of related but incompatible protocols for the
|
STC MCUs use a variety of related but incompatible protocols for the
|
||||||
BSL. The protocol can be specified with the ```-P``` flag. By default
|
BSL. The protocol can be specified with the ```-P``` flag. Optionally,
|
||||||
UART protocol autodetection is used. The mapping between protocols
|
experimental protocol autodetection can be used. The mapping between
|
||||||
and MCU series is as follows:
|
protocols and MCU series is as follows:
|
||||||
|
|
||||||
* ```stc89``` STC89/90 series
|
* ```stc89``` STC 89/90 series
|
||||||
* ```stc12a``` STC12x052 series and possibly others
|
* ```stc12a``` STC12Cx052AD and possibly others
|
||||||
* ```stc12b``` STC12x52 series, STC12x56 series and possibly others
|
* ```stc12b``` STC12x52xx series, STC12x56xx series and possibly others
|
||||||
* ```stc12``` Most STC10/11/12 series
|
* ```stc12``` Most STC10/11/12 series (default)
|
||||||
* ```stc15a``` STC15x104E and STC15x204E(A) series
|
* ```stc15a``` STC15x104E and STC15x204E(A) series
|
||||||
* ```stc15``` Most STC15 series
|
* ```stc15``` Most STC15 series
|
||||||
* ```usb15``` USB support on STC15W4 series
|
* ```usb15``` USB support on STC15W4 series
|
||||||
* ```auto``` Automatic detection of UART based protocols (default)
|
* ```auto``` Automatic detection of UART based protocols
|
||||||
|
|
||||||
The text files in the doc/ subdirectory provide an overview over
|
The text files in the doc/ subdirectory provide an overview over
|
||||||
the reverse engineered protocols used by the BSLs. For more details,
|
the reverse engineered protocols used by the BSLs. For more details,
|
||||||
|
13
debian/changelog
vendored
13
debian/changelog
vendored
@ -1,16 +1,3 @@
|
|||||||
stcgal (1.3) unstable; urgency=low
|
|
||||||
|
|
||||||
* Update to 1.3
|
|
||||||
|
|
||||||
-- Grigori Goronzy <greg@chown.ath.cx> Sat, 10 Jun 2017 10:01:07 +0200
|
|
||||||
|
|
||||||
stcgal (1.2) unstable; urgency=low
|
|
||||||
|
|
||||||
* Update to 1.2
|
|
||||||
* Add optional python3-usb dependency
|
|
||||||
|
|
||||||
-- Grigori Goronzy <greg@chown.ath.cx> Fri, 20 May 2016 03:21:25 +0200
|
|
||||||
|
|
||||||
stcgal (1.0git) unstable; urgency=low
|
stcgal (1.0git) unstable; urgency=low
|
||||||
|
|
||||||
* Initial Debianized Release
|
* Initial Debianized Release
|
||||||
|
18
debian/control
vendored
18
debian/control
vendored
@ -10,17 +10,17 @@ X-Python3-Version: >= 3.2
|
|||||||
Package: stcgal
|
Package: stcgal
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${misc:Depends}, python3, python3-serial
|
Depends: ${misc:Depends}, python3, python3-serial
|
||||||
Recommends: python3-usb (>= 1.0.0~b2)
|
|
||||||
Description: STC MCU ISP flash tool
|
Description: STC MCU ISP flash tool
|
||||||
stcgal is a command line flash programming tool for STC MCU Ltd.
|
stcgal is a command line flash programming tool for STC MCU Ltd. 8051
|
||||||
8051 compatible microcontrollers. The name was inspired by avrdude.
|
compatible microcontrollers. The name was inspired by avrdude.
|
||||||
.
|
.
|
||||||
STC microcontrollers have an UART/USB based boot strap loader (BSL). It
|
STC microcontrollers have a UART based boot strap loader (BSL). It
|
||||||
utilizes a packet-based protocol to flash the code memory and IAP
|
utilizes a packet-based protocol to flash the code memory and
|
||||||
memory over a serial link. This is referred to as in-system programming
|
IAP memory over a serial link. This is referred to as in-system
|
||||||
(ISP). The BSL is also used to configure various (fuse-like) device
|
programming (ISP). The BSL is also used to configure various
|
||||||
options. Unfortunately, this protocol is not publicly documented and
|
(fuse-like) device options. Unfortunately, this protocol is not
|
||||||
STC only provide a (crude) Windows GUI application for programming.
|
publicly documented and STC only provide a (crude) Windows GUI
|
||||||
|
application for programming.
|
||||||
.
|
.
|
||||||
stcgal is a full-featured Open Source replacement for STC's Windows
|
stcgal is a full-featured Open Source replacement for STC's Windows
|
||||||
software; it supports a wide range of MCUs, it is very portable and
|
software; it supports a wide range of MCUs, it is very portable and
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
STC15 series USB ISP protocol
|
|
||||||
=============================
|
|
||||||
|
|
||||||
General principle
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
- host does OUT and IN control transfers for write and read
|
|
||||||
- IN transfer with wLength = 132, wValue = 0, wIndex = 0, bRequest = 0 are used for all reads
|
|
||||||
- OUT transfers with with specific bRequest, wValue, wIndex are used for writes
|
|
||||||
|
|
||||||
|
|
||||||
Packet coding
|
|
||||||
-------------
|
|
||||||
|
|
||||||
- packets from MCU
|
|
||||||
always start with 0x46 0xb9, similar to serial protocols
|
|
||||||
third byte is packet length, followed by data bytes
|
|
||||||
checksum at the end: 8 bit modular sum
|
|
||||||
|
|
||||||
- packets from host
|
|
||||||
no header bytes
|
|
||||||
bRequest sets packet type
|
|
||||||
wValue, wIndex interpretation according to packet type
|
|
||||||
8 bit modular checksum for every 7 bytes, interleaved
|
|
||||||
|
|
||||||
- packet types derived from the serial protocol
|
|
||||||
|
|
||||||
Specific packet information
|
|
||||||
---------------------------
|
|
||||||
|
|
||||||
- flash data
|
|
||||||
wIndex specifies write address
|
|
||||||
wValue is 0xa55a
|
|
||||||
bRequest is 0x22 for first packet, 0x02 for the following ones
|
|
||||||
unusually encoded: a total of 128 bytes per packet,
|
|
||||||
with every 7 byte checksummed in some way,
|
|
||||||
for a total of 18x7 byte segments and a final 2 byte segment
|
|
||||||
checksum: 8 bit modular sum
|
|
||||||
|
|
||||||
- option packet
|
|
||||||
generally same as with serial protocol, some header stuff omitted
|
|
||||||
wIndex is 0
|
|
||||||
wValue is 0xa55a
|
|
||||||
bRequest is 4
|
|
||||||
seems to use the same checksumming scheme as flash writes
|
|
||||||
|
|
@ -1 +1 @@
|
|||||||
__version__ = "1.3"
|
__version__ = "1.0"
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (c) 2013-2015 Grigori Goronzy <greg@chown.ath.cx>
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
|
||||||
# in the Software without restriction, including without limitation the rights
|
|
||||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
# copies of the Software, and to permit persons to whom the Software is
|
|
||||||
# furnished to do so, subject to the following conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be included in all
|
|
||||||
# copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
# SOFTWARE.
|
|
||||||
#
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import stcgal.frontend
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(stcgal.frontend.cli())
|
|
@ -192,11 +192,11 @@ class StcGal:
|
|||||||
def cli():
|
def cli():
|
||||||
# check arguments
|
# check arguments
|
||||||
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
|
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
description="stcgal %s - an STC MCU ISP flash tool\n(C) 2014-2017 Grigori Goronzy\nhttps://github.com/grigorig/stcgal" %stcgal.__version__)
|
description="stcgal %s - an STC MCU ISP flash tool\n(C) 2014-2015 Grigori Goronzy\nhttps://github.com/grigorig/stcgal" %stcgal.__version__)
|
||||||
parser.add_argument("code_image", help="code segment file to flash (BIN/HEX)", type=argparse.FileType("rb"), nargs='?')
|
parser.add_argument("code_image", help="code segment file to flash (BIN/HEX)", type=argparse.FileType("rb"), nargs='?')
|
||||||
parser.add_argument("eeprom_image", help="eeprom segment file to flash (BIN/HEX)", type=argparse.FileType("rb"), nargs='?')
|
parser.add_argument("eeprom_image", help="eeprom segment file to flash (BIN/HEX)", type=argparse.FileType("rb"), nargs='?')
|
||||||
parser.add_argument("-a", "--autoreset", help="cycle power automatically by asserting DTR", action="store_true")
|
parser.add_argument("-a", "--autoreset", help="cycle power automatically by asserting DTR", action="store_true")
|
||||||
parser.add_argument("-P", "--protocol", help="protocol version (default: auto)", choices=["stc89", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "usb15", "auto"], default="auto")
|
parser.add_argument("-P", "--protocol", help="protocol version", choices=["stc89", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "usb15", "auto"], default="stc12")
|
||||||
parser.add_argument("-p", "--port", help="serial port device", default="/dev/ttyUSB0")
|
parser.add_argument("-p", "--port", help="serial port device", default="/dev/ttyUSB0")
|
||||||
parser.add_argument("-b", "--baud", help="transfer baud rate (default: 19200)", type=BaudType(), default=19200)
|
parser.add_argument("-b", "--baud", help="transfer baud rate (default: 19200)", type=BaudType(), default=19200)
|
||||||
parser.add_argument("-l", "--handshake", help="handshake baud rate (default: 2400)", type=BaudType(), default=2400)
|
parser.add_argument("-l", "--handshake", help="handshake baud rate (default: 2400)", type=BaudType(), default=2400)
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import serial
|
import serial
|
||||||
import sys, os, time, struct, re, errno
|
import sys, os, time, struct, re
|
||||||
import argparse
|
import argparse
|
||||||
import collections
|
import collections
|
||||||
from stcgal.models import MCUModelDatabase
|
from stcgal.models import MCUModelDatabase
|
||||||
@ -114,11 +114,7 @@ class StcBaseProtocol:
|
|||||||
|
|
||||||
# read and check frame start magic
|
# read and check frame start magic
|
||||||
packet = bytes()
|
packet = bytes()
|
||||||
# XXX: skip extraneous 0xFE byte?
|
packet += self.read_bytes_safe(1)
|
||||||
leading = self.read_bytes_safe(1)
|
|
||||||
if leading == 0xfe:
|
|
||||||
leading = self.read_bytes_safe(1)
|
|
||||||
packet += leading
|
|
||||||
# Some (?) BSL versions don't send a frame start with the status
|
# Some (?) BSL versions don't send a frame start with the status
|
||||||
# packet. Let's be liberal and accept that always, just in case.
|
# packet. Let's be liberal and accept that always, just in case.
|
||||||
if packet[0] == self.PACKET_MCU[0]:
|
if packet[0] == self.PACKET_MCU[0]:
|
||||||
@ -895,6 +891,8 @@ class Stc12BaseProtocol(StcBaseProtocol):
|
|||||||
response = self.read_packet()
|
response = self.read_packet()
|
||||||
if response[0] != 0x00:
|
if response[0] != 0x00:
|
||||||
raise StcProtocolException("incorrect magic in write packet")
|
raise StcProtocolException("incorrect magic in write packet")
|
||||||
|
elif response[1] != csum:
|
||||||
|
raise StcProtocolException("verification checksum mismatch")
|
||||||
print(".", end="")
|
print(".", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
print(" done")
|
print(" done")
|
||||||
@ -1297,7 +1295,7 @@ class Stc15Protocol(Stc15AProtocol):
|
|||||||
# This is a bit of a hack, but it works.
|
# This is a bit of a hack, but it works.
|
||||||
bauds = self.baud_transfer if (self.mcu_magic >> 8) == 0xf2 else self.baud_transfer * 4
|
bauds = self.baud_transfer if (self.mcu_magic >> 8) == 0xf2 else self.baud_transfer * 4
|
||||||
packet += struct.pack(">H", int(65535 - program_speed / bauds))
|
packet += struct.pack(">H", int(65535 - program_speed / bauds))
|
||||||
packet += bytes(user_trim)
|
packet += struct.pack(">H", int(65535 - (program_speed / bauds) * 1.5))
|
||||||
iap_wait = self.get_iap_delay(program_speed)
|
iap_wait = self.get_iap_delay(program_speed)
|
||||||
packet += bytes([iap_wait])
|
packet += bytes([iap_wait])
|
||||||
self.write_packet(packet)
|
self.write_packet(packet)
|
||||||
@ -1530,11 +1528,7 @@ class StcUsb15Protocol(Stc15Protocol):
|
|||||||
self.status_packet = None
|
self.status_packet = None
|
||||||
raise StcFramingException
|
raise StcFramingException
|
||||||
else: raise StcFramingException
|
else: raise StcFramingException
|
||||||
except StcFramingException:
|
except (StcFramingException, usb.core.USBError): time.sleep(0.5)
|
||||||
time.sleep(0.5)
|
|
||||||
except usb.core.USBError as err:
|
|
||||||
if err.errno == errno.EACCES:
|
|
||||||
raise IOError(err.strerror)
|
|
||||||
|
|
||||||
self.initialize_model()
|
self.initialize_model()
|
||||||
print("done")
|
print("done")
|
||||||
|
Reference in New Issue
Block a user