esptool to update Wifi-NINA

Hello All,

Has anyone been successful upgrading the NINA on the MKR 4K to 1.2.1?

This is about the best I have thus far:

John@pc MINGW32 /c/esp/nina-fw
$ python /c/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port COM31 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 /c/esp/nina-fw/build/bootloader/bootloader.bin 0xf000 /c/esp/nina-fw/build/phy_init_data.bin 0x30000 /c/esp/nina-fw/build/nina-fw.bin 0x8000 /c/esp/nina-fw/build/partitions.bin
esptool.py v2.6
Serial port COM31
Connecting........__
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:86:05:d8
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 2MB
Compressed 15968 bytes to 10587...
Writing at 0x00001000... (100 %)Traceback (most recent call last):
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2959, in
_main()
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2952, in _main
main()
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2698, in main
operation_func(esp, args)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2158, in write_flash
esp.flash_defl_block(block, seq, timeout=DEFAULT_TIMEOUT * ratio * 2)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 104, in inner
return func(*args, **kwargs)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 632, in flash_defl_block
self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 354, in check_command
val, data = self.command(op, data, chk, timeout=timeout)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 322, in command
self.write(pkt)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 285, in write
self._port.write(buf)
File "C:/msys32/mingw32/lib/python2.7/site-packages/serial/serialwin32.py", line 323, in write
raise writeTimeoutError
serial.serialutil.SerialTimeoutException: Write timeout

I also had to stub out ping due to:
C:/esp/nina-fw/arduino/libraries/WiFi/src/WiFi.cpp:114:54: error: 'inet_addr_from_ipaddr' was not declared in this scope

Thanks In Advance,
John W.

OK - looks like the issue is here:

With posted workaround - I get this:

john@pc MINGW32 /c/esp/nina-fw

python /c/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port COM11 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x0 NINA_W102.bin

esptool.py v2.6
Serial port COM11
Connecting........__
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:86:05:d8
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 2MB
Compressed 1050624 bytes to 567834...
Writing at 0x00000000... (2 %)Traceback (most recent call last):
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2959, in
_main()
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2952, in _main
main()
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2698, in main
operation_func(esp, args)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2158, in write_flash
esp.flash_defl_block(block, seq, timeout=DEFAULT_TIMEOUT * ratio * 2)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 104, in inner
return func(*args, **kwargs)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 632, in flash_defl_block
self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 354, in check_command
val, data = self.command(op, data, chk, timeout=timeout)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 322, in command
self.write(pkt)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 285, in write
self._port.write(buf)
File "C:/msys32/mingw32/lib/python2.7/site-packages/serial/serialwin32.py", line 323, in write
raise writeTimeoutError
serial.serialutil.SerialTimeoutException: Write timeout

This was for the MKR 1010:

john@pc MINGW32 /c/esp/nina-fw

python /c/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port COM17 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x0 NINA_W102.bin

esptool.py v2.6
Serial port COM17
Connecting.....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 84:0d:8e:34:62:20
Uploading stub...

A fatal error occurred: Timed out waiting for packet header

ok - made sure using 3.1 IDF - getting this on MKR 1010:
john@WEI-WS2 MINGW32 /c/esp/nina-fw
$ python /c/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port COM17 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x0 NINA_W102.bin
esptool.py v2.5.0
Serial port COM17
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse
MAC: 84:0d:8e:34:62:20
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 2MB
Compressed 1001472 bytes to 538027...
Writing at 0x0003c000... (48 %)Traceback (most recent call last):
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2849, in
_main()
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2842, in _main
main()
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2594, in main
operation_func(esp, args)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 2074, in write_flash
esp.flash_defl_block(block, seq, timeout=DEFAULT_TIMEOUT * ratio)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 95, in inner
return func(*args, **kwargs)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 616, in flash_defl_block
self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 338, in check_command
val, data = self.command(op, data, chk, timeout=timeout)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 306, in command
self.write(pkt)
File "C:/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 269, in write
self._port.write(buf)
File "C:/msys32/mingw32/lib/python2.7/site-packages/serial/serialwin32.py", line 323, in write
raise writeTimeoutError
serial.serialutil.SerialTimeoutException: Write timeout

Hello Again,

Finally got back to this - and using a custom board I've made for the uBlox NINA-W102, I've been able to get this to work - the issue was GPIO0 was not being pulled down at the appropriate time.

I'm using an FTDI cable currently and have some headers on my board - one for JTAG and one for the UART programming method - here's a log:

