GPIO0 and GPIO2 flashing / gpio_init() mystery

Posts: 116
Joined: Mon Jun 22, 2015 5:35 am

GPIO0 and GPIO2 flashing / gpio_init() mystery

Postby blubb » Sat Oct 14, 2017 8:46 pm


for a project I am using the very simple ESP-01 modules. I use the UART for communication with another uC. This is all fine.

Now I still have two free pins: GPIO0 and GPIO2. I want to use them to display the current WiFi status. I know these pins have to be high during boot, so I wired two LEDs so that they are driven in active low:

3V3 ---> resistor ---> LED0 ---> GPIO0
3V3 ---> resistor ---> LED2 ---> GPIO2

Well, the ESP still boots fine and I can indeed use gpio_output_set() to signal the stuff I want.

However, I noticed that on every boot both LEDs flash for a short period when they should not. I can even remove all the pin related code and the flashing still happens. Why is that? I thought those pins are inputs with pullups enabled as long as the bootloader is active and they basically stay like this until I change that.

Also, my second question concerns the function gpio_init(). There are many examples which call gpio_init() in user_init(void). But there is no further explanation. It is not mentioned in the SDK manual either. What exactly is this functions purpose?

User avatar
Posts: 467
Joined: Wed Jun 29, 2016 7:17 pm
Location: India

Re: GPIO0 and GPIO2 flashing / gpio_init() mystery

Postby pratik » Tue Oct 17, 2017 11:20 pm

The gpio_init() is not required anyway, you can skip it.
And you are getting the flashes because GPIO0 outputs 40 MHz clock signal when the ESP8266 is booting. So you may have a dimly lit LED on boot.
The initial state of GPIO after booting can be set by the bootloader or "boot.bin". You can request a custom boot.bin from Espressif technical support. :)
Pratik Panda

Custom firmware, Knowledge base and freelancing (ESP8266/ESP32):

Posts: 116
Joined: Mon Jun 22, 2015 5:35 am

Re: GPIO0 and GPIO2 flashing / gpio_init() mystery

Postby blubb » Wed Oct 18, 2017 12:43 am

Thanks for your answer.

Nice to know that gpio_init() is not required. I guess this is one of the things that get copied from example to example to example without questioning its use. That always makes me suspicious. ;)

The 40 MHz signal, does it happen before the bootloader? Then a custom boot.bin would not help. What about GPIO2? Why is it flashing? And what are the initial states of the pins with the default boot.bin? Not input?

Who is online

Users browsing this forum: No registered users and 6 guests