How to detect, set and use BOD at runtime when using Arduino IDE for development?

dattasaurabh82
Posts: 1
Joined: Mon Dec 30, 2024 1:17 pm

How to detect, set and use BOD at runtime when using Arduino IDE for development?

Postby dattasaurabh82 » Mon Dec 30, 2024 1:39 pm

Board: ESP32-H2-mini-DevKit
Dev Env: Arduino IDE 2.3.4
ESP32 Arduino Core: 3.0.7

Code: Untitled.c Select all

#include "esp_private/brownout.h"
// #include "esp_adc/adc_cali.h"
// #include "esp_adc/adc_cali_scheme.h"

// const float BATTERY_THRESHOLD = 3.0; // Battery voltage threshold for low battery detection

void setup() {
Serial.begin(115200);

// Enable brown-out detection
esp_brownout_init();

// Get the current brown-out detection threshold
uint8_t threshold = esp_brownout_get_threshold();


// Set brown-out threshold to 2.8V
// esp_brownout_set_threshold(ESP_BROWNOUT_THRESHOLD_2_8);
}

void loop() {
}

Which gives me error:

Code: Select all


FQBN: esp32:esp32:esp32h2:EraseFlash=all
Using board 'esp32h2' from platform in folder: /Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7
Using core 'esp32' from platform in folder: /Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7

/usr/bin/env bash -c "[ ! -f \"/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a\"/partitions.csv ] || cp -f \"/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a\"/partitions.csv \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/partitions.csv"
/usr/bin/env bash -c "[ -f \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/partitions.csv ] || [ ! -f \"/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/variants/esp32h2\"/partitions.csv ] || cp \"/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/variants/esp32h2\"/partitions.csv \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/partitions.csv"
/usr/bin/env bash -c "[ -f \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/partitions.csv ] || cp \"/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7\"/tools/partitions/default.csv \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/partitions.csv"
/usr/bin/env bash -c "[ -f \"/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a\"/bootloader.bin ] && cp -f \"/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a\"/bootloader.bin \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/sketch_dec30a.ino.bootloader.bin || ( [ -f \"/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/variants/esp32h2\"/bootloader.bin ] && cp \"/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/variants/esp32h2\"/bootloader.bin \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/sketch_dec30a.ino.bootloader.bin || \"/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esptool_py/4.6\"/esptool --chip esp32h2 elf2image --flash_mode dio --flash_freq 48m --flash_size 4MB -o \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/sketch_dec30a.ino.bootloader.bin \"/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2\"/bin/bootloader_qio_64m.elf )"
esptool.py v4.6
Creating esp32h2 image...
Merged 2 ELF sections
Successfully created esp32h2 image.
/usr/bin/env bash -c "[ ! -f \"/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a\"/build_opt.h ] || cp -f \"/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a\"/build_opt.h \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/build_opt.h"
/usr/bin/env bash -c "[ -f \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/build_opt.h ] || : > \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/build_opt.h"
/usr/bin/env bash -c ": > '/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/file_opts'"
/usr/bin/env bash -c "cp -f \"/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2\"/sdkconfig \"/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC\"/sdkconfig"
Detecting libraries used...
/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp-rv32/2302/bin/riscv32-esp-elf-g++ -c @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/cpp_flags -w -Os -Werror=return-type -w -x c++ -E -CC -DF_CPU=96000000L -DARDUINO=10607 -DARDUINO_ESP32H2_DEV -DARDUINO_ARCH_ESP32 -DARDUINO_BOARD="ESP32H2_DEV" -DARDUINO_VARIANT="esp32h2" -DARDUINO_PARTITION_default -DARDUINO_HOST_OS="macosx" -DARDUINO_FQBN="esp32:esp32:esp32h2:UploadSpeed=921600,CDCOnBoot=default,FlashFreq=64,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=none,EraseFlash=all,JTAGAdapter=default,ZigbeeMode=default" -DESP32=ESP32 -DCORE_DEBUG_LEVEL=0 -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/defines -I/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a -iprefix /Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/include/ @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/includes -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/qio_qspi/include -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/cores/esp32 -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/variants/esp32h2 @/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/build_opt.h @/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/file_opts /Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/sketch/sketch_dec30a.ino.cpp -o /dev/null
Generating function prototypes...
/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp-rv32/2302/bin/riscv32-esp-elf-g++ -c @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/cpp_flags -w -Os -Werror=return-type -w -x c++ -E -CC -DF_CPU=96000000L -DARDUINO=10607 -DARDUINO_ESP32H2_DEV -DARDUINO_ARCH_ESP32 -DARDUINO_BOARD="ESP32H2_DEV" -DARDUINO_VARIANT="esp32h2" -DARDUINO_PARTITION_default -DARDUINO_HOST_OS="macosx" -DARDUINO_FQBN="esp32:esp32:esp32h2:UploadSpeed=921600,CDCOnBoot=default,FlashFreq=64,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=none,EraseFlash=all,JTAGAdapter=default,ZigbeeMode=default" -DESP32=ESP32 -DCORE_DEBUG_LEVEL=0 -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/defines -I/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a -iprefix /Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/include/ @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/includes -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/qio_qspi/include -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/cores/esp32 -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/variants/esp32h2 @/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/build_opt.h @/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/file_opts /Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/sketch/sketch_dec30a.ino.cpp -o /private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/1676748927/sketch_merged.cpp
/Users/saurabhdatta/Library/Arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/1676748927/sketch_merged.cpp
Compiling sketch...
/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp-rv32/2302/bin/riscv32-esp-elf-g++ -MMD -c @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/cpp_flags -Wall -Wextra -Os -Werror=return-type -DF_CPU=96000000L -DARDUINO=10607 -DARDUINO_ESP32H2_DEV -DARDUINO_ARCH_ESP32 "-DARDUINO_BOARD=\"ESP32H2_DEV\"" "-DARDUINO_VARIANT=\"esp32h2\"" -DARDUINO_PARTITION_default "-DARDUINO_HOST_OS=\"macosx\"" "-DARDUINO_FQBN=\"esp32:esp32:esp32h2:UploadSpeed=921600,CDCOnBoot=default,FlashFreq=64,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=none,EraseFlash=all,JTAGAdapter=default,ZigbeeMode=default\"" -DESP32=ESP32 -DCORE_DEBUG_LEVEL=0 -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/defines -I/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a -iprefix /Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/include/ @/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/flags/includes -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/qio_qspi/include -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/cores/esp32 -I/Users/saurabhdatta/Library/Arduino15/packages/esp32/hardware/esp32/3.0.7/variants/esp32h2 @/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/build_opt.h @/Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/file_opts /Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/sketch/sketch_dec30a.ino.cpp -o /Users/saurabhdatta/Library/Caches/arduino/sketches/EC3DE553062F99E740470A5FD38B8EBC/sketch/sketch_dec30a.ino.cpp.o
/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a/sketch_dec30a.ino: In function 'void setup()':
/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a/sketch_dec30a.ino:14:23: error: 'esp_brownout_get_threshold' was not declared in this scope; did you mean 'esprv_intc_int_set_threshold'?
   14 |   uint8_t threshold = esp_brownout_get_threshold();
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                       esprv_intc_int_set_threshold
/private/var/folders/dc/34bnwlzn445813wfqdxjpvxc0000gn/T/.arduinoIDE-unsaved20241130-62534-11j2tre.d4sg/sketch_dec30a/sketch_dec30a.ino:14:11: warning: unused variable 'threshold' [-Wunused-variable]
   14 |   uint8_t threshold = esp_brownout_get_threshold();
      |           ^~~~~~~~~

