Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions adafruit_miniesptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def flash_begin(self, *, size=0, offset=0):
number of blocks requred."""
if self._chipfamily == ESP32:
self.check_command(ESP_SPI_ATTACH, bytes([0] * 8))
# We are harcoded for 4MB flash on ESP32
# We are hardcoded for 4MB flash on ESP32
buffer = struct.pack(
"<IIIIII", 0, self._flashsize, 0x10000, 4096, 256, 0xFFFF
)
Expand All @@ -270,7 +270,7 @@ def flash_begin(self, *, size=0, offset=0):
erase_size = self.get_erase_size(offset, size)
else:
erase_size = size
timeout = 5
timeout = 13
stamp = time.monotonic()
buffer = struct.pack(
"<IIII", erase_size, num_blocks, self.FLASH_WRITE_SIZE, offset
Expand Down Expand Up @@ -303,7 +303,7 @@ def check_command(
else:
if len(data) in (2, 4):
status_len = len(data)
if len(data) < status_len:
if data is None or len(data) < status_len:
raise RuntimeError("Didn't get enough status bytes")
status = data[-status_len:]
data = data[:-status_len]
Expand Down Expand Up @@ -372,7 +372,10 @@ def get_response(self, opcode, timeout=0.1): # pylint: disable=too-many-branche
packet_length = reply[3] + (reply[4] << 8)
if len(reply) == packet_length + 10:
break
else:
# Check to see if we have a complete packet. If not, we timed out.
if len(reply) != packet_length + 10:
if self._debug:
print("Timed out after {} seconds".format(timeout))
return (None, None)
if self._debug:
print("Packet:", [hex(i) for i in reply])
Expand Down Expand Up @@ -464,7 +467,7 @@ def sync(self):
ESP ROM bootloader, we will retry a few times"""
self.reset(True)

for _ in range(3):
for _ in range(5):
if self._sync():
time.sleep(0.1)
return True
Expand Down
14 changes: 9 additions & 5 deletions examples/miniesptool_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

print("ESP32 Nina-FW")

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

uart = busio.UART(tx, rx, baudrate=115200, timeout=1)

esptool = adafruit_miniesptool.miniesptool(
uart, gpio0pin, resetpin, flashsize=4 * 1024 * 1024
uart, DigitalInOut(gpio0pin), DigitalInOut(resetpin), flashsize=4 * 1024 * 1024
)
esptool.sync()

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

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

esptool.reset()
time.sleep(0.5)