GD32 BKP — 入侵检测

GD32 GD32F30x_Firmware_Library V3.0.3 BKP 入侵检测 示例教学

BKP — 入侵检测

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


功能简介

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

完整代码

 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
64
65
66
67
68
69
70
71
#include "gd32f30x.h"
#include "gd32f307c_eval.h"
#define BKP_DATA_REG_NUM              42

void led_config(void);
void nvic_config(void);
void write_backup_register(uint16_t data);
uint32_t check_backup_register(uint16_t data);
    
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    /* led configuration and turn on all led */
    led_config();
    /* NVIC configuration */
    nvic_config();
    /* PMU lock enable */
    rcu_periph_clock_enable(RCU_PMU);
    /* BKP clock enable */
    rcu_periph_clock_enable(RCU_BKPI);
    
    /* enable write access to the registers in backup domain */
    pmu_backup_write_enable();
    /* confirm RCU_BDCTL_BKPRST bit is reset */
    if(RESET != (RCU_BDCTL & RCU_BDCTL_BKPRST)){
        rcu_bkp_reset_disable();
    }
    /* tamper pin active level set */
    bkp_tamper_active_level_set(TAMPER_PIN_ACTIVE_LOW);
    /* tamper detection disable  */
    bkp_tamper_detection_disable();
    /* disable the tamper interrupt */
    bkp_tamper_interrupt_disable();
    /* clear the bit flag of tamper event */
    bkp_flag_clear(BKP_FLAG_TAMPER);
    /* configure the tamper pin active on low level, and enable the tamper pin */
    bkp_tamper_interrupt_enable();
    /* tamper detection enable  */
    bkp_tamper_detection_enable();
    /* write data to backup DATAx registers */
    write_backup_register(0x1226);
  
    /* check if the written data are correct */
    if(0x00 == check_backup_register(0x1226)){
        /* turn on LED2 */
        gd_eval_led_on(LED2);
    }else{
        /* turn on LED3 */
        gd_eval_led_on(LED3);
    }
    while(1){
    }
}

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

void nvic_config(void)
{
    nvic_irq_enable(TAMPER_IRQn,0,0);
}

代码讲解

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

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