Skip to content

Commit 3e75756

Browse files
committed
Merge branch 'feat/add_vbat_doc' into 'master'
feat: add esp32p4 vbat solution doc Closes AEG-2021 See merge request ae_group/esp-iot-solution!1116
2 parents 5b46b36 + 7223272 commit 3e75756

File tree

8 files changed

+518
-2
lines changed

8 files changed

+518
-2
lines changed
62 KB
Loading
66.5 KB
Loading

docs/en/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ ESP-IoT-Solution contains device drivers and code frameworks for the development
7676
AI <ai/index>
7777
Input Device <input_device/index>
7878
IR <ir/index>
79+
Low Power Solution <low_power_solution/index>
7980
Sensors <sensors/index>
8081
Touch <touch/index>
8182
Storage <storage/index>
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
ESP32-P4 Battery Backup Solution
2+
==================================
3+
4+
:link_to_translation:`zh_CN:[中文]`
5+
6+
The ESP32-P4 integrates RTC (Real-Time Clock) functionality, which includes a battery backup (VBAT), an external 32.768kHz crystal oscillator input, and power switching control, allowing it to maintain accurate time even when the main power is disconnected.
7+
8+
.. warning:: ESP-IDF does not fully support the VBAT scheme yet, and the current scheme is for testing purposes only. Please follow the process below to modify the ESP-IDF driver on the master branch.
9+
10+
**Supports the following features**:
11+
12+
- Supports timekeeping functionality during main power loss, with backup power supplied by the battery backup (VBAT) after power failure.
13+
- Supports automatic power source switching by the PMU (Power Management Unit) during sleep/wake states.
14+
- Supports battery backup voltage detection with threshold alarms.
15+
- Supports charging of the battery backup; when VDDA is present, the battery backup (VBAT) can be charged through an internal resistor.
16+
17+
.. figure:: ../../_static/low_power/p4_vbat_frame.png
18+
:align: center
19+
:scale: 70%
20+
21+
ESP32-P4 Backup Battery Connection Diagram
22+
23+
Battery Connection and Circuit Protection
24+
---------------------------------------------
25+
26+
The connection of the ESP32-P4 backup battery is very simple. The VBAT pin has an integrated charging protection circuit, so no external resistors or diodes are required, effectively reducing the harmful risks associated with adding components in the backup battery path.
27+
28+
.. figure:: ../../_static/low_power/p4_power_switch.png
29+
:align: center
30+
:scale: 80%
31+
32+
ESP32-P4 Battery Switch Control Block Diagram
33+
34+
Selection of Battery Backup
35+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
37+
- Low Self-Discharge Rate: The battery should have excellent leakage resistance.
38+
- Charge and Discharge Performance: Batteries with a higher charge/discharge cycle count can extend the product's lifespan.
39+
- Discharge Current: The VBAT supply consumes very little power (a few microamperes), so most batteries' discharge capabilities will be sufficient.
40+
- Charging Current: VDDA supports charging the backup battery on VBAT. The charging current limit resistor can be configured by software, ranging from 1kΩ to 9kΩ.
41+
42+
.. warning:: It is strictly prohibited to connect a 3.6V rechargeable battery, as the voltage of a fully charged 3.6V battery can reach around 4V. Since the input voltage range for the VBAT pin is 2.3V ~ 3.6V, this could potentially damage the VBAT pin.
43+
44+
Decoupling Capacitor on the Battery
45+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
47+
In circuit design, users typically add a decoupling capacitor for each power supply pin. However, when VBAT is used as a backup power input, leakage on the capacitor will significantly shorten the battery life. Moreover, since the battery itself has good capacitive characteristics, no external decoupling capacitor is needed.
48+
49+
.. note:: D1 and R1 are ESD protection components, and Rx is the charging protection resistor, limiting the charging current to below 1 mA. The protection circuit meets UL certification testing requirements.
50+
51+
Power Switching
52+
-----------------
53+
54+
The power selection between VBAT and VDDA is automatically controlled by the PMU during sleep and wake states, or can be manually selected. Users need to configure the registers in advance. When the chip is in sleep mode, VDDA or VBAT can be configured as the power input.
55+
56+
- PMU_HP_SLEEP_VDDBAT_MODE: Selects the power supply during the HP_SLEEP state. 0: VDDA power supply, 1: VBAT power supply, 2: Auto selection.
57+
- PMU_VDDBAT_SW_UPDATE: Set to 1 to make the configuration in the ``PMU_VDDBAT_CFG_REG`` register effective.
58+
- PMU_LP_ANA_WAIT_TARGET: Sets the delay time during the wake-up process. The duration should be longer than the power-up stabilization time of the external VDDA power supply.
59+
60+
.. note:: Currently, ESP-IDF does not fully support the PMU driver. If you need to test the VBAT functionality, please follow the testing procedure below to add the necessary code in ESP-IDF.
61+
62+
The testing procedure is as follows:
63+
64+
1. Add the necessary header files in ``components/esp_hw_support/port/esp32p4/pmu_sleep.c``
65+
66+
.. code:: c
67+
68+
#include "soc/pmu_reg.h"
69+
#include "soc/lp_analog_peri_reg.h"
70+
#include "soc/lp_gpio_struct.h"
71+
#include "esp_private/regi2c_ctrl.h"
72+
#include "soc/lp_analog_peri_reg.h"
73+
#include "soc/lp_analog_peri_struct.h"
74+
#include "esp_private/regi2c_ctrl.h"
75+
#include "soc/regi2c_bias.h"
76+
77+
78+
2. Add the following code above ``pmu_ll_hp_set_sleep_enable(PMU_instance()->hal->dev);`` in the ``pmu_sleep_start`` function in ``components/esp_hw_support/port/esp32p4/pmu_sleep.c``:
79+
80+
Method 1: Automatic Switching Between VDDA and VBAT:
81+
82+
.. code:: c
83+
84+
#define VBAT_MODE_VDDA 0
85+
#define VBAT_MODE_VBAT 1
86+
#define VBAT_MODE_AUTO 2
87+
88+
REG_SET_FIELD(PMU_HP_SLEEP_LP_DIG_POWER_REG, PMU_HP_SLEEP_VDDBAT_MODE, VBAT_MODE_AUTO);
89+
REG_SET_BIT(PMU_VDDBAT_CFG_REG, PMU_VDDBAT_SW_UPDATE);
90+
while(VBAT_MODE_AUTO != REG_GET_FIELD(PMU_VDDBAT_CFG_REG, PMU_ANA_VDDBAT_MODE));
91+
92+
93+
Method 2: Manual Configuration of VDDA and VBAT:
94+
95+
.. code:: c
96+
97+
#define VBAT_MODE_VDDA 0
98+
#define VBAT_MODE_VBAT 1
99+
#define VBAT_MODE_AUTO 2
100+
101+
REG_SET_FIELD(PMU_HP_SLEEP_LP_DIG_POWER_REG, PMU_HP_SLEEP_VDDBAT_MODE, VBAT_MODE_VDDA);
102+
REG_SET_BIT(PMU_VDDBAT_CFG_REG, PMU_VDDBAT_SW_UPDATE);
103+
while(VBAT_MODE_VDDA != REG_GET_FIELD(PMU_VDDBAT_CFG_REG, PMU_ANA_VDDBAT_MODE));
104+
REG_SET_FIELD(PMU_LP_SLEEP_LP_DIG_POWER_REG, PMU_LP_SLEEP_VDDBAT_MODE, VBAT_MODE_VBAT);
105+
REG_SET_FIELD(PMU_SLP_WAKEUP_CNTL5_REG, PMU_LP_ANA_WAIT_TARGET, 0xFF);
106+
107+
.. note:: After testing, the average VBAT current in deep sleep is 7 µA, and the average VBAT current in light sleep is 21 µA.
108+
109+
Backup Battery Runtime
110+
^^^^^^^^^^^^^^^^^^^^^^^^
111+
112+
Taking the CR2032 battery (225 mAh) as an example, the theoretical standby time in deep sleep is 3.669 years.
113+
114+
Brown-out Detector & BOD filter
115+
-----------------------------------
116+
117+
The Brown-out Detector of the ESP32-P4 supports monitoring the voltage of VDDA and VBAT. It triggers a signal when the voltage rapidly drops below a preset threshold and performs the corresponding actions.
118+
119+
Threshold Configuration and Voltage Relationship:
120+
121+
+-------------------------+---------+
122+
| Threshold Configuration | Voltage |
123+
+=========================+=========+
124+
| 0 | 2.52v |
125+
+-------------------------+---------+
126+
| 1 | 2.57v |
127+
+-------------------------+---------+
128+
| 2 | 2.63v |
129+
+-------------------------+---------+
130+
| 3 | 2.68v |
131+
+-------------------------+---------+
132+
| 4 | 2.74v |
133+
+-------------------------+---------+
134+
| 5 | 2.78v |
135+
+-------------------------+---------+
136+
| 6 | 2.83v |
137+
+-------------------------+---------+
138+
| 7 | 2.89v |
139+
+-------------------------+---------+
140+
141+
Create a new test project and add the following code to check the undervoltage flag:
142+
143+
.. code:: c
144+
145+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFL_VDDA, 6);
146+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFH_VDDA, 7); // Vdda comparator voltage threshold set to 2.83 - 2.89
147+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFL_VBAT, 6);
148+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFH_VBAT, 7); // Vbat comparator voltage threshold set to 2.83 - 2.89
149+
150+
REG_SET_FIELD(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_UNDERVOLTAGE_TARGET, 20);
151+
REG_SET_FIELD(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_UPVOLTAGE_TARGET, 10); // Set the time threshold for the BOD filter, in 20 MHz cycles.
152+
REG_SET_BIT(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_CNT_CLR);
153+
esp_rom_delay_us(30);
154+
REG_CLR_BIT(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_CNT_CLR);
155+
156+
while (1)
157+
{
158+
printf("value:%lx\n", REG_READ(LP_ANALOG_PERI_VDD_SOURCE_CNTL_REG));
159+
REG_WRITE(LP_ANALOG_PERI_VDD_SOURCE_CNTL_REG, 0X30020000); // clear VBAT flag
160+
REG_WRITE(LP_ANALOG_PERI_VDD_SOURCE_CNTL_REG, 0X30040000); // clear VDDA flag
161+
vTaskDelay(500 / portTICK_PERIOD_MS);
162+
}
163+
164+
165+
Battery Charging Circuit
166+
-------------------------------
167+
168+
When a rechargeable battery is selected as the VBAT power input, the chip supports detecting the battery voltage and, when it falls below the set threshold, it charges the VBAT-side battery through VDDA in reverse.
169+
170+
Threshold Configuration and Voltage Relationship:
171+
172+
+-------------------------+---------+
173+
| Threshold Configuration | Voltage |
174+
+=========================+=========+
175+
| 0 | 2.52v |
176+
+-------------------------+---------+
177+
| 1 | 2.57v |
178+
+-------------------------+---------+
179+
| 2 | 2.63v |
180+
+-------------------------+---------+
181+
| 3 | 2.68v |
182+
+-------------------------+---------+
183+
| 4 | 2.74v |
184+
+-------------------------+---------+
185+
| 5 | 2.78v |
186+
+-------------------------+---------+
187+
| 6 | 2.83v |
188+
+-------------------------+---------+
189+
| 7 | 2.89v |
190+
+-------------------------+---------+
191+
192+
Create a new test project and add the following code to check the undervoltage flag:
193+
194+
.. code:: c
195+
196+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFL_VDDA, 6);
197+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFH_VDDA, 7); // Vdda comparator voltage threshold set to 2.83 - 2.89
198+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFL_VBAT, 6);
199+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFH_VBAT, 7); // Vbat comparator voltage threshold set to 2.83 - 2.89
200+
201+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFL_VBAT_CHARGER, 6);
202+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_DREFH_VBAT_CHARGER, 7); // Charging detection comparator threshold setting.
203+
REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_OR_FORCE_PU_VBAT_CHARGER, 1); // Force power-on of the vbat_charger comparator.
204+
205+
REG_SET_FIELD(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_UNDERVOLTAGE_TARGET, 20);
206+
REG_SET_FIELD(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_UPVOLTAGE_TARGET, 10); // Set the time threshold for the BOD filter, in 20 MHz cycles.
207+
REG_SET_BIT(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_CNT_CLR);
208+
esp_rom_delay_us(30);
209+
REG_CLR_BIT(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_CNT_CLR);
210+
211+
while(1)
212+
{
213+
printf("value:%lx\n", REG_GET_BIT(LP_ANALOG_PERI_VDDBAT_CHARGE_CNTL_REG, LP_ANALOG_PERI_VDDBAT_CHARGE_UNDERVOLTAGE_FLAG)); // Get VBAT pin charge flag
214+
vTaskDelay(500 / portTICK_PERIOD_MS);
215+
}
216+
217+
218+
219+
Peripheral Support in VBAT Power Supply Scenario
220+
---------------------------------------------------
221+
222+
RTC TIMER
223+
^^^^^^^^^^^^
224+
225+
After switching to VBAT power supply when entering sleep mode, the RTC TIMER continues to count normally after VDDA is powered off. After restarting, the time display is normal. The test code is as follows:
226+
227+
.. code:: c
228+
229+
time_t now;
230+
char strftime_buf[64];
231+
struct tm timeinfo;
232+
time(&now);
233+
localtime_r(&now, &timeinfo);
234+
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
235+
printf( "The current date/time is: %s\n", strftime_buf);
236+
237+
const gpio_config_t config = {
238+
.pin_bit_mask = BIT(GPIO_NUM_0),
239+
.mode = GPIO_MODE_INPUT,
240+
};
241+
242+
ESP_ERROR_CHECK(gpio_config(&config));
243+
esp_deep_sleep_enable_gpio_wakeup(BIT(GPIO_NUM_0), 0);
244+
245+
esp_deep_sleep_start();
246+
247+
.. note:: You need to add the power switching code in ESP-IDF according to the above 'Power Switching' section. Meanwhile, the test process involved waiting for a period after VDDA power-off, then powering it back on, and using GPIO0 to wake up the ESP32-P4, comparing the time difference before and after sleep.
248+
249+
250+
LP GPIO/ADC/UART Peripheral
251+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
252+
253+
Please refer to the test driver in ``examples/system/ulp/lp_core`` in ESP-IDF for testing. The current GPIO/ADC/UART test already support ESP32-P4.

docs/en/low_power_solution/index.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Low-Power solution
88
.. toctree::
99
:maxdepth: 1
1010

11+
ESP32-P4 battery backup solution <esp32p4_vbat>
12+
13+
..
1114
deepsleep current test <deep-sleep_current_test>
1215
esp32 lowpower solution <esp32_lowpower_solution>
13-
ULP Co-processor and Assembly Environment Setup <esp32_ulp_co-processor_and_assembly_environment_setup>
16+
ULP Co-processor and Assembly Environment Setup <esp32_ulp_co-processor_and_assembly_environment_setup>
17+
..

docs/zh_CN/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ ESP-IoT-Solution 包含物联网系统开发中常用的外设驱动和代码框
7676
人工智能 <ai/index>
7777
输入设备 <input_device/index>
7878
红外 <ir/index>
79+
低功耗方案 <low_power_solution/index>
7980
传感器集 <sensors/index>
8081
触摸传感器 <touch/index>
8182
存储方案 <storage/index>

0 commit comments

Comments
 (0)