GD32 PMU — 待机 WKUP 唤醒

GD32 GD32F30x_Firmware_Library V3.0.3 PMU 待机 WKUP 唤醒 示例教学

PMU — 待机 WKUP 唤醒

固件库: GD32F30x_Firmware_Library V3.0.3
芯片: GD32
源文件: GD32F30x_Firmware_Library_V3.0.3/Examples/PMU/Standby_wakeup_pin/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
59
#include "gd32f30x.h"
#include <stdio.h>
#include "gd32f307c_eval.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)
{
    /* enable clock */
    rcu_periph_clock_enable(RCU_PMU);
    /* LED configuration and turn on all LEDs */
    led_config();
    gd_eval_led_on(LED2);
    gd_eval_led_on(LED4);
    gd_eval_led_on(LED3);
    gd_eval_led_on(LED5);
    /* tamper key configuration */
    gd_eval_key_init(KEY_TAMPER, KEY_MODE_GPIO);
    /* enable wakeup pin */
    pmu_wakeup_pin_enable();
    /* press tamper key to enter standby mode and use wakeup key to wakeup mcu */
    while(1) {
        if(RESET == gpio_input_bit_get(TAMPER_KEY_GPIO_PORT, TAMPER_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_standbymode();
        }
    }
}

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 设计