Skip to content

Commit ee4026b

Browse files
committed
fix(docs): Add time measuring methods
1 parent 8f57051 commit ee4026b

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed
20.8 KB
Loading

docs/en/api-guides/deep-sleep-stub.rst

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,76 @@ Application Examples
155155
.. only:: SOC_RTC_FAST_MEM_SUPPORTED
156156

157157
- :example:`system/deep_sleep_wake_stub` demonstrates how to use the Deep-sleep wake stub on {IDF_TARGET_NAME} to quickly perform some tasks (the wake stub code) immediately after wake-up before going back to sleep.
158+
159+
Measure Time from Deep-sleep Wake-up to Wake Stub Execution
160+
-------------------------------------------------------------
161+
162+
In certain low-power scenarios, you may want to measure the time it takes for an {IDF_TARGET_NAME} chip to wake up from Deep-sleep to executing the wake stub function.
163+
164+
This section describes two methods for measuring this wake-up duration.
165+
166+
Method 1: Estimate Using CPU Cycle Count
167+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168+
169+
This method uses the CPU's internal cycle counter to estimate the wake-up time. At the beginning of the stub (with the function type of `esp_deep_sleep_wake_stub_fn_t`), the current CPU cycle count is read and converted into time based on the running CPU frequency.
170+
171+
Reference example: :example:`system/deep_sleep_wake_stub`.
172+
173+
After running the example, you will see a log similar to:
174+
175+
.. code-block:: bash
176+
177+
Enabling timer wakeup, 10s
178+
Entering deep sleep
179+
ESP-ROM:esp32c3-api1-20210207
180+
Build:Feb 7 2021
181+
rst:0x5 (DSLEEP),boot:0xc (SPI_FAST_FLASH_BOOT)
182+
wake stub: wakeup count is 1, wakeup cause is 8, wakeup cost 12734 us
183+
wake stub: going to deep sleep
184+
ESP-ROM:esp32c3-api1-20210207
185+
Build:Feb 7 2021
186+
rst:0x5 (DSLEEP),boot:0xc (SPI_FAST_FLASH_BOOT)
187+
188+
The ``wakeup cost 12734 us`` is time between Deep-sleep wake-up and wake stub execution.
189+
190+
Advantages:
191+
192+
- Requires no external hardware.
193+
- Easy to implement.
194+
195+
Limitations:
196+
197+
- The measured duration may include part of the initialization flow.
198+
- Not suitable for ultra-precise timing analysis.
199+
200+
Method 2: Use GPIO pins and Logic Analyzer
201+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
202+
203+
You can use one GPIO pin as the wake-up source and another GPIO pin to indicate when the wake stub begins execution. By observing the timing between these GPIO transitions on a logic analyzer, you can obtain an accurate measurement of the time from wake-up to stub execution.
204+
205+
For example, in the screenshot below, GPIO4 functions as the wake-up source, and GPIO5 indicates when the wake stub begins execution. The timing between the high level of GPIO4 and GPIO5 is the time from wake-up to stub execution.
206+
207+
.. figure:: ../../_static/deep-sleep-stub-logic-analyzer-result.png
208+
:align: center
209+
:alt: Time from Wake-up to Stub Execution
210+
:width: 100%
211+
212+
Time from Wake-up to Stub Execution
213+
214+
The ``2.657ms`` is time between Deep-sleep wake-up and wake stub execution.
215+
216+
Advantages:
217+
218+
- High accuracy.
219+
- Useful for validating hardware timing behavior.
220+
221+
Limitations:
222+
223+
- Requires external equipment (logic analyzer or oscilloscope).
224+
- May require test pin wiring on custom boards.
225+
226+
Recommendation
227+
^^^^^^^^^^^^^^^^
228+
229+
- For quick estimation or software-only testing, Method 1 is sufficient.
230+
- For precise validation and hardware-level timing, Method 2 is recommended.