exit status 1

Compilation error: 'esp_brownout_get_threshold' was not declared in this scope; did you mean 'esprv_intc_int_set_threshold'?
So I checked few files:

Code: Select all

./esp/v5.3.2/esp-idf/components/esp_system/port/include/private/esp_private/brownout.h
./esp/esp-idf/components/esp_system/port/include/private/esp_private/brownout.h
./Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-632e0c2a/esp32h2/include/esp_system/port/include/private/esp_private/brownout.h
And in most of them I found:

[Codebox=c file=esp_private/brownout.h]/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/


#ifndef __ESP_BROWNOUT_H
#define __ESP_BROWNOUT_H

#ifdef __cplusplus
extern "C" {
#endif

void esp_brownout_init(void);

void esp_brownout_disable(void);

#ifdef __cplusplus
}
#endif

#endif[/Codebox]

So, basically no way to adjust/detect BOD from Arduino IDE?
Only by ESP-IDF during project setup?

RandomInternetGuy
Posts: 81
Joined: Fri Aug 11, 2023 4:56 am

Re: How to detect, set and use BOD at runtime when using Arduino IDE for development?

Postby RandomInternetGuy » Wed Feb 26, 2025 6:07 am

I don't see the symbol esp_brownout_get_threshold anywhere in the ESP-IDF documentation for any version online, nor can I find it in the ESP-IDF source tree So I don't know what documentation you are finding that's setting an expectation that it's callable, but that doesn't seem to be the case.


Now if this is something that used to work and doesn't now, there's no expectation that symbols provided in private namespaces
#include "esp_private/brownout.h"
are stable across ESP-IDF releases. You shouldn't rely on them. That's why they're in esp_private.

HOWEVER, it if were old, I'd expect to find traces of it in old code or via search:

https://www.google.com/search?q=%22esp_ ... reshold%22


As of this moment, the only page on the entire internet that Google has indexed that has that symbol, is this one:

Image

Was this a legitimate help request where you have a valid reason to expect that code has ever worked or did you just send a fellow enthusiast on a goose chase, perhaps from some AI-induced code binge?
Attachments
Screenshot 2025-02-25 at 11.59.47 PM.png
Screenshot 2025-02-25 at 11.59.47 PM.png (189.17 KiB) Viewed 15465 times

Who is online

Users browsing this forum: No registered users and 1 guest