pypicoboot 1.3.2__py3-none-any.whl → 1.5__py3-none-any.whl

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.
picoboot/_version.py CHANGED
@@ -17,4 +17,4 @@
17
17
  */
18
18
  """
19
19
 
20
- __version__ = "1.3.2"
20
+ __version__ = "1.5"
picoboot/picoboot.py CHANGED
@@ -23,7 +23,7 @@ import usb.core
23
23
  import usb.util
24
24
  import struct
25
25
  import itertools
26
- from .utils import uint_to_int
26
+ from .utils import uint_to_int, crc32_ieee
27
27
  from .core.enums import NamedIntEnum
28
28
  from .picobootmonitor import PicoBootMonitor, PicoBootMonitorObserver
29
29
  from .core.log import get_logger
@@ -134,6 +134,7 @@ class Platform(NamedIntEnum):
134
134
 
135
135
  class Addresses(NamedIntEnum):
136
136
  BOOTROM_MAGIC = 0x00000010
137
+ PHYMARKER = 0x10100000
137
138
 
138
139
  class PicoBoot:
139
140
 
@@ -174,7 +175,7 @@ class PicoBoot:
174
175
  logger.debug("PicoBoot device initialized.")
175
176
 
176
177
  @classmethod
177
- def open(cls, vid: int = DEFAULT_VID, pid: list[int] = [DEFAULT_PID_RP2040, DEFAULT_PID_RP2350], serial: Optional[str] = None) -> "PicoBoot":
178
+ def open(cls, vid: int = DEFAULT_VID, pid: list[int] = [DEFAULT_PID_RP2040, DEFAULT_PID_RP2350], serial: Optional[str] = None, slot = -1) -> "PicoBoot":
178
179
  logger.info(f"Opening PicoBoot device with VID={vid:04x} and PIDs={[f'{p:04x}' for p in pid]}...")
179
180
  class find_vidpids(object):
180
181
 
@@ -193,6 +194,13 @@ class PicoBoot:
193
194
  logger.error("No device found in PICOBOOT mode")
194
195
  raise PicoBootNotFoundError("No device found in PICOBOOT mode")
195
196
 
197
+ if slot >= 0:
198
+ logger.info(f"Looking for device in slot {slot}...")
199
+ if (slot >= len(devices)):
200
+ logger.error("No device found in the specified slot")
201
+ raise PicoBootNotFoundError("No device found in the specified slot")
202
+ devices = [devices[slot]] if slot < len(devices) else []
203
+
196
204
  dev = None
197
205
  if serial is None:
198
206
  logger.info("No serial number provided, using the first device found.")
@@ -270,16 +278,30 @@ class PicoBoot:
270
278
  def has_device(self):
271
279
  return self.dev is not None
272
280
 
273
- @property
274
- def serial_number(self) -> int:
275
- s = usb.util.get_string(self.dev, self.dev.iSerialNumber)
276
- return int(s, 16)
277
-
278
281
  @property
279
282
  def serial_number_str(self) -> str:
280
- s = usb.util.get_string(self.dev, self.dev.iSerialNumber)
283
+ try:
284
+ s = None
285
+ if self.platform == Platform.RP2040:
286
+ r = self.flash_read(Addresses.PHYMARKER, 24)
287
+ magic = struct.unpack_from("<Q", r, 0)[0]
288
+ if (magic == 0x5049434F4B455953): # "PICOKEYS"
289
+ crc32 = crc32_ieee(r[0:20])
290
+ if crc32 == struct.unpack_from("<I", r, 20)[0]:
291
+ s = hexlify(r[12:20]).decode().upper()
292
+ if not s:
293
+ s = usb.util.get_string(self.dev, self.dev.iSerialNumber)
294
+ except Exception:
295
+ s = "unknown"
281
296
  return s
282
297
 
298
+ @property
299
+ def serial_number(self) -> int:
300
+ if self.dev is None:
301
+ raise PicoBootInvalidStateError("Device not connected")
302
+ s = self.serial_number_str
303
+ return int(s, 16)
304
+
283
305
  def interface_reset(self) -> None:
284
306
  logger.debug("Resetting interface...")
285
307
  self.dev.ctrl_transfer(
picoboot/utils.py CHANGED
@@ -22,4 +22,18 @@ def uint_to_int(value: int, bits: int = 8) -> int:
22
22
  mask = (1 << bits) - 1
23
23
  value &= mask # ensure value fits in `bits`
24
24
  sign_bit = 1 << (bits - 1)
25
- return value - (1 << bits) if (value & sign_bit) else value
25
+ return value - (1 << bits) if (value & sign_bit) else value
26
+
27
+ def crc32_ieee(data: bytes) -> int:
28
+ crc = 0xFFFFFFFF
29
+
30
+ for b in data:
31
+ crc ^= b
32
+ for _ in range(8):
33
+ if crc & 1:
34
+ crc = (crc >> 1) ^ 0xEDB88320
35
+ else:
36
+ crc >>= 1
37
+
38
+ return crc ^ 0xFFFFFFFF
39
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypicoboot
3
- Version: 1.3.2
3
+ Version: 1.5
4
4
  Summary: Pico Boot for Python
5
5
  Home-page: https://github.com/polhenarejos/pypicoboot
6
6
  Author: Pol Henarejos
@@ -1,14 +1,14 @@
1
1
  picoboot/__init__.py,sha256=c49mZU1EUgBbiMUKo7sLsZE4u1RKmBXjXHmCSgeM5vw,168
2
- picoboot/_version.py,sha256=Q-vBfh-W2TOcL_ePbk1kpQ1OhGGEPzkigb1DJArcDd0,778
3
- picoboot/picoboot.py,sha256=EzSecCtLccsPi7KhdLvbHfNT9PCnM6ZSLIKkwOx8c6A,25927
2
+ picoboot/_version.py,sha256=S-eokld2tlibADYtsq4K91uxjtIu6SYu30ozInVJoBU,776
3
+ picoboot/picoboot.py,sha256=Q1Ur-4-Dv-cepL-Qd4S6PUtrp1srD0kWJeQLHLjp_k8,26925
4
4
  picoboot/picobootmonitor.py,sha256=3msEP2S8ZS7P8QVgKpq9Z9Rcud78XygmG1_0L_OZOvs,2443
5
- picoboot/utils.py,sha256=SjpAoPZrgyD9Ws7NIFVBHt0zPOb8Lpu2_lsmfeT2rXE,1083
5
+ picoboot/utils.py,sha256=7dtF_QEXGLuJispFlrotOuTeyU5FiK26759108k_H8w,1350
6
6
  picoboot/core/__init__.py,sha256=c1kJprnljn0eP1NR3wEw-wJSCSxSRF3DA2jF5MowHXk,57
7
7
  picoboot/core/enums.py,sha256=ugXS-dbdnusLib_ge0vT1OugHVG9ZjJfpUR073MhwdQ,1353
8
8
  picoboot/core/exceptions.py,sha256=AXilq0ViaXyA6Ls9aGx6DHE9TQyPacQbwnHBXgFD3EQ,909
9
9
  picoboot/core/log.py,sha256=XWtN_hgmOtvpDMGDg-9f2BDLUe8elqUAbWti5yCJAA0,1768
10
10
  picoboot/tools/picotool.py,sha256=e2xjIxP5UZn9yfjxUWkJXq6KQHyw4YsGbuQbTauo0-Q,94
11
- pypicoboot-1.3.2.dist-info/METADATA,sha256=CKAHWYWIRjvTbWzanCeZh3w-7NovaoE3IKE9o8uZqtU,41111
12
- pypicoboot-1.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- pypicoboot-1.3.2.dist-info/top_level.txt,sha256=sjegZQO5-kQdFOXXJHm0P7Hg1Nw4Ri0WKHnRYDTsa4I,9
14
- pypicoboot-1.3.2.dist-info/RECORD,,
11
+ pypicoboot-1.5.dist-info/METADATA,sha256=-0G8dMhaIcb-IT3GY5N8_y2uDh4PYWqq0wE-AwvZLnU,41109
12
+ pypicoboot-1.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
+ pypicoboot-1.5.dist-info/top_level.txt,sha256=sjegZQO5-kQdFOXXJHm0P7Hg1Nw4Ri0WKHnRYDTsa4I,9
14
+ pypicoboot-1.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5