docs/zh_CN/api-guides/deep-sleep-stub.rst

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,76 @@ Deep-sleep 唤醒存根
155155
.. only:: SOC_RTC_FAST_MEM_SUPPORTED
156156

157157
- :example:`system/deep_sleep_wake_stub` 演示如何使用 {IDF_TARGET_NAME} 上的深度睡眠唤醒存根,以便在唤醒后立即执行一些任务(唤醒存根代码),然后再返回睡眠状态。
158+
159+
测量从 Deep-sleep 唤醒到唤醒存根执行的时间
160+
---------------------------------------------------
161+
162+
在某些低功耗场景下,开发者可能希望测量 {IDF_TARGET_NAME} 芯片从 Deep-sleep 唤醒到执行唤醒存根所需的时间。
163+
164+
本节介绍了两种测量该唤醒时长的方法。
165+
166+
方法一:使用 CPU 周期计数器估算
167+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168+
169+
该方法利用 CPU 的内部周期计数器来估算唤醒时间。在存根函数(类型为 `esp_deep_sleep_wake_stub_fn_t`)的开头,读取当前的 CPU 周期计数,并根据运行的 CPU 频率将其转换为时间。
170+
171+
参考示例::example:`system/deep_sleep_wake_stub`。
172+
173+
运行示例后,你将看到类似如下的日志:
174+
175+
.. code-block:: bash
176+
177+
Enabling timer wakeup, 10s
178+
Entering deep sleep
179+
ESP-ROM:esp32c3-api1-20210207
180+
Build:Feb 7 2021
181+
rst:0x5 (DSLEEP),boot:0xc (SPI_FAST_FLASH_BOOT)
182+
wake stub: wakeup count is 1, wakeup cause is 8, wakeup cost 12734 us
183+
wake stub: going to deep sleep
184+
ESP-ROM:esp32c3-api1-20210207
185+
Build:Feb 7 2021
186+
rst:0x5 (DSLEEP),boot:0xc (SPI_FAST_FLASH_BOOT)
187+
188+
其中 ``wakeup cost 12734 us`` 表示从 Deep-sleep 唤醒到唤醒存根执行之间的时间。
189+
190+
方法一的优点:
191+
192+
- 不需要外部硬件。
193+
- 实现简单。
194+
195+
方法一的局限性:
196+
197+
- 测量的时长可能包含部分初始化流程。
198+
- 不适用于超高精度的时序分析。
199+
200+
方法二:使用 GPIO 管脚和逻辑分析仪
201+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
202+
203+
你可以使用一个 GPIO 管脚作为唤醒源,另一个 GPIO 管脚用于指示唤醒存根开始执行。通过在逻辑分析仪上观察这些 GPIO 的电平变化,可以准确测量从唤醒到存根执行的时间。
204+
205+
例如,在下图中,GPIO4 作为唤醒源,GPIO5 用于指示唤醒存根开始执行。GPIO4 和 GPIO5 的高电平之间的时长即为从唤醒到存根执行的时间。
206+
207+
.. figure:: ../../_static/deep-sleep-stub-logic-analyzer-result.png
208+
:align: center
209+
:alt: 从唤醒到存根执行的时间
210+
:width: 100%
211+
212+
从唤醒到存根执行的时间
213+
214+
其中 ``2.657ms`` 表示从 Deep-sleep 唤醒到唤醒存根执行之间的时间。
215+
216+
方法二的优点:
217+
218+
- 精度高。
219+
- 适用于验证硬件时序行为。
220+
221+
方法二的局限性:
222+
223+
- 需要外部设备(逻辑分析仪或示波器)。
224+
- 在定制板上可能需要测试引脚布线。
225+
226+
建议
227+
^^^^^^
228+
229+
- 对于快速估算或纯软件测试,方法一已足够。
230+
- 对于精确验证和硬件级时序分析,推荐使用方法二。

0 commit comments

Comments
 (0)