stuck in endless deep sleep loop, unable to access serial or reflash firmware



  • I have copied the Quick Usage Example of sleep onto a Lopy on a PySense (connected power and comms via serial through USB cable) and restarted the board.
    Unfortunately as the sample code runs deepsleep, I have immediately lost access to the serial comms. I am now of course also unable to access the Lopy serial comms (via USB) to stop the endless loop by Ctrl-C...
    Having tried various approaches (Atom Pymakr addin cannot open port, neither can screen, Rshell etc)

    I have given up, and have now been trying to just reflash the firmware.

    However, I cannot even do this as the firmware update tool will not connect to the serial port (while it runs the endless loop...)

    Help! How can I access the board/stop the program/reflash the firmware?

    Another point is how on earth was the Quick Usage Example of sleep expected to work? How was the user expected to access serial comms and read the print statements once the loop ran its first deepsleep and wake loop?

    would appreciate any help on this as I am completely stuck...!



  • @xykon thanks for this note.
    In this case I didn't need to reflash the firmware, however I will remember your advice as I am sure to need it soon enough!



  • thanks @robert-hh I had completely forgotten the safe boot option. This allowed me to get a serial connection, then amend the code.
    I will put in a check, to allow the user to push the Pysense user button, to not enter the loop, which should solve the problem.

    Another (better) option would be for the ESP32 to confirm if the USB is connected (UART0 uart.any=1 ??) before entering the loop. However I am not sure if you can create uart objects on uart0 bus, like the following. Is there a more elegant way of doing this?

    from machine import UART
    uart=UART(0, 115200)
    if uart.any>0:
        ## leave the main loop
    else:
        continue #on with the main loop
    

  • administrators

    @philwilkinson Can you please try the following?

    Plug the Pysense into your computer without the module. Run the firmware updater until you get to the Communication page where you select the serial port. Make sure the correct port is selected. Now select "Erase flash file system" but do not click "Continue" yet.

    Next unplug the Pysense, mount the module (make sure it's aligned correctly), and plug in the USB cable while pressing the reset button next to the RGB LED on the LoPy. Keep pressing the reset button until you select "Continue" in the firmware update tool and you see the message "Please wait, reading information about the board". Now release the reset button and the firmware updater should flash the board and erase all your scripts at the same time. It might take two or three attempts.



  • @philwilkinson What happens if you do a safe boot? Tie P12 to 3.3V and reset the device. During a safe boot, boot.py and main.py are ignored.



  • thanks for responding @Xykon
    Yes, the Pysense firmware is up to date.
    Yes, I used the firmware updater a few hours ago to update the LoPy firmware. It ran fine
    Yes, the firmware updater tool does see the port (dev/ttyACM0) when the module is removed.

    I should also have mentioned that the module appears to be running the Quick usage example of sleep OK too. I know this as when I shake the accelerometer there is a slight delay then a red LED flash.


  • administrators

    @philwilkinson Did you update the firmware of the Pysense before trying the firmware updater? Have you been able to use the firmware updater before uploading the problematic code?

    Is the com port visible if you plug in the Pysense without any module?


 

Pycom on Twitter