tinyocd 1.0.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinyocd
3
- Version: 1.0.0
3
+ Version: 1.2.0
4
4
  Summary: Programming Tool for STM32, PY32 and SAMD Microcontrollers via CMSIS-DAP, ST-Link or J-Link
5
5
  Author-email: Stefan Wagner <wagiminator@web.de>
6
6
  Maintainer-email: Stefan Wagner <wagiminator@web.de>
@@ -106,6 +106,8 @@ Example:
106
106
  tinyocd -f firmware.bin
107
107
  ```
108
108
 
109
+ Without action arguments, tinyocd shows the programmer, the chip, whether it is read protected and its option byte registers (user row on SAMD). Then the firmware is started.
110
+
109
111
  Notes:
110
112
  - The BIN file is written to the start of the flash memory (0x08000000 for STM32/PY32, 0x00000000 for SAMD).
111
113
  - If the chip cannot be halted (e.g. SWD pins disabled by the firmware), tinyOCD connects under reset. For this, NRST must be connected to the programmer.
@@ -59,6 +59,8 @@ Example:
59
59
  tinyocd -f firmware.bin
60
60
  ```
61
61
 
62
+ Without action arguments, tinyocd shows the programmer, the chip, whether it is read protected and its option byte registers (user row on SAMD). Then the firmware is started.
63
+
62
64
  Notes:
63
65
  - The BIN file is written to the start of the flash memory (0x08000000 for STM32/PY32, 0x00000000 for SAMD).
64
66
  - If the chip cannot be halted (e.g. SWD pins disabled by the firmware), tinyOCD connects under reset. For this, NRST must be connected to the programmer.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tinyocd"
7
- version = "1.0.0"
7
+ version = "1.2.0"
8
8
  description = "Programming Tool for STM32, PY32 and SAMD Microcontrollers via CMSIS-DAP, ST-Link or J-Link"
9
9
  keywords = ["SWD", "ARM", "Cortex-M", "STM32", "PY32", "PUYA", "SAMD", "ATSAMD21", "CMSIS-DAP", "DAPLink", "ST-Link", "J-Link", "microcontroller"]
10
10
  dependencies = ["pyusb", "libusb-package; platform_system == 'Windows'"]
@@ -2,7 +2,7 @@
2
2
  # ===================================================================================
3
3
  # Project: tinyOCD - Programming Tool for STM32, PY32 and SAMD Microcontrollers
4
4
  # via CMSIS-DAP (DAPLink), ST-Link or J-Link
5
- # Version: v1.0
5
+ # Version: v1.2
6
6
  # Year: 2026
7
7
  # Author: Stefan Wagner
8
8
  # Github: https://github.com/wagiminator
@@ -70,6 +70,8 @@
70
70
  # -R, --pinreset make NRST pin a reset pin
71
71
  # -f FLASH, --flash FLASH write BIN file to flash and verify
72
72
  # -t, --list list supported chips
73
+ # Without action arguments, the programmer, the chip and its option bytes
74
+ # (user row on SAMD) are shown.
73
75
  #
74
76
  # - Example:
75
77
  # python3 tinyocd.py -f firmware.bin
@@ -113,10 +115,8 @@ def _main():
113
115
  print_supported_chips()
114
116
  sys.exit(0)
115
117
 
116
- # Check arguments
117
- if not any( (args.unlock, args.lock, args.erase, args.bootpin, args.pingpio, args.pinreset, args.flash) ):
118
- print('No arguments - no action!')
119
- sys.exit(0)
118
+ # Check arguments (without action arguments the chip info is shown)
119
+ showinfo = not any( (args.unlock, args.lock, args.erase, args.bootpin, args.pingpio, args.pinreset, args.flash) )
120
120
  if args.pingpio and args.pinreset:
121
121
  sys.stderr.write('ERROR: -G and -R cannot be used together!\n')
122
122
  sys.exit(1)
@@ -160,6 +160,17 @@ def _main():
160
160
  if ocd.locked:
161
161
  print('Chip is read protected (locked).')
162
162
 
163
+ # Show option bytes (no action arguments)
164
+ if showinfo:
165
+ if not ocd.locked:
166
+ print('Read protection: off')
167
+ options = ocd.option_bytes()
168
+ if options and all(value is None for name, value in options):
169
+ print('INFO: Option bytes cannot be read.')
170
+ else:
171
+ for name, value in options:
172
+ print('%-16s %s' % (name + ':', 'not readable' if value is None else '0x%08x' % value))
173
+
163
174
  # Check option support before doing anything
164
175
  if args.bootpin and not ocd.chip.has_bootpin:
165
176
  raise Exception('BOOT0 pin configuration is not supported on this chip')
