stc8: print additional MCU info

Print manufacturing date as well as the factory-measured internal
voltage reference value. These values are displayed by STC-ISP, too.
This commit is contained in:
Grigori Goronzy 2018-08-21 12:42:51 +02:00
parent 7b4758499b
commit fcbc560ade
4 changed files with 29 additions and 1 deletions

View File

@ -20,7 +20,8 @@ Status packet
-------------
46 B9 68 00 30 50 00 54 62 58 5D 00 04 FF FD 8B BF FF 27 4A F7 FE 73 55 00 F6 28 09 85 E3 5F 80 07 20 20 20 01 00 00 FE 05 3A 17 05 25 91 FF 10 AE 16
^^^^^ wakeup clock
^^^^^ wakeup clock ^^^^^ reference voltage
^^^^^^^^ mfg. date
Clock set to 20 MHz by STC-ISP (encoding is different compared to STC15):

View File

@ -1554,6 +1554,8 @@ class Stc8Protocol(Stc15Protocol):
def __init__(self, port, handshake, baud, trim):
Stc15Protocol.__init__(self, port, handshake, baud, trim)
self.trim_divider = None
self.reference_voltage = None
self.mfg_date = ()
def initialize_options(self, status_packet):
"""Initialize options"""
@ -1580,6 +1582,12 @@ class Stc8Protocol(Stc15Protocol):
# wakeup timer factory value
self.wakeup_freq, = struct.unpack(">H", packet[23:25])
self.reference_voltage, = struct.unpack(">H", packet[35:37])
self.mfg_date = (
2000 + Utils.decode_packed_bcd(packet[37]),
Utils.decode_packed_bcd(packet[38]),
Utils.decode_packed_bcd(packet[39])
)
bl_version, bl_stepping = struct.unpack("BB", packet[17:19])
bl_minor = packet[22] & 0x0f
@ -1587,6 +1595,12 @@ class Stc8Protocol(Stc15Protocol):
bl_minor, chr(bl_stepping))
self.bsl_version = bl_version
def print_mcu_info(self):
"""Print additional STC8 info"""
super().print_mcu_info()
print("Target ref. voltage: %d mV" % self.reference_voltage)
print("Target mfg. date: %04d-%02d-%02d" % self.mfg_date)
def calibrate(self):
"""Calibrate selected user frequency frequency and switch to selected baudrate."""

View File

@ -52,6 +52,11 @@ class Utils:
return sep.join(["%02X" % x for x in bytes(bytestr)])
@classmethod
def decode_packed_bcd(cls, byt):
"""Decode two-digit packed BCD value"""
return (byt & 0x0f) + (10 * (byt >> 4))
class BaudType:
"""Check baud rate for validity"""

View File

@ -64,6 +64,14 @@ class TestUtils(unittest.TestCase):
with self.assertRaises(Exception):
Utils.hexstr([400, 500])
def test_decode_packed_bcd(self):
"""Test packed BCD decoder"""
self.assertEqual(Utils.decode_packed_bcd(0x01), 1)
self.assertEqual(Utils.decode_packed_bcd(0x10), 10)
self.assertEqual(Utils.decode_packed_bcd(0x11), 11)
self.assertEqual(Utils.decode_packed_bcd(0x25), 25)
self.assertEqual(Utils.decode_packed_bcd(0x99), 99)
class TestBaudType(unittest.TestCase):
"""Test BaudType class"""