GD32 PMU — 深度睡眠 RTC 唤醒

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

PMU — 深度睡眠 RTC 唤醒

固件库: GD32F30x_Firmware_Library V3.0.3
芯片: GD32
源文件: GD32F30x_Firmware_Library_V3.0.3/Examples/PMU/Deepsleep_wakeup_RTC/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
60
61
62
63
#include "gd32f30x.h"
#include "gd32f307c_eval.h"
#include "systick.h"
#include "main.h"

void led_config(void);
void nvic_configuration(void);
void rtc_configuration(void);
void fwdgt_configuration(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)
{
    /* nvic configuration */
    nvic_configuration();
    /* LED configuration */
    led_config();
    /* systick configuration */
    systick_config();
    gd_eval_led_on(LED5);
    delay_1ms(2000U);
    gd_eval_led_off(LED5);
    /* RTC configuration */
    rtc_configuration();
    /* FWDGT configuration */
    fwdgt_configuration();

    while(1){
        delay_1ms(50U);
        /* 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 enters deepsleep mode */
        pmu_to_deepsleepmode(PMU_LDO_LOWPOWER, PMU_LOWDRIVER_DISABLE, WFI_CMD);
        gd_eval_led_toggle(LED2);
    }
}

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

代码讲解

中断优先级配置:NVIC 设置中断的抢占优先级和子优先级。数字越小优先级越高。

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