Erasing flash via pycom-fwtool-cli with barebones LoPy4

  • Hello all:

    I am attempting to erase the flash (and ultimately flash new firmware) to a LoPy4 that is barebones, connected to a breadboard, via the pycom-fwtool-cli tool. I currently have nothing else connected to the LoPy4 other than:

    • 5V power from external power supply
    • GND from external power supply
    • TX, RX and GND to an FTDI USB to Serial converter
    • GPIO0 (P2) connected to GND on boot (to enter bootloader mode)

    When entering bootloader mode, I get the following message:

    waiting for download

    However, when I run pycom-fwtool-cli.exe -p COM7 erase_all, I get the following output:

    Running in FTDI mode
    Erasing the board can take up to 40 seconds.
    Exception: Failed to connect to ESP32: Timed out waiting for packet header

    Is it possible to do these sort of commands without an Expansion board? I am testing this on a breadboard because I want to be able to do this on a PCB I am working on.

    I have already tested lowering the baud rate, but no luck!

    Maybe, @Gijs, could you help me out?



  • @robert-hh Thanks for the mention of the -c option! I did not know this, but it works! No more resets needed between commands.

    And yes, I understand that I do not need to erase the flash every time I load a new firmware. But my example was trying to show that any 2 commands in a row had the same behaviour, for example:

    1. Run pycom-fwtool-cli -p COM7 lpwan
      • The correct output is shown, with the SMAC, SID, PAC and LORA REGION
    2. Run pycom-fwtool-cli -p COM7 lpwan once again, without resetting LoPy
      • The same error occurs: Exception: Failed to connect to ESP32: Timed out waiting for packet header

    Now, with the -c option enabled, the procedure above works! Thanks so much!

  • @d-alvrzx You do not have to erase flash everytime you upload new firmware. Only if you think the flash is corrupted.
    Besides that there is the -c option which you could try.

  • @robert-hh Thank you! So I uncovered what might be the problem: the commands coming from pycom-fwtool-cli only work once. Say, following this procedure:

    • Connect P2 to GND while LoPy4 powered off
    • Power on LoPy4
    • Send pycom-fwtool-cli -p COM7 erase_all command
      • This command works, flash is erased in 15.98 seconds
    • Send pycom-fwtool-cli -p COM7 flash -t LoPy4-1.20.2.rc6.tar.gz to flash new firmware
      • This command does not work, throws Exception: Failed to connect to ESP32: Timed out waiting for packet header
    • Restart LoPy4 with P2 to GND
    • Try pycom-fwtool-cli -p COM7 flash -t LoPy4-1.20.2.rc6.tar.gz again
      • This command works, firmware is flashed correctly.

    So it seems I need a reset between each command? Is this how it should work?

    EDIT: And yes, I did close all other software before opening the pycom fwtool.

  • @d-alvrzx Yes, you can do that without an expansion board. Did you close all other software connected to the LoPy4 before starting pycom-fwtool-cli?
    You may also try to use itself, which is the heart of

  • If you are able to connect to the device and run code, you can run

    import os

    If fsformat() doesn't work, it's because Pycom has changed the function name several times. Also try with makefs and mkfs (with the same arguments) in case you have a lower version.

Log in to reply

Pycom on Twitter