MicroPython Startup Time

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
paulg
Posts: 29
Joined: Fri Oct 23, 2015 1:06 pm

MicroPython Startup Time

Post by paulg » Tue Dec 10, 2019 5:50 pm

I have been doing some timing measurements on an ESP32 MicroPython application that spends most of the time in deep sleep. The board (a TinyPICO) takes 1.67 seconds to reach main.py from wakeup. Does this sound reasonable given that MicroPython boots to essentially the same place in 150 microseconds on a Pyboard? Why the big difference?

Christian Walther
Posts: 169
Joined: Fri Aug 19, 2016 11:55 am

Re: MicroPython Startup Time

Post by Christian Walther » Tue Dec 10, 2019 6:28 pm

This has been discussed on Discord:
https://discordapp.com/channels/6056217 ... 8651969537
https://discordapp.com/channels/6056217 ... 3429890058
UnexpectedMaker wrote:Time to boot the TinyPICO and get into MicroPython is hampered by the RAM test that the IDF does on the extra PSRAM during init - That can be turned off, but requires you to make a custom MicroPython firmware.

paulg
Posts: 29
Joined: Fri Oct 23, 2015 1:06 pm

Re: MicroPython Startup Time

Post by paulg » Tue Dec 10, 2019 8:07 pm

@Christian, thanks for the links. I was not aware of those discussions.

My application is a small one and I don't think I need the PSRAM. I will try a non-SPIRAM ESP32 firmware and see if that improves matters.

Paul

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: MicroPython Startup Time

Post by mattyt » Tue Dec 10, 2019 10:31 pm

Hey Paul, please report back - I'd be curious to know what the startup time is on an ESP32 w/o PSRAM. Thanks!

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython Startup Time

Post by Roberthh » Wed Dec 11, 2019 7:53 am

MicroPython boots to essentially the same place in 150 microseconds on a Pyboard?
Pyboard is fast but maybe not that fast. Could it be 150 ms?

paulg
Posts: 29
Joined: Fri Oct 23, 2015 1:06 pm

Re: MicroPython Startup Time

Post by paulg » Wed Dec 11, 2019 10:29 am

Hi guys,

I flashed the generic non-spiram esp32 firmware (esp32-idf3-20190529-v1.11.bin) into my TinyPICO, reloaded the app files and repeated the test. The time from wakeup to reaching main.py is now 612ms. That is over 1 second faster than before.

For completeness I should say that my application is a battery powered remote sensor. It is woken up by a button press. It connects to Wi-Fi, gets the time from the network, reads the sensor, briefly displays the reading on an OLED display and then goes back to deep sleep. The application will also transmit the readings to a host, but I haven't coded that bit yet. I am measuring the run time with led2.on() at the start of main.py and led2.off() immediately before calling deepsleep.

I am measuring the startup time using a digital scope. One channel is connected to the button GPIO, the other to led2 GPIO. The scope is triggered by a falling edge on the button input and is in single sweep mode. I am using the cursors to measure the time delay between the falling edge of the button input and the rising edge of led2 output.

With normal python files, the run takes 4.94 seconds. I switched to using pre-compiled bytecode and that shaved 400 milliseconds off the run time.

The startup time saving is significant. It will extend the battery life by around 3 days.

@Roberthh, the following statement is taken from the home page of micropython.org. I have no reason to believe it's not true.

fast start-up time from boot to loading of first script (150 microseconds to get to boot.py, on PYBv1.1 running at 168MHz)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: MicroPython Startup Time

Post by pythoncoder » Wed Dec 11, 2019 6:15 pm

You may find that using frozen bytecode saves a bit more time by removing the need to access the filesystem.
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython Startup Time

Post by Roberthh » Wed Dec 11, 2019 7:07 pm

fast start-up time from boot to loading of first script (150 microseconds to get to boot.py, on PYBv1.1 running at 168MHz)
I made a little test, adding a pin toggle statement just at the start of boot.py. The code consist of:

Code: Select all

from machine import Pin
p=Pin("X9", Pin.OUT, value=1)
p(0)
p(1)
Time from trailing edge of the reset signal to that pulse ~8.4ms. I consider that fast, compared to the seconds time needed by the ESP32. But it's just a little bit longer than 150µs. Pyboard 1.1 @ 168MHz

paulg
Posts: 29
Joined: Fri Oct 23, 2015 1:06 pm

Re: MicroPython Startup Time

Post by paulg » Wed Dec 11, 2019 9:11 pm

@Roberthh which board did you use for your test?

I agree with you that 8.4ms is a very respectable result.

So where did the 150us come from? Could it be that Damien made a mistake and nobody thought to question it or double check it?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython Startup Time

Post by Roberthh » Wed Dec 11, 2019 9:28 pm

As told: Pyboard V1.1 @ 168MHz

Post Reply