Manipulating GPIO inside Bootloader Hooks

shachar.flycatcher
Posts: 4
Joined: Mon Oct 12, 2020 7:29 am

Manipulating GPIO inside Bootloader Hooks

Postby shachar.flycatcher » Wed Feb 02, 2022 1:19 pm

Hi,
I am trying to use the Bootloader_Hooks to set a specific critical pin to output and specific level, earlier than app_main().
(Great feature BTW)
I tried to extent the example project, but I am not sure how to set this up - which Cmake changes to I need? Which functions do I use to manipulate GPIO while hooking to the bootloader? Which include files?

See below example to get an idea of what it is I am trying to achieve
(ESP IDF version ESP-IDF v5.0-dev-1426-ge899edd793 with Eclipse)

/////////////
hooks.c
/////////////
#include "esp_log.h"
????
#include "hal/gpio_hal.h"
????
.....
void bootloader_after_init(void) {
ESP_LOGI("HOOK", "This hook is called AFTER bootloader initialization");
gpio_ll_output_enable (&GPIO, GPIO_NUM_33);
gpio_ll_set_level (&GPIO, GPIO_NUM_33, 1);

}

ESP_Mahavir
Posts: 190
Joined: Wed Jan 24, 2018 6:51 am

Re: Manipulating GPIO inside Bootloader Hooks

Postby ESP_Mahavir » Wed Feb 09, 2022 10:01 am

Hello,

Please try following patch:

Code: Select all

diff --git examples/custom_bootloader/bootloader_hooks/bootloader_components/my_boot_hooks/CMakeLists.txt examples/custom_bootloader/bootloader_hooks/bootloader_components/my_boot_hooks/CMakeLists.txt
index 6aa3bbd8a9..49baa3c6f7 100644
--- examples/custom_bootloader/bootloader_hooks/bootloader_components/my_boot_hooks/CMakeLists.txt
+++ examples/custom_bootloader/bootloader_hooks/bootloader_components/my_boot_hooks/CMakeLists.txt
@@ -1,4 +1,5 @@
-idf_component_register(SRCS "hooks.c")
+idf_component_register(SRCS "hooks.c"
+                        PRIV_REQUIRES hal)
 
 # We need to force GCC to integrate this static library into the
 # bootloader link. Indeed, by default, as the hooks in the bootloader are weak,
diff --git examples/custom_bootloader/bootloader_hooks/bootloader_components/my_boot_hooks/hooks.c examples/custom_bootloader/bootloader_hooks/bootloader_components/my_boot_hooks/hooks.c
index 688a500bbe..ac4fe93782 100644
--- examples/custom_bootloader/bootloader_hooks/bootloader_components/my_boot_hooks/hooks.c
+++ examples/custom_bootloader/bootloader_hooks/bootloader_components/my_boot_hooks/hooks.c
@@ -1,4 +1,5 @@
 #include "esp_log.h"
+#include "hal/gpio_hal.h"
 
 /* Function used to tell the linker to include this file
  * with all its symbols.
@@ -16,4 +17,6 @@ void bootloader_before_init(void) {
 
 void bootloader_after_init(void) {
     ESP_LOGI("HOOK", "This hook is called AFTER bootloader initialization");
+    gpio_ll_output_enable (&GPIO, GPIO_NUM_33);
+    gpio_ll_set_level (&GPIO, GPIO_NUM_33, 1);
 }
Please refer to documentation on build system at https://docs.espressif.com/projects/esp ... ystem.html for more details.

Hope this helps!

Who is online

Users browsing this forum: Gaston1980, Majestic-12 [Bot] and 82 guests