@@ -1467,6 +1478,12 @@ class Target:
1467
1478
  self.chip.driver.nrst(gpio)
1468
1479
  self.reconnect_after_reset()
1469
1480
 
1481
+ # Option byte registers (user row on SAMD) as list of (name, value or None)
1482
+ def option_bytes(self):
1483
+ if self.chip.driver is None:
1484
+ return []
1485
+ return self.chip.driver.options()
1486
+
1470
1487
 
1471
1488
  # ===================================================================================
1472
1489
  # Flash Driver Base Class
@@ -1475,6 +1492,7 @@ class Target:
1475
1492
  class FlashDriver:
1476
1493
  unit = 4
1477
1494
  iwdg_freeze = None
1495
+ option_regs = () # (name, offset) of option registers
1478
1496
 
1479
1497
  def __init__(self, target):
1480
1498
  self.t = target
@@ -1503,6 +1521,9 @@ class FlashDriver:
1503
1521
  def nrst(self, gpio):
1504
1522
  raise Exception('NRST pin configuration is not supported on this chip')
1505
1523
 
1524
+ def options(self):
1525
+ return [(name, self.t.try_read32(self.base + offset)) for name, offset in self.option_regs]
1526
+
1506
1527
  def r(self, reg):
1507
1528
  return self.t.read32(self.base + reg)
1508
1529
 
@@ -1523,6 +1544,7 @@ class FlashDriver:
1523
1544
 
1524
1545
  class STM32F1Flash(FlashDriver):
1525
1546
  unit = 2
1547
+ option_regs = (('FLASH_OBR', 0x1C), ('FLASH_WRPR', 0x20))
1526
1548
 
1527
1549
  def __init__(self, target, part, devid, size):
1528
1550
  super().__init__(target)
@@ -1628,6 +1650,7 @@ class STM32F1Flash(FlashDriver):
1628
1650
 
1629
1651
  class STM32F4Flash(FlashDriver):
1630
1652
  unit = 2
1653
+ option_regs = (('FLASH_OPTCR', 0x14),)
1631
1654
 
1632
1655
  def __init__(self, target, part, devid, size):
1633
1656
  super().__init__(target)
@@ -1703,6 +1726,8 @@ class STM32F4Flash(FlashDriver):
1703
1726
  # ===================================================================================
1704
1727
 
1705
1728
  class STM32L0Flash(FlashDriver):
1729
+ option_regs = (('FLASH_OPTR', 0x1C),)
1730
+
1706
1731
  def __init__(self, target, part, devid, size):
1707
1732
  super().__init__(target)
1708
1733
  self.l1 = (part == 0xC23)
@@ -1794,6 +1819,7 @@ class STM32L4Flash(FlashDriver):
1794
1819
  self.busy = (1 << 16) | (1 << 18) | ((1 << 17) if devid == 0x467 else 0)
1795
1820
  self.KEYR, self.OPTKEYR, self.SR, self.CR, self.OPTR = \
1796
1821
  (0x08, 0x10, 0x20, 0x28, 0x40) if self.l5 else (0x08, 0x0C, 0x10, 0x14, 0x20)
1822
+ self.option_regs = (('FLASH_OPTR', self.OPTR),)
1797
1823
  if opts.get('tz') and (self.r(self.OPTR) & (1 << 31)):
1798
1824
  raise Exception('TrustZone is enabled on this chip, not supported')
1799
1825
  fz = opts.get('fz')
@@ -1881,6 +1907,8 @@ class STM32L4Flash(FlashDriver):
1881
1907
  # ===================================================================================
1882
1908
 
1883
1909
  class STM32H7Flash(FlashDriver):
1910
+ option_regs = (('FLASH_OPTSR_CUR', 0x1C),)
1911
+
1884
1912
  def __init__(self, target, part, devid, size):
1885
1913
  super().__init__(target)
1886
1914
  self.base = 0x52002000
@@ -1967,6 +1995,7 @@ class STM32H7Flash(FlashDriver):
1967
1995
 
1968
1996
  class STM32H5Flash(FlashDriver):
1969
1997
  unit = 16
1998
+ option_regs = (('FLASH_OPTSR_CUR', 0x50),)
1970
1999
  iwdg_freeze = (0x44024008, 1 << 12)
1971
2000
 
1972
2001
  def __init__(self, target, part, devid, size):
