#include"gd32f30x.h"#include"gd32f307c_eval.h"#define BKP_DATA_REG_NUM 42
voidled_config(void);voidnvic_config(void);voidwrite_backup_register(uint16_tdata);uint32_tcheck_backup_register(uint16_tdata);/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/intmain(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){}}voidled_config(void){gd_eval_led_init(LED2);gd_eval_led_init(LED3);gd_eval_led_init(LED4);gd_eval_led_init(LED5);}voidnvic_config(void){nvic_irq_enable(TAMPER_IRQn,0,0);}