keer_zu 发表于 2025-8-14 03:22

STM32L051C8T6两个低功耗模式对比

<pre class="vditor-yml-front-matter"><code class="language-yaml">### **1. Standby Mode with RTC**

#### **进入方法**:

```c
// 配置RTC唤醒源(如周期唤醒)
HAL_RTCEx_SetWakeUpTimer_IT(&amp;hrtc, 0x1000, RTC_WAKEUPCLOCK_RTCCLK_DIV16); // 示例值

// 进入Standby模式
HAL_PWR_EnterSTANDBYMode();
```

**关键步骤**:

1. 使能RTC时钟(`__HAL_RCC_RTC_ENABLE()`)
2. 配置RTC唤醒时间(通过 `HAL_RTCEx_SetWakeUpTimer_IT()`)
3. 使能唤醒中断(`__HAL_PWR_ENABLE_IT(PWR_IT_WU)`)
4. 清除唤醒标志(`__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU)`)
5. 执行 `HAL_PWR_EnterSTANDBYMode()`

#### **功耗**:

- **典型值**:0.3 μA(VDD = 3.3V, 25°C)
- 所有时钟关闭,内核电压域断电,SRAM/寄存器内容丢失(除备份域)。

#### **唤醒源**:

- **RTC唤醒事件**(配置的定时器到期)
- **NRST引脚外部复位**
- **唤醒引脚(PA0)**(上升沿触发)

#### **唤醒后执行**:

- **系统复位**,程序从头开始执行(相当于上电复位)。
- 可通过 `PWR-&gt;CSR`检查唤醒标志(`SBF`)判断是否从Standby唤醒:
```c
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); // 清除标志
    // 执行唤醒初始化
}
```</code></pre>
<h3><strong>2. Stop Mode with RTC</strong></h3>
<h4><strong>进入方法</strong>:</h4>
<pre><code class="language-c">// 配置RTC唤醒
HAL_RTCEx_SetWakeUpTimer_IT(&amp;hrtc, 0x1000, RTC_WAKEUPCLOCK_RTCCLK_DIV16);

// 进入Stop模式
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
</code></pre>
<p><strong>关键步骤</strong>:</p>
<ol>
<li>选择稳压器模式(<code>PWR_LOWPOWERREGULATOR_ON</code> 或 <code>PWR_MAINREGULATOR_ON</code>)</li>
<li>配置RTC唤醒(同上)</li>
<li>使用 <code>WFI</code>或 <code>WFE</code>指令进入(<code>PWR_STOPENTRY_WFI/WFE</code>)</li>
</ol>
<h4><strong>功耗</strong>:</h4>
<ul>
<li><strong>低功耗稳压器开启</strong>:~1 μA(VDD=3.3V, 25°C)</li>
<li><strong>主稳压器开启</strong>:~10 μA<br />
<em>实际功耗受GPIO状态、未关闭外设影响。</em></li>
</ul>
<h4><strong>唤醒源</strong>:</h4>
<ul>
<li><strong>RTC唤醒事件</strong></li>
<li><strong>外部中断(EXTI)</strong>(如按键、传感器信号)</li>
<li><strong>LPUART/USART唤醒</strong></li>
<li><strong>LPTIM中断</strong></li>
</ul>
<h4><strong>唤醒后执行</strong>:</h4>
<ul>
<li><strong>从中断处继续执行</strong>(非复位)。</li>
<li><strong>需重新配置系统时钟</strong>(HSI默认作为系统时钟唤醒后):
<pre><code class="language-c">void SystemClock_ReConfig(void) {
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
// 重新配置HSI/MSI/PLL等
HAL_RCC_OscConfig(&amp;RCC_OscInitStruct);
HAL_RCC_ClockConfig(&amp;RCC_ClkInitStruct, FLASH_LATENCY_1);
}
</code></pre>
</li>
<li>RTC时钟无需重新配置(由备份域维持)。</li>
</ul>
<hr />
<h3><strong>关键差异总结</strong></h3>
<table>
<thead>
<tr>
<th><strong>特性</strong></th>
<th><strong>Standby Mode</strong></th>
<th><strong>Stop Mode</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>功耗</strong></td>
<td>~0.3 μA</td>
<td>~1 μA (低功耗稳压器)</td>
</tr>
<tr>
<td><strong>SRAM保持</strong></td>
<td>否</td>
<td>是</td>
</tr>
<tr>
<td><strong>唤醒后执行位置</strong></td>
<td>复位(从头开始)</td>
<td>中断处继续执行</td>
</tr>
<tr>
<td><strong>时钟恢复</strong></td>
<td>无需(复位后初始化)</td>
<td>需手动重新配置系统时钟</td>
</tr>
<tr>
<td><strong>唤醒延迟</strong></td>
<td>较长(复位流程)</td>
<td>极短(仅中断响应时间)</td>
</tr>
</tbody>
</table>
<hr />
<h3><strong>补充说明</strong></h3>
<ol>
<li>
<p><strong>RTC时钟源</strong>:</p>
<ul>
<li>使用LSE(32.768 kHz)以最小化功耗。</li>
<li>确保RTC配置正确:
<pre><code class="language-c">RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
HAL_RCCEx_PeriphCLKConfig(&amp;PeriphClkInit);
</code></pre>
</li>
</ul>
</li>
<li>
<p><strong>GPIO配置</strong>:</p>
<ul>
<li>所有未使用的GPIO应配置为模拟输入以降低功耗。</li>
<li>唤醒引脚(如PA0)需配置为 <code>GPIO_MODE_IT_RISING</code>。</li>
</ul>
</li>
<li>
<p><strong>调试影响</strong>:</p>
<ul>
<li>连接调试器时功耗会增加,实际测量需断开调试接口。</li>
</ul>
</li>
</ol>
<p>建议参考STM32L051x8数据手册(DS11195)和参考手册(RM0377)获取更详细的电气特性与寄存器配置细节。</p>
页: [1]
查看完整版本: STM32L051C8T6两个低功耗模式对比