@@ -2017,6 +2046,7 @@ PY32_VARIANTS = {
2017
2046
 
2018
2047
  class PY32Flash(FlashDriver):
2019
2048
  unit = 128
2049
+ option_regs = (('FLASH_OPTR', 0x20),)
2020
2050
 
2021
2051
  def __init__(self, target, variant):
2022
2052
  super().__init__(target)
@@ -2162,6 +2192,9 @@ class SAMDFlash(FlashDriver):
2162
2192
  if flags & 0x02:
2163
2193
  raise Exception('NVM controller error (STATUS 0x%04x)' % (self.r(0x18) & 0xFFFF))
2164
2194
 
2195
+ def options(self):
2196
+ return [('USER ROW word %d' % i, self.t.try_read32(0x00804000 + 4 * i)) for i in range(3 if self.d5x else 2)]
2197
+
2165
2198
  def _bootprot(self):
2166
2199
  user = self.t.read32(0x00804000)
2167
2200
  if self.d5x:
@@ -2381,6 +2414,10 @@ def stm32_chip(target, part, devid, dev):
2381
2414
  lock = False
2382
2415
  return Chip(name, drv, base, size, 0x20000000, ramkb * 1024, regions, bootpin, nrst, lock)
2383
2416
 
2417
+ # DBGMCU_IDCODE DEV_ID of PY32F0 devices (the PY32F07x has its own IDCODE):
2418
+ # 0x000: PY32F002A/F003/F030 and early PY32F002B, 0x064: production PY32F002B
2419
+ PY32_DEV_IDS = (0x000, 0x064)
2420
+
2384
2421
  def py32_chip(target, idcode):
2385
2422
  if idcode is None:
2386
2423
  return None
@@ -2391,15 +2428,17 @@ def py32_chip(target, idcode):
2391
2428
  flash = ((v & 7) + 1) << 14 # 16 KB units (max. 128 KB)
2392
2429
  return Chip('PY32F07x', PY32Flash(target, 'f07x'), 0x08000000, flash, 0x20000000, 0x2000,
2393
2430
  bootpin='option', nrst=True)
2394
- if (idcode & 0xFFF) != 0 or idcode in (0, 0xFFFFFFFF):
2431
+ devid = idcode & 0xFFF
2432
+ if devid not in PY32_DEV_IDS or idcode in (0, 0xFFFFFFFF):
2395
2433
  return None
2396
- v = target.try_read32(0x1FFF0FFC)
2397
- t = target.try_read32(0x1FFF0F1C)
2398
- if v not in (None, 0, 0xFFFFFFFF) and t not in (None, 0, 0xFFFFFFFF):
2399
- flash, ram = ((v & 7) + 1) << 13, (((v >> 4) & 3) + 1) << 11
2400
- return Chip('PY32F002A/F003/F030', PY32Flash(target, 'f0xx'), 0x08000000, flash, 0x20000000, ram,
2401
- bootpin='option', nrst=True)
2402
- t = target.try_read32(0x1FFF011C)
2434
+ if devid == 0x000: # PY32F002A/F003/F030 (DEV_ID 0)
2435
+ v = target.try_read32(0x1FFF0FFC)
2436
+ t = target.try_read32(0x1FFF0F1C)
2437
+ if v not in (None, 0, 0xFFFFFFFF) and t not in (None, 0, 0xFFFFFFFF):
2438
+ flash, ram = ((v & 7) + 1) << 13, (((v >> 4) & 3) + 1) << 11
2439
+ return Chip('PY32F002A/F003/F030', PY32Flash(target, 'f0xx'), 0x08000000, flash, 0x20000000, ram,
2440
+ bootpin='option', nrst=True)
2441
+ t = target.try_read32(0x1FFF011C) # PY32F002B (DEV_ID 0 or 0x064)
2403
2442
  if t not in (None, 0, 0xFFFFFFFF):
2404
2443
  return Chip('PY32F002B', PY32Flash(target, 'f002b'), 0x08000000, 0x6000, 0x20000000, 0xC00,
2405
2444
  bootpin=None, nrst=True, lock=False)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinyocd
3
- Version: 1.0.0
3
+ Version: 1.2.0
4
4
  Summary: Programming Tool for STM32, PY32 and SAMD Microcontrollers via CMSIS-DAP, ST-Link or J-Link
5
5
  Author-email: Stefan Wagner <wagiminator@web.de>
6
6
  Maintainer-email: Stefan Wagner <wagiminator@web.de>
@@ -106,6 +106,8 @@ Example:
106
106
  tinyocd -f firmware.bin
107
107
  ```
108
108
 
109
+ Without action arguments, tinyocd shows the programmer, the chip, whether it is read protected and its option byte registers (user row on SAMD). Then the firmware is started.
110
+
109
111
  Notes:
110
112
  - The BIN file is written to the start of the flash memory (0x08000000 for STM32/PY32, 0x00000000 for SAMD).
111
113
  - If the chip cannot be halted (e.g. SWD pins disabled by the firmware), tinyOCD connects under reset. For this, NRST must be connected to the programmer.
File without changes
File without changes