Skip to content

Commit

Permalink
Merge branch 'vendor' into vendor-probe
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-sl committed Jun 30, 2024
2 parents e9c04c2 + 2e20c3b commit 36f4665
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 11 additions & 2 deletions universal_silabs_flasher/flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ProbeResult:
version: Version | None
continue_probing: bool
baudrate: int
vendor: str | None = dataclasses.field(default=None)


class Flasher:
Expand Down Expand Up @@ -153,10 +154,11 @@ async def probe_ezsp(self, baudrate: int) -> ProbeResult:

async def probe_spinel(self, baudrate: int) -> ProbeResult:
async with self._connect_spinel(baudrate) as spinel:
version = await spinel.probe()
version, vendor = await spinel.probe()

return ProbeResult(
version=version,
vendor=vendor,
baudrate=baudrate,
continue_probing=False,
)
Expand Down Expand Up @@ -219,6 +221,7 @@ async def probe_app_type(
self.app_type = probe_method
self.app_version = result.version
self.app_baudrate = result.baudrate
self.app_vendor = result.vendor.strip() if result.vendor else ""
break
else:
if bootloader_probe and self._reset_target:
Expand All @@ -235,8 +238,9 @@ async def probe_app_type(
raise RuntimeError("Failed to probe running application type")

_LOGGER.info(
"Detected %s, version %s at %s baudrate (bootloader baudrate %s)",
"Detected %s, %s version %s at %s baudrate (bootloader baudrate %s)",
self.app_type,
self.app_vendor,
self.app_version,
self.app_baudrate,
self.bootloader_baudrate,
Expand All @@ -256,6 +260,11 @@ async def enter_bootloader(self) -> None:
elif self.app_type is ApplicationType.SPINEL:
async with self._connect_spinel(self.app_baudrate) as spinel:
async with async_timeout.timeout(PROBE_TIMEOUT):
if self.app_vendor and "EFR32" not in self.app_vendor:
raise RuntimeError(
"Flashing Thread firmware is only supported on "
"EFR32 devices"
)
await spinel.enter_bootloader()
elif self.app_type is ApplicationType.EZSP:
async with self._connect_ezsp(self.app_baudrate) as ezsp:
Expand Down
15 changes: 12 additions & 3 deletions universal_silabs_flasher/spinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import typing

import async_timeout
from serial_asyncio import SerialTransport
import zigpy.types

from .common import SerialProtocol, Version, crc16_kermit
Expand Down Expand Up @@ -109,6 +110,14 @@ def __init__(self) -> None:
self._transaction_id: int = 1
self._pending_frames: dict[int, asyncio.Future] = {}

def connection_made(self, transport: SerialTransport) -> None:
super().connection_made(transport)

# de-assert DTR/RTS, some dongles use these to reset device
if transport is not None:
transport.serial.dtr = False
transport.serial.rts = False

def data_received(self, data: bytes) -> None:
super().data_received(data)

Expand Down Expand Up @@ -239,7 +248,7 @@ async def send_command(

return await self.send_frame(frame, **kwargs)

async def probe(self) -> Version:
async def probe(self) -> tuple[Version, str]:
rsp = await self.send_command(
CommandID.PROP_VALUE_GET,
PropertyID.NCP_VERSION.serialize(),
Expand All @@ -252,9 +261,9 @@ async def probe(self) -> Version:
version = version_string.rstrip(b"\x00").decode("ascii")

# We strip off the date code to get something reasonably stable
short_version, _ = version.split(";", 1)
short_version, vendor, _ = version.split(";", 2)

return Version(short_version)
return Version(short_version), vendor

async def enter_bootloader(self) -> None:
await self.send_command(
Expand Down

0 comments on commit 36f4665

Please sign in to comment.