32 Commits

Author SHA1 Message Date
51ac52d3a3 Fix build status badge
Use GitHub Actions badge.
2021-01-02 18:13:29 +01:00
43dbb2ef64 README: fix coverage badge branch 2021-01-02 18:07:21 +01:00
d7ed8bd530 Fix coveralls integration 2021-01-02 18:06:19 +01:00
6b83017de9 Raise minimal Python version to 3.5
Newer PyYAML versions require Python 3.5.

Python 3.4 is EOL for some time and even 3.5 reached EOL recently. So
just switch to that as minimum version.
2021-01-02 17:24:44 +01:00
2d7ccf8b3d Fix PyYAML warning
Use SafeLoader to get rid of warning.
2021-01-02 17:22:15 +01:00
77b3f0e1b7 Replace Travis CI with GitHub Actions 2021-01-02 15:24:46 +01:00
5d3214060b Merge branch 'coveralls' 2018-11-13 03:18:07 +01:00
7e413b09ec CI: disable PyPy3
There are some test-related issues with it, so disable it for now.
2018-11-13 03:16:52 +01:00
3aa08b67c0 CI: prefer pip to Debian packages
According to Travis CI docs, pip should be preferred.
2018-11-13 03:07:06 +01:00
42f93bc481 Add coveralls badge to README 2018-11-13 02:59:32 +01:00
dbfc1b3f50 CI: Add coveralls support 2018-11-13 02:52:46 +01:00
9d47588ad2 Add PyPI badge to README 2018-11-13 02:20:42 +01:00
217e5fb17e CI: try to fix and simplify apt setup
Run apt update to update the package cache, as this seems to be needed by
Travis now. Also reduce the package set - we don't build any deb or rpm
packages anymore. This should hopefully fix the CI build.
2018-11-09 01:14:41 +01:00
3875b1f415 Note serial module name conflict in FAQ
See #35 for discussion.
2018-11-09 01:02:01 +01:00
8e31765cba Add Quickstart documentation 2018-09-24 23:29:45 +02:00
75db655419 Update version to 1.6
Update version to 1.6 for both the Python package and the Debian package
metadata (untested).
2018-09-24 23:01:13 +02:00
1c062ed0c7 Update documentation
Minor updates and improvements to the documentation.
2018-09-24 22:51:57 +02:00
4fe0a30072 Add test for untrimmed MCUs
Add a test that verifies that programming untrimmed MCUs results in
an error.
2018-09-24 22:15:43 +02:00
7d9f512b6d Fix programing tests
The options mock object needs to have the "version" property, otherwise
tests always pass (they just end up calling the version info).
2018-09-24 22:14:29 +02:00
6544699a84 Minor FAQ rewording 2018-09-24 21:41:36 +02:00
f5089af93a Remove note about stc8 support maturity
It's not experimental anymore.
2018-09-24 21:41:19 +02:00
bc829ce54c frontend: catch unknown errors
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.
2018-09-24 00:43:27 +02:00
97d0d1123b frontend: add -V/--version flag
Add a new CLI flag to print version info and exit, like it is common.
2018-09-23 23:41:44 +02:00
5032b631bf Drop documentation file installation
This doesn't work as I want it to work, after all. Don't install any
documentation for now.
2018-09-23 22:47:50 +02:00
9ae334ec25 Update installation instructions
Mention TQDM dependency and switch to official PyPI repositories.
2018-09-23 22:47:50 +02:00
05984a6c49 CI: drop deploy step
RPM/DEB packages are discontinued (they're unlikely to come back). Users
are encouraged to use PyPI instead.
2018-09-23 22:47:39 +02:00
e0e2ab5526 Update packaging data for PyPI
This makes some minor adjustments, plus some general updates. In short:

* Mark stcgal as stable
* Make tqdm and pyserial requirements more specific
* Add a new long description, specific for PyPI
* Add documentation files to distribution
2018-09-23 22:04:52 +02:00
4cc0deb8e9 Prepare for v1.5 2018-09-23 20:42:06 +02:00
5ab2a73411 Merge pull request #45 from Seanjimon/add_tqdm_dependency
Add tqdm as required package. Otherwise missing dependency.
2018-09-20 18:06:10 +02:00
4a40d5613a add tqdm as required package. Otherwise missing dependency 2018-09-20 17:15:42 +02:00
83c0b47f62 Update installation instructions
The easiest way to install is arguably by using pip, so recommend that.
2018-09-06 21:54:09 +02:00
b0e882ff32 Merge branch 'better-docs' 2018-09-06 21:07:49 +02:00
15 changed files with 176 additions and 70 deletions

50
.github/workflows/python.yml vendored Normal file
View File

@ -0,0 +1,50 @@
name: Python package
on: [push]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.5, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyusb coverage coveralls pyserial PyYAML tqdm
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build package
run: |
python setup.py build
- name: Test with unittest
run: |
coverage run --source=stcgal setup.py test
- name: Coveralls
run: |
coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: ${{ matrix.python-version }}
COVERALLS_PARALLEL: true
coveralls:
name: Finish Coveralls
needs: test
runs-on: ubuntu-latest
container: python:3-slim
steps:
- name: Finished
run: |
pip3 install --upgrade coveralls
coveralls --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,33 +0,0 @@
sudo: required
dist: trusty
language: python
cache:
- pip
python:
- "3.4"
- "3.5"
- "3.6"
- "pypy3"
before_install:
- sudo apt install rpm dpkg-dev debhelper dh-python python3-setuptools fakeroot python3-serial python3-yaml
install:
- pip install pyserial pyusb tqdm
script:
- python setup.py build
- python setup.py test
before_deploy:
- deactivate
- python3 setup.py bdist_rpm
- dpkg-buildpackage -uc -us
- cp ../*.deb dist/
deploy:
provider: releases
api_key: $GH_TOKEN
file_glob: true
file:
- dist/stcgal*_all.deb
- dist/stcgal*.noarch.rpm
skip_cleanup: true
on:
tags: true
python: "3.4"

View File

@ -1,4 +1,6 @@
[![Build Status](https://travis-ci.org/grigorig/stcgal.svg)](https://travis-ci.org/grigorig/stcgal) [![Build Status](https://github.com/grigorig/stcgal/workflows/Python%20package/badge.svg?branch=master)](https://github.com/grigorig/stcgal/actions?query=workflow%3A%22Python+package%22)
[![Coverage Status](https://coveralls.io/repos/github/grigorig/stcgal/badge.svg?branch=master)](https://coveralls.io/github/grigorig/stcgal?branch=master)
[![PyPI version](https://badge.fury.io/py/stcgal.svg)](https://badge.fury.io/py/stcgal)
stcgal - STC MCU ISP flash tool stcgal - STC MCU ISP flash tool
=============================== ===============================
@ -32,6 +34,17 @@ Features
* Automatic power-cycling with DTR toggle or a custom shell command * Automatic power-cycling with DTR toggle or a custom shell command
* Automatic UART protocol detection * Automatic UART protocol detection
Quickstart
----------
Install stcgal (might need root/administrator privileges):
pip3 install stcgal
Call stcgal and show usage:
stcgal -h
Further information Further information
------------------- -------------------

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
stcgal (1.6) unstable; urgency=low
* Update to 1.6
-- Grigori Goronzy <greg@chown.ath.cx> Mon, 24 Sep 2018 22:56:31 +0200
stcgal (1.4) unstable; urgency=low stcgal (1.4) unstable; urgency=low
* Update to 1.4 * Update to 1.4

4
debian/docs vendored
View File

@ -1,2 +1,4 @@
README.md README.md
TODO.md doc/USAGE.md
doc/MODELS.md
doc/FAQ.md

View File

@ -7,7 +7,7 @@ By design, this is not possible with STC's bootloader protocols. This is conside
### Which serial interfaces have been tested with stcgal? ### Which serial interfaces have been tested with stcgal?
The following USB-based UART interface chips have been successfully tested with stcgal: stcgal should work fine with common 16550 compatible UARTs that are traditionally available on many platforms. However, nowadays, USB-based UARTs are the typical case. The following USB-based UART interface chips have been successfully tested with stcgal:
* FT232 family (OS: Linux, Windows) * FT232 family (OS: Linux, Windows)
* CH340/CH341 (OS: Windows, Linux requires Kernel 4.10) * CH340/CH341 (OS: Windows, Linux requires Kernel 4.10)
@ -20,6 +20,10 @@ Interfaces that are known to not work:
In general, stcgal requires accurate baud rate timings and parity support. In general, stcgal requires accurate baud rate timings and parity support.
### stcgal fails to start with the error `module 'serial' has no attribute 'PARITY_NONE'` or similar
There is a module name conflict between the PyPI package 'serial' (a data serialization library) and the PyPI package 'pyserial' (the serial port access library needed by stcgal). You have to uninstall the 'serial' package (`pip3 uninstall serial`) and reinstall 'pyserial' (`pip3 install --force-reinstall pyserial`) to fix this. There is no other known solution at the moment.
### stcgal fails to recognize the MCU and is stuck at "Waiting for MCU" ### stcgal fails to recognize the MCU and is stuck at "Waiting for MCU"
There are a number of issues that can result in this symptom: There are a number of issues that can result in this symptom:
@ -40,7 +44,7 @@ Various remedies are possible to avoid parasitic powering.
First, make sure that the frequency specified uses the correct unit. The frequency is specified in kHz and the safe range is approximately 5000 kHz - 30000 kHz. Furthermore, frequency trimming uses the UART clock as the clock reference, so UART incompatibilities or clock inaccuracies can also result in issues with frequency trimming. If possible, try another UART chip. First, make sure that the frequency specified uses the correct unit. The frequency is specified in kHz and the safe range is approximately 5000 kHz - 30000 kHz. Furthermore, frequency trimming uses the UART clock as the clock reference, so UART incompatibilities or clock inaccuracies can also result in issues with frequency trimming. If possible, try another UART chip.
### Baud rate switching fails ### Baud rate switching fails or flash programming fails
This can especially happen at high programming baud rates, e.g. 115200 baud. Try a lower baudrate, or stick to the default of 19200 baud. Some USB UARTs are known to cause problems due to inaccurate timing as well, which can lead to various issues. This can especially happen at high programming baud rates, e.g. 115200 baud. Try a lower baudrate, or stick to the default of 19200 baud. Some USB UARTs are known to cause problems due to inaccurate timing as well, which can lead to various issues.

View File

@ -1,10 +1,17 @@
Installation Installation
============ ============
stcgal requires Python 3.2 (or later) and pySerial. USB support is stcgal requires Python 3.2 (or later), pyserial 3.0 or later and
optional and requires pyusb 1.0.0b2 or later. You can run stcgal TQDM 4.0.0 or later. USB support is optional and requires pyusb
directly with the included ```stcgal.py``` script. The recommended 1.0.0b2 or later. You can run stcgal directly with the included
method for permanent installation is to use Python's setuptools. Run ```stcgal.py``` script if the dependencies are already installed.
```./setup.py build``` to build and ```sudo ./setup.py install```
to install stcgal. A permanent installation provides the ```stcgal``` There are several options for permanent installation:
command.
* Use Python3 and ```pip```. Run ```pip3 install stcgal``` to
install the latest release of stcgal globally on your system.
This may require administrator/root permissions for write access
to system directories.
* Use setuptools. Run ```./setup.py build``` to build and
```sudo ./setup.py install``` to install stcgal.

View File

@ -1,7 +1,7 @@
Supported MCU models Supported MCU models
==================== ====================
stcgal should fully support STC 89/90/10/11/12/15 series MCUs. Support for STC8 series MCUs is work in progress. stcgal should fully support STC 89/90/10/11/12/15/8 series MCUs.
So far, stcgal was tested with the following MCU models: So far, stcgal was tested with the following MCU models:

18
doc/PyPI.md Normal file
View File

@ -0,0 +1,18 @@
stcgal - STC MCU ISP flash tool
===============================
stcgal is a command line flash programming tool for [STC MCU Ltd](http://stcmcu.com/).
8051 compatible microcontrollers.
STC microcontrollers have an UART/USB based boot strap loader (BSL). It
utilizes a packet-based protocol to flash the code memory and IAP
memory over a serial link. This is referred to as in-system programming
(ISP). The BSL is also used to configure various (fuse-like) device
options. Unfortunately, this protocol is not 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
software; it supports a wide range of MCUs, it is very portable and
suitable for automation.
[See the GitHub page for more information](https://github.com/grigorig/stcgal).

View File

@ -4,12 +4,14 @@ Usage
Call stcgal with ```-h``` for usage information. Call stcgal with ```-h``` for usage information.
``` ```
usage: stcgal.py [-h] [-a] [-P {stc89,stc12a,stc12,stc15a,stc15,auto}] usage: stcgal.py [-h] [-a] [-r RESETCMD]
[-P {stc89,stc12a,stc12b,stc12,stc15a,stc15,stc8,usb15,auto}]
[-p PORT] [-b BAUD] [-l HANDSHAKE] [-o OPTION] [-t TRIM] [-D] [-p PORT] [-b BAUD] [-l HANDSHAKE] [-o OPTION] [-t TRIM] [-D]
[-V]
[code_image] [eeprom_image] [code_image] [eeprom_image]
stcgal 1.0 - an STC MCU ISP flash tool stcgal 1.5 - an STC MCU ISP flash tool
(C) 2014-2015 Grigori Goronzy (C) 2014-2018 Grigori Goronzy and others
https://github.com/grigorig/stcgal https://github.com/grigorig/stcgal
positional arguments: positional arguments:
@ -20,18 +22,20 @@ optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-a, --autoreset cycle power automatically by asserting DTR -a, --autoreset cycle power automatically by asserting DTR
-r RESETCMD, --resetcmd RESETCMD -r RESETCMD, --resetcmd RESETCMD
Use this shell command for board power-cycling shell command for board power-cycling (instead of DTR
(instead of DTR assertion) assertion)
-P {stc89,stc12a,stc12,stc15a,stc15,auto}, --protocol {stc89,stc12a,stc12,stc15a,stc15,auto} -P {stc89,stc12a,stc12b,stc12,stc15a,stc15,stc8,usb15,auto}, --protocol {stc89,stc12a,stc12b,stc12,stc15a,stc15,stc8,usb15,auto}
protocol version protocol version (default: auto)
-p PORT, --port PORT serial port device -p PORT, --port PORT serial port device
-b BAUD, --baud BAUD transfer baud rate (default: 19200) -b BAUD, --baud BAUD transfer baud rate (default: 19200)
-l HANDSHAKE, --handshake HANDSHAKE -l HANDSHAKE, --handshake HANDSHAKE
handshake baud rate (default: 2400) handshake baud rate (default: 2400)
-o OPTION, --option OPTION -o OPTION, --option OPTION
set option (can be used multiple times) set option (can be used multiple times, see
-t TRIM, --trim TRIM RC oscillator frequency in kHz (STC15 series only) documentation)
-t TRIM, --trim TRIM RC oscillator frequency in kHz (STC15+ series only)
-D, --debug enable debug output -D, --debug enable debug output
-V, --version print version info and exit
``` ```
Most importantly, ```-p``` sets the serial port to be used for programming. Most importantly, ```-p``` sets the serial port to be used for programming.
@ -43,6 +47,7 @@ BSL. The protocol can be specified with the ```-P``` flag. By default
UART protocol autodetection is used. The mapping between protocols UART protocol autodetection is used. The mapping between protocols
and MCU series is as follows: and MCU series is as follows:
* ```auto``` Automatic detection of UART based protocols (default)
* ```stc89``` STC89/90 series * ```stc89``` STC89/90 series
* ```stc12a``` STC12x052 series and possibly others * ```stc12a``` STC12x052 series and possibly others
* ```stc12b``` STC12x52 series, STC12x56 series and possibly others * ```stc12b``` STC12x52 series, STC12x56 series and possibly others
@ -51,11 +56,10 @@ and MCU series is as follows:
* ```stc15``` Most STC15 series * ```stc15``` Most STC15 series
* ```stc8``` STC8 series * ```stc8``` STC8 series
* ```usb15``` USB support on STC15W4 series * ```usb15``` USB support on STC15W4 series
* ```auto``` Automatic detection of UART based protocols (default)
The text files in the doc/ subdirectory provide an overview over The text files in the doc/reverse-engineering subdirectory provide an
the reverse engineered protocols used by the BSLs. For more details, overview over the reverse engineered protocols used by the BSLs. For
please read the source code. more details, please read the source code.
### Getting MCU information ### Getting MCU information
@ -92,6 +96,8 @@ Target options:
Disconnected! Disconnected!
``` ```
If the identification fails, see the [FAQ](FAQ.md) for troubleshooting.
### Program the flash memory ### Program the flash memory
stcgal supports Intel HEX encoded files as well as binary files. Intel stcgal supports Intel HEX encoded files as well as binary files. Intel
@ -195,8 +201,8 @@ If the internal RC oscillator is used (```clock_source=internal```),
stcgal can execute a trim procedure to adjust it to a given value. This stcgal can execute a trim procedure to adjust it to a given value. This
is only supported by STC15 series and newer. The trim values are stored is only supported by STC15 series and newer. The trim values are stored
with device options. Use the ```-t``` flag to request trimming to a certain with device options. Use the ```-t``` flag to request trimming to a certain
value. Generally, frequencies between 4 and 35 MHz can be achieved. If value. Generally, frequencies between 4000 and 30000 kHz can be achieved.
trimming fails, stcgal will abort. If trimming fails, stcgal will abort.
### Automatic power-cycling ### Automatic power-cycling

View File

@ -24,14 +24,14 @@
import stcgal import stcgal
from setuptools import setup, find_packages from setuptools import setup, find_packages
with open("README.md", "r") as fh: with open("doc/PyPI.md", "r") as fh:
long_description = fh.read() long_description = fh.read()
setup( setup(
name = "stcgal", name = "stcgal",
version = stcgal.__version__, version = stcgal.__version__,
packages = find_packages(exclude=["doc", "tests"]), packages = find_packages(exclude=["doc", "tests"]),
install_requires = ["pyserial"], install_requires = ["pyserial>=3.0", "tqdm>=4.0.0"],
extras_require = { extras_require = {
"usb": ["pyusb>=1.0.0"] "usb": ["pyusb>=1.0.0"]
}, },
@ -50,7 +50,7 @@ setup(
license = "MIT License", license = "MIT License",
platforms = "any", platforms = "any",
classifiers = [ classifiers = [
"Development Status :: 4 - Beta", "Development Status :: 5 - Production/Stable",
"Environment :: Console", "Environment :: Console",
"Intended Audience :: Developers", "Intended Audience :: Developers",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
@ -58,7 +58,6 @@ setup(
"Operating System :: Microsoft :: Windows", "Operating System :: Microsoft :: Windows",
"Operating System :: MacOS", "Operating System :: MacOS",
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.6",
"Topic :: Software Development :: Embedded Systems", "Topic :: Software Development :: Embedded Systems",

View File

@ -1 +1 @@
__version__ = "1.4" __version__ = "1.6"

View File

@ -147,6 +147,10 @@ class StcGal:
def run(self): def run(self):
"""Run programmer, main entry point.""" """Run programmer, main entry point."""
if self.opts.version:
print("stcgal {}".format(stcgal.__version__))
return 0
try: try:
self.protocol.connect(autoreset=self.opts.autoreset, resetcmd=self.opts.resetcmd) self.protocol.connect(autoreset=self.opts.autoreset, resetcmd=self.opts.resetcmd)
if isinstance(self.protocol, StcAutoProtocol): if isinstance(self.protocol, StcAutoProtocol):
@ -178,6 +182,10 @@ class StcGal:
sys.stdout.flush() sys.stdout.flush()
print("I/O error: %s" % ex, file=sys.stderr) print("I/O error: %s" % ex, file=sys.stderr)
return 1 return 1
except Exception as ex:
sys.stdout.flush()
print("Unexpected error: %s" % ex, file=sys.stderr)
return 1
try: try:
if self.opts.code_image: if self.opts.code_image:
@ -214,19 +222,20 @@ def cli():
# check arguments # check arguments
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
description="stcgal {} - an STC MCU ISP flash tool\n".format(stcgal.__version__) + description="stcgal {} - an STC MCU ISP flash tool\n".format(stcgal.__version__) +
"(C) 2014-2017 Grigori Goronzy\nhttps://github.com/grigorig/stcgal") "(C) 2014-2018 Grigori Goronzy and others\nhttps://github.com/grigorig/stcgal")
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("-r", "--resetcmd", help="Use this shell command for board power-cycling (instead of DTR assertion)", action="store") parser.add_argument("-r", "--resetcmd", help="shell command for board power-cycling (instead of DTR assertion)", action="store")
parser.add_argument("-P", "--protocol", help="protocol version (default: auto)", parser.add_argument("-P", "--protocol", help="protocol version (default: auto)",
choices=["stc89", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "stc8", "usb15", "auto"], default="auto") choices=["stc89", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "stc8", "usb15", "auto"], default="auto")
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)
parser.add_argument("-o", "--option", help="set option (can be used multiple times)", action="append") parser.add_argument("-o", "--option", help="set option (can be used multiple times, see documentation)", action="append")
parser.add_argument("-t", "--trim", help="RC oscillator frequency in kHz (STC15 series only)", type=float, default=0.0) parser.add_argument("-t", "--trim", help="RC oscillator frequency in kHz (STC15+ series only)", type=float, default=0.0)
parser.add_argument("-D", "--debug", help="enable debug output", action="store_true") parser.add_argument("-D", "--debug", help="enable debug output", action="store_true")
parser.add_argument("-V", "--version", help="print version info and exit", action="store_true")
opts = parser.parse_args() opts = parser.parse_args()
# run programmer # run programmer

View File

@ -0,0 +1,5 @@
name: STC8F2K08S2 untrimmed programming test
protocol: stc8
code_data: [49, 50, 51, 52, 53, 54, 55, 56, 57]
responses:
- [0x50, 0xFF, 0xFF, 0xFF, 0xFF, 0x8F, 0x00, 0x04, 0xFF, 0xFF, 0x8B, 0xFD, 0xFF, 0x27, 0x38, 0xF5, 0x73, 0x73, 0x55, 0x00, 0xF6, 0x41, 0x0A, 0x88, 0x86, 0x6F, 0x8F, 0x08, 0x20, 0x20, 0x20, 0x01, 0x00, 0x00, 0x20, 0x05, 0x3C, 0x18, 0x05, 0x22, 0x32, 0xFF]

View File

@ -27,6 +27,7 @@ from unittest.mock import patch
import yaml import yaml
import stcgal.frontend import stcgal.frontend
import stcgal.protocols import stcgal.protocols
from stcgal.protocols import StcProtocolException
def convert_to_bytes(list_of_lists): def convert_to_bytes(list_of_lists):
"""Convert lists of integer lists to list of byte lists""" """Convert lists of integer lists to list of byte lists"""
@ -43,6 +44,7 @@ def get_default_opts():
opts.trim = 22118 opts.trim = 22118
opts.eeprom_image = None opts.eeprom_image = None
opts.debug = False opts.debug = False
opts.version = False
opts.code_image.name = "test.bin" opts.code_image.name = "test.bin"
opts.code_image.read.return_value = b"123456789" opts.code_image.read.return_value = b"123456789"
return opts return opts
@ -127,6 +129,24 @@ class ProgramTests(unittest.TestCase):
"""Test a programming cycle with STC15 protocol, L1 series""" """Test a programming cycle with STC15 protocol, L1 series"""
self._program_yml("./tests/stc15l104w.yml", serial_mock, read_mock) self._program_yml("./tests/stc15l104w.yml", serial_mock, read_mock)
@patch("stcgal.protocols.StcBaseProtocol.read_packet")
@patch("stcgal.protocols.Stc89Protocol.write_packet")
@patch("stcgal.protocols.serial.Serial", autospec=True)
@patch("stcgal.protocols.time.sleep")
@patch("sys.stdout")
def test_program_stc8_untrimmed(self, out, sleep_mock, serial_mock, write_mock, read_mock):
"""Test error with untrimmed MCU"""
with open("./tests/stc8f2k08s2-untrimmed.yml") as test_file:
test_data = yaml.load(test_file.read(), Loader=yaml.SafeLoader)
opts = get_default_opts()
opts.trim = 0.0
opts.protocol = test_data["protocol"]
opts.code_image.read.return_value = bytes(test_data["code_data"])
serial_mock.return_value.inWaiting.return_value = 1
read_mock.side_effect = convert_to_bytes(test_data["responses"])
gal = stcgal.frontend.StcGal(opts)
self.assertEqual(gal.run(), 1)
def test_program_stc15w4_usb(self): def test_program_stc15w4_usb(self):
"""Test a programming cycle with STC15W4 USB protocol""" """Test a programming cycle with STC15W4 USB protocol"""
self.skipTest("USB not supported yet, trace missing") self.skipTest("USB not supported yet, trace missing")
@ -134,7 +154,7 @@ class ProgramTests(unittest.TestCase):
def _program_yml(self, yml, serial_mock, read_mock): def _program_yml(self, yml, serial_mock, read_mock):
"""Program MCU with data from YAML file""" """Program MCU with data from YAML file"""
with open(yml) as test_file: with open(yml) as test_file:
test_data = yaml.load(test_file.read()) test_data = yaml.load(test_file.read(), Loader=yaml.SafeLoader)
opts = get_default_opts() opts = get_default_opts()
opts.protocol = test_data["protocol"] opts.protocol = test_data["protocol"]
opts.code_image.read.return_value = bytes(test_data["code_data"]) opts.code_image.read.return_value = bytes(test_data["code_data"])