What happens to GPIO output pin during reboot?

jcolebaker
Posts: 68
Joined: Thu Mar 18, 2021 12:23 am

What happens to GPIO output pin during reboot?

Postby jcolebaker » Wed Nov 27, 2024 6:06 pm

Hi,

We are using a ESP32 WROOM module and the design uses a "power enable" signal to keep the power supply turned on. This is wired to GPIO21 on our ESP32.

I set this pin high at start up using a bootloader hook, to make sure that the power supply stays on. It's also set high by the main firmware when it boots up. This works well.

However, I want to be sure about what happens when the ESP32 is rebooted with "esp_restart()", which triggers a reboot with the boot reason SW_CPU_RESET. If GPIO21 goes low for more than ~1.5 microseconds, the power supply will shut down and the user will need to press the power button again. This is undesirable (e.g. when installing a firmware update).

The technical reference manual says that pin GPIO21 is set up as an input after reset (oe=0, ie=0 at reset, then oe=0, ie=1). This means I would expect the pin to briefly toggle LOW when the reset happened. However, I can't see this on my scope; it seems to remain high.

In other words, it is working OK but I would like to be sure. Would the output pin be expected to reliably hold its state while the ESP32 reboots?

igormoo
Posts: 11
Joined: Thu Nov 28, 2024 12:54 am

Re: What happens to GPIO output pin during reboot?

Postby igormoo » Thu Nov 28, 2024 1:05 am

Any chance you can share a snippet of your bootloader hook?

boarchuz
Posts: 619
Joined: Tue Aug 21, 2018 5:28 am

Re: What happens to GPIO output pin during reboot?

Postby boarchuz » Thu Nov 28, 2024 5:52 am

CPU reset does not affect GPIOs. See TRM 3.1.1.

MicroController
Posts: 1821
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: What happens to GPIO output pin during reboot?

Postby MicroController » Thu Nov 28, 2024 8:37 pm

You may want to look into gpio_hold_en() &c. to make sure nothing messes with your desired pin state.

jcolebaker
Posts: 68
Joined: Thu Mar 18, 2021 12:23 am

Re: What happens to GPIO output pin during reboot?

Postby jcolebaker » Mon Dec 02, 2024 3:16 am

igormoo wrote:
Thu Nov 28, 2024 1:05 am
Any chance you can share a snippet of your bootloader hook?
Here's my bootloader hook to set GPIO 21 high at boot time.

Code: Select all

// Base address of GPIO registers:
#define GPIO_REG_BASE_ADDR 0x3FF44000

// GPIO Output Register Offsets:
#define GPIO_OUT_REG      (GPIO_REG_BASE_ADDR + 0x04)  // Write GPIO values
#define GPIO_ENABLE_REG   (GPIO_REG_BASE_ADDR + 0x20)  // Enable GPIO pins

// Bit position for GPIO 21 (POWER_HOLD):
#define GPIO21_BIT (1 << 21)


/**
 * @brief Empty function to force this file to be included by the linker.
 * The bootloader hooks are declared as "weak", so they will be ignored unless
 * "bootloader_hooks_include" is also declared.
 */
void bootloader_hooks_include(void) {}


/**
 * @brief Bootloader "Before Init" hook implementation.
 * This function will be called before the bootloader initialisation starts
 * (i.e. at the start of the 2nd stage bootloader).
 */
void bootloader_before_init(void)
{
    // Enable the GPIO pin (set it as an output):
    *(volatile uint32_t *)GPIO_ENABLE_REG |= GPIO21_BIT;

    // Set the GPIO pin high:
    *(volatile uint32_t *)GPIO_OUT_REG |= GPIO21_BIT;
}
It's pretty crude - just toggles register bits to make the pin an output and set it high. It works well, though.

This is placed in a file called bootloader_components/boot_hooks/hooks.c

The bootloader_components/boot_hooks folder also contains a CMakeLists.txt file with the following:

Code: Select all

idf_component_register(SRCS "hooks.c")

jcolebaker
Posts: 68
Joined: Thu Mar 18, 2021 12:23 am

Re: What happens to GPIO output pin during reboot?

Postby jcolebaker » Mon Dec 02, 2024 3:25 am

MicroController wrote:
Thu Nov 28, 2024 8:37 pm
You may want to look into gpio_hold_en() &c. to make sure nothing messes with your desired pin state.
Interesting - thanks!

jcolebaker
Posts: 68
Joined: Thu Mar 18, 2021 12:23 am

Re: What happens to GPIO output pin during reboot?

Postby jcolebaker » Mon Dec 02, 2024 3:26 am

boarchuz wrote:
Thu Nov 28, 2024 5:52 am
CPU reset does not affect GPIOs. See TRM 3.1.1.
Thanks - I think it's TRM section 4.1.1? (System Reset). I had missed that bit.

Who is online

Users browsing this forum: No registered users and 86 guests