GD32 PMU — 深度睡眠 EXTI 唤醒

GD32 GD32F30x_Firmware_Library V3.0.3 PMU 深度睡眠 EXTI 唤醒 示例教学

PMU — 深度睡眠 EXTI 唤醒

固件库: GD32F30x_Firmware_Library V3.0.3
芯片: GD32
源文件: GD32F30x_Firmware_Library_V3.0.3/Examples/PMU/Deepsleep_wakeup_exti/main.c


功能简介

本示例演示 PMU 的基本用法。

完整代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "gd32f30x.h"
#include "gd32f307c_eval.h"
#include "systick.h"
#include "main.h"

void led_config(void);

/* software delay to prevent the impact of Vcore fluctuations.
   It is strongly recommended to include it to avoid issues caused by self-removal. */
static void _soft_delay_(uint32_t time)
{
    __IO uint32_t i;
    for(i=0; i<time*10; i++){
    }
}

int main(void)
{
    /* systick configuration */
    systick_config();
    /* LED configuration */
    led_config();
    /* enable clock */
    rcu_periph_clock_enable(RCU_PMU);
    /* wakeup key configuration */
    gd_eval_key_init(KEY_WAKEUP, KEY_MODE_GPIO);
    /* tamper key EXTI configuration */
    gd_eval_key_init(KEY_TAMPER, KEY_MODE_EXTI);
    /* press wakeup key to enter deepsleep mode and use tamper key to generate a exti interrupt to wakeup mcu */
    while(1){
        if(RESET == gpio_input_bit_get(WAKEUP_KEY_GPIO_PORT, WAKEUP_KEY_PIN)){
            /* The following is to prevent Vcore fluctuations caused by frequency switching. 
               It is strongly recommended to include it to avoid issues caused by self-removal. */
            _soft_delay_(0x50);
            rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV2);
            _soft_delay_(0x50);
            rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV4);
            _soft_delay_(0x50);
            rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV8);
            _soft_delay_(0x50);
            rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV16);
            _soft_delay_(0x50);
            rcu_system_clock_source_config(RCU_CKSYSSRC_IRC8M);
            _soft_delay_(200);
            rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);

            pmu_to_deepsleepmode(PMU_LDO_LOWPOWER, PMU_LOWDRIVER_DISABLE, WFI_CMD);
        }
    }
}

void led_config(void)
{
    gd_eval_led_init(LED2);
    gd_eval_led_init(LED3);
    gd_eval_led_init(LED4);
    gd_eval_led_init(LED5);
}

代码讲解

代码结构清晰,主要包含外设初始化配置和主循环中的功能逻辑。请结合注释理解每一步的含义。

世界是你们
使用 Hugo 构建
主题 StackJimmy 设计