Skip to content

Commit ad6dfc8

Browse files
committed
cmsis_dap: Send correct version string when queried.
1 parent 1c0cc13 commit ad6dfc8

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

orbtrace/debug/cmsis_dap.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from amaranth import *
22
from .dbgIF import DBGIF
3+
from ..git_version import get_version
34

45
# Principle of operation
56
# ======================
@@ -19,8 +20,8 @@
1920
DAP_CONNECT_DEFAULT = 1 # Default connect is SWD
2021
DAP_PROTOCOL_STRING_LEN = 5
2122
DAP_PROTOCOL_STRING = Cat(C(DAP_PROTOCOL_STRING_LEN+1,8),C(ord('2'),8),C(ord('.'),8),C(ord('1'),8),C(ord('.'),8),C(ord('0'),8),C(0,8)) # Protocol version V2.1.0
22-
DAP_VERSION_STRING_LEN = 4
23-
DAP_VERSION_STRING = Cat(C(DAP_VERSION_STRING_LEN+1,8),C(0x31,8),C(0x2e,8),C(0x30,8),C(0x30,8),C(0,8))
23+
DAP_VERSION_STRING_LEN = len(get_version().encode('utf-8'))
24+
DAP_VERSION_STRING = Cat(C(DAP_VERSION_STRING_LEN+1,8), *(C(c, 8) for c in get_version().encode('utf-8')), C(0,8))
2425
DAP_CAPABILITIES = 0x03 # JTAG and SWD Debug
2526
DAP_TD_TIMER_FREQ = 0x3B9ACA00 # 1uS resolution timer
2627
DAP_MAX_PACKET_COUNT = 1 # 1 max packet count
@@ -164,7 +165,7 @@ def __init__(self, streamIn, streamOut, dbgif, v2Indication):
164165
self.rxedLen = Signal(3) # Rxlen picked up so far
165166

166167
# Transmit block construction
167-
self.txBlock = Signal( 14*8 ) # Response to be returned
168+
self.txBlock = Signal( 32*8 ) # Response to be returned
168169
self.txLen = Signal(range(MAX_MSG_LEN)) # Length of response to be returned
169170
self.txedLen = Signal(range(MAX_MSG_LEN)) # Length of response that has been returned so far
170171
self.busy = Signal() # Indicator that we can't receive stream traffic at the moment

orbtrace/git_version.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import functools
2+
import subprocess
3+
import re
4+
5+
@functools.cache
6+
def get_version():
7+
return subprocess.check_output('git describe --always --long --dirty', shell = True).decode('utf-8').strip()
8+
9+
def get_version_bcd():
10+
m = re.match(r'v(\d{1,2})\.(\d)(?:\.(\d+))?-', get_version())
11+
12+
if not m:
13+
raise ValueError('Version doesn\'t match pattern representable as BCD')
14+
15+
major, minor, patch = m.groups()
16+
17+
return int(major) + int(minor) * 0.1 + int(patch or 0) * 0.01

orbtrace/soc.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import subprocess
21
import uuid
32

43
from orbtrace.usb_serialnumber import USBSerialNumberHandler
@@ -31,6 +30,8 @@
3130

3231
from .reset import Reset
3332

33+
from .git_version import get_version, get_version_bcd
34+
3435
from usb_protocol.types import USBTransferType, USBRequestType, USBStandardRequests, USBRequestRecipient, DescriptorTypes
3536
from usb_protocol.emitters.descriptors import cdc
3637

@@ -767,16 +768,14 @@ def add_usb_version(self):
767768
# USB interface.
768769
if_num = self.usb_alloc.interface(guid_discriminator=0x00_56)
769770

770-
version = subprocess.check_output('git describe --always --long --dirty', shell = True).decode('utf-8').strip()
771-
772771
# USB descriptors.
773772
with self.usb_conf_desc.InterfaceDescriptor() as i:
774773
i.bInterfaceNumber = if_num
775774
i.bInterfaceClass = 0xff
776775
i.bInterfaceSubclass = 0x56
777776
i.bInterfaceProtocol = 0x00
778777

779-
i.iInterface = f'Version: {version}'
778+
i.iInterface = f'Version: {get_version()}'
780779

781780
def add_usb_control_handler(self, handler):
782781
if hasattr(self, 'usb_control_ep'):
@@ -798,7 +797,7 @@ def add_usb(self, vid, pid):
798797
d.idVendor = vid
799798
d.idProduct = pid
800799
d.bcdUSB = 2.1 # Support BOS descriptors
801-
d.bcdDevice = 1.2
800+
d.bcdDevice = get_version_bcd()
802801

803802
d.iManufacturer = "Orbcode"
804803
d.iProduct = "Orbtrace Bootloader" if pid == 0x3442 else "Orbtrace Test" if pid == 0x0001 else "Orbtrace"

0 commit comments

Comments
 (0)