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?
What happens to GPIO output pin during reboot?
-
- Posts: 68
- Joined: Thu Mar 18, 2021 12:23 am
Re: What happens to GPIO output pin during reboot?
Any chance you can share a snippet of your bootloader hook?
Re: What happens to GPIO output pin during reboot?
CPU reset does not affect GPIOs. See TRM 3.1.1.
-
- Posts: 1821
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: What happens to GPIO output pin during reboot?
You may want to look into gpio_hold_en() &c. to make sure nothing messes with your desired pin state.
-
- Posts: 68
- Joined: Thu Mar 18, 2021 12:23 am
Re: What happens to GPIO output pin during reboot?
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;
}
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")
-
- Posts: 68
- Joined: Thu Mar 18, 2021 12:23 am
Re: What happens to GPIO output pin during reboot?
Interesting - thanks!MicroController wrote: ↑Thu Nov 28, 2024 8:37 pmYou may want to look into gpio_hold_en() &c. to make sure nothing messes with your desired pin state.
-
- Posts: 68
- Joined: Thu Mar 18, 2021 12:23 am
Who is online
Users browsing this forum: Majestic-12 [Bot] and 86 guests