$ python /c/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port COM7 --baud 119400 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 /c/esp/nina-fw/build/bootloader/bootloader.bin 0x30000 /c/esp/nina-fw/build/nina-fw.bin 0x8000 /c/esp/nina-fw/build/partitions.bin
esptool.py v2.6-beta1
Serial port COM7
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 3c:71:bf:cc:0e:80
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 119400
Changed.
Configuring flash size...
Auto-detected Flash size: 2MB
Compressed 14912 bytes to 9815...
Wrote 14912 bytes (9815 compressed) at 0x00001000 in 0.9 seconds (effective 139.5 kbit/s)...
Hash of data verified.
Compressed 824416 bytes to 505604...
Wrote 824416 bytes (505604 compressed) at 0x00030000 in 43.6 seconds (effective 151.4 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 120...
Wrote 3072 bytes (120 compressed) at 0x00008000 in 0.0 seconds (effective 2033.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Note the image here is the one that blinks the RGB LED - I've posted that build in other threads on this forum - also one for the MKR Vidor 4K.

I thought posting this could be useful since IMHO it's been a little difficult to discern the correct operation of GPIO0 based on other projects/posts - and of course looking in the docs at espressif helped resolve some of this.

Of course - other pins in the design need to be set properly for this to work as well - but those seem to be documented correctly.

Regards,
John

Hi John,

I'm also trying to flash with esptool, but ran into the same serial timeout exception.

I am trying to use the SerialNINAPassthrough sketch, and based on your comment about GPIO0 not being pulled down at the correct time, I changed Serial.dtr() == 1 to == 0 in this line:

FPGA.digitalWrite(FPGA_NINA_GPIO0, (Serial.dtr() == 1) ? HIGH : LOW);

and suddenly, it showed up!

esptool.py v2.8
Serial port /dev/ttyACM0
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 80:7d:3a:86:7f:78
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 119400
Changed.
Configuring flash size...
Auto-detected Flash size: 2MB
Compressed 935872 bytes to 574441...
Writing at 0x00000000... (2 %)Traceback (most recent call last):
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 3201, in <module>
    _main()
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 3194, in _main
    main()
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 2938, in main
    operation_func(esp, args)
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 2374, in write_flash
    esp.flash_defl_block(block, seq, timeout=DEFAULT_TIMEOUT * ratio * 2)
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 104, in inner
    return func(*args, **kwargs)
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 671, in flash_defl_block
    self.check_command("write compressed data to flash after seq %d" % seq,
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 369, in check_command
    val, data = self.command(op, data, chk, timeout=timeout)
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 337, in command
    self.write(pkt)
  File "/opt/esp-idf/components/esptool_py/esptool/esptool.py", line 300, in write
    self._port.write(buf)
  File "/usr/lib/python3.8/site-packages/serial/serialposix.py", line 552, in write
    raise writeTimeoutError
serial.serialutil.SerialTimeoutException: Write timeout

Unfortunately, it still times out so there's probably something else I'm missing.

Thanks,
Sameer

1 Like

In the few hours since I last posted, I managed to get it to work. Changing the dtr parameter was the right thing to do. Just needed to add an extra flag to ESPTool:

  --no-stub Disable launching the flasher stub, only talk to ROM bootloader. Some features will not be available.

Now it is directly flashing, just like the WifiNINA Firmware Updater does. It's really slow and takes 13 minutes, but it flashes:

> python /opt/esp-idf/components/esptool_py/esptool/esptool.py --no-stub --chip esp32 --port /dev/ttyACM0 --baud 119400 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x0 WiFi101-FirmwareUpdater-Plugin/firmwares/NINA/1.2.1/NINA_W102.bin
esptool.py v2.8
Serial port /dev/ttyACM0
Connecting......
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
WARNING: Detected crystal freq 38.94MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: 80:7d:3a:86:7f:78
Changing baud rate to 119400
Changed.
Enabling default SPI flash mode...
Configuring flash size...
Auto-detected Flash size: 2MB
Erasing flash...
Compressed 880640 bytes to 495730...
Took 7.46s to erase flash block
Wrote 880640 bytes (495730 compressed) at 0x00000000 in 790.6 seconds (effective 8.9 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

I could not get the version I built from the nina-fw repository to work, but flashing 1.2.1 worked perfectly. With the CheckFirmwareVersion sketch:

WiFiNINA firmware check.

Firmware version installed: 1.2.1
Latest firmware version available : 1.2.1

Check result: PASSED

I will submit a PR to fix that dts == 1 line for the SerialNINAPassthrough sketch. I think this can be marked as solved now.

Edit: the warning about the oscillator can be ignored, but I've submitted another PR to fix that.
Edit2: I have submitted a PR to speed up the flashing by a factor of 10, it is now only 47.9 seconds!

purisame:
I will submit a PR to fix that dts == 1 line for the SerialNINAPassthrough sketch.

@purisame's PR:

I have a question, you say "dts == 1", and mention dts in the commit message/PR description, but the change in the code is about Serial.dtr(). Was the mention of dts a typo, or do I just not understand the subject?

purisame:
the warning about the oscillator can be ignored, but I've submitted another PR to fix that.

purisame's PR:

purisame:
I have submitted a PR to speed up the flashing by a factor of 10, it is now only 47.9 seconds!

purisame's PR:

pert:
@purisame's PR:
Fix MKR Vidor 4000 Serial.dtr by sameer · Pull Request #109 · arduino-libraries/WiFiNINA · GitHub

I have a question, you say "dts == 1", and mention dts in the commit message/PR description, but the change in the code is about Serial.dtr(). Was the mention of dts a typo, or do I just not understand the subject?
purisame's PR:
Don't change default baud rate for MKR Vidor 4000 by sameer · Pull Request #110 · arduino-libraries/WiFiNINA · GitHub
purisame's PR:
Give SerialNINAPassthrough flash rate 10x speedup by sameer · Pull Request #112 · arduino-libraries/WiFiNINA · GitHub

Sorry for the confusion, I meant to write dtr but mixed it up with rts.

Thanks for the clarification @purisame. I was afraid there was some "dts" thing I had never heard of. Thanks also for taking the time to update your commit and pull request accordingly. As someone who spends a lot of time reading the commit histories of Arduino's repositories, I very much appreciate efforts to make them easy to understand.