Skip to content

Commit c3b1489

Browse files
authored
Merge pull request #21 from tannewt/nina161
Support Nina 1.6.1 and pins from board
2 parents 30526ed + 8816081 commit c3b1489

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

adafruit_miniesptool.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def flash_begin(self, *, size=0, offset=0):
259259
number of blocks requred."""
260260
if self._chipfamily == ESP32:
261261
self.check_command(ESP_SPI_ATTACH, bytes([0] * 8))
262-
# We are harcoded for 4MB flash on ESP32
262+
# We are hardcoded for 4MB flash on ESP32
263263
buffer = struct.pack(
264264
"<IIIIII", 0, self._flashsize, 0x10000, 4096, 256, 0xFFFF
265265
)
@@ -270,7 +270,7 @@ def flash_begin(self, *, size=0, offset=0):
270270
erase_size = self.get_erase_size(offset, size)
271271
else:
272272
erase_size = size
273-
timeout = 5
273+
timeout = 13
274274
stamp = time.monotonic()
275275
buffer = struct.pack(
276276
"<IIII", erase_size, num_blocks, self.FLASH_WRITE_SIZE, offset
@@ -303,7 +303,7 @@ def check_command(
303303
else:
304304
if len(data) in (2, 4):
305305
status_len = len(data)
306-
if len(data) < status_len:
306+
if data is None or len(data) < status_len:
307307
raise RuntimeError("Didn't get enough status bytes")
308308
status = data[-status_len:]
309309
data = data[:-status_len]
@@ -372,7 +372,10 @@ def get_response(self, opcode, timeout=0.1): # pylint: disable=too-many-branche
372372
packet_length = reply[3] + (reply[4] << 8)
373373
if len(reply) == packet_length + 10:
374374
break
375-
else:
375+
# Check to see if we have a complete packet. If not, we timed out.
376+
if len(reply) != packet_length + 10:
377+
if self._debug:
378+
print("Timed out after {} seconds".format(timeout))
376379
return (None, None)
377380
if self._debug:
378381
print("Packet:", [hex(i) for i in reply])
@@ -464,7 +467,7 @@ def sync(self):
464467
ESP ROM bootloader, we will retry a few times"""
465468
self.reset(True)
466469

467-
for _ in range(3):
470+
for _ in range(5):
468471
if self._sync():
469472
time.sleep(0.1)
470473
return True

examples/miniesptool_simpletest.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77
print("ESP32 Nina-FW")
88

9-
uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=1)
10-
resetpin = DigitalInOut(board.D5)
11-
gpio0pin = DigitalInOut(board.D6)
9+
# Override these if you are manually wiring. Otherwise, this will use ESP pins from board.
10+
tx = getattr(board, "ESP_TX", board.TX)
11+
rx = getattr(board, "ESP_RX", board.RX)
12+
resetpin = getattr(board, "ESP_RESET", board.D12)
13+
gpio0pin = getattr(board, "ESP_GPIO0", board.D10)
14+
15+
uart = busio.UART(tx, rx, baudrate=115200, timeout=1)
1216

1317
esptool = adafruit_miniesptool.miniesptool(
14-
uart, gpio0pin, resetpin, flashsize=4 * 1024 * 1024
18+
uart, DigitalInOut(gpio0pin), DigitalInOut(resetpin), flashsize=4 * 1024 * 1024
1519
)
1620
esptool.sync()
1721

@@ -23,7 +27,7 @@
2327
print("MAC ADDR: ", [hex(i) for i in esptool.mac_addr])
2428

2529
# Note: Make sure to use the LATEST nina-fw binary release!
26-
esptool.flash_file("NINA_W102-1.3.1.bin", 0x0, "3f9d2765dd3b7b1eab61e1eccae73e44")
30+
esptool.flash_file("NINA_W102-1.6.1.bin", 0x0, "0326db53e579f8a4293feac70d00f6bb")
2731

2832
esptool.reset()
2933
time.sleep(0.5)

0 commit comments

Comments
 (0)