整体代码,首先一开始led周期为2s的闪烁到十秒之后进入slepp模式,配置为外部PA0唤醒,但是唤醒之后从头开始执行,一直在while里面循环打印,没有
没有在去启动时钟,很纳
// See LICENSE for license details.
#include
#include
#include
#include "nuclei_sdk_soc.h"
#include "nuclei_sdk_hal.h"
int set=0;
int tmp ;
int flag;
int flag_p;
/**
@brief configure the GPIO ports
@param[in] none
@param[out] none
@retval none
*/
void drv_cfg_init_gpio_led ()
{
rcu_periph_clock_enable (RCU_GPIOA);
rcu_periph_clock_enable (RCU_AF);
gpio_init (GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
}
void rtc_configuration(void)
{
rcu_periph_clock_enable(RCU_BKPI);
rcu_periph_clock_enable(RCU_PMU);
pmu_backup_write_enable();
bkp_deinit();
rcu_osci_on(RCU_LXTAL);
rcu_osci_stab_wait(RCU_LXTAL);
rcu_rtc_clock_config(RCU_RTCSRC_LXTAL);
rcu_periph_clock_enable(RCU_RTC);
rtc_register_sync_wait();
rtc_lwoff_wait();
rtc_interrupt_enable(RTC_INT_SECOND);
rtc_lwoff_wait();
rtc_prescaler_set(32767);
rtc_lwoff_wait();
}
void cfg_init_exit ()
{
//rcu_periph_clock_enable(RCU_GPIOA);
//rcu_periph_clock_enable(RCU_AF);
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_2MHZ, GPIO_PIN_0);
ECLIC_EnableIRQ(EXTI0_IRQn);
//ECLIC_Register_IRQ (EXTI0_IRQn, ECLIC_NON_VECTOR_INTERRUPT, ECLIC_NEGTIVE_EDGE_TRIGGER, 1, 2, NULL);
ECLIC_SetLevelIRQ(EXTI0_IRQn,1);
ECLIC_SetPriorityIRQ(EXTI0_IRQn,1);
gpio_exti_source_select(GPIOA, GPIO_PIN_0);
exti_init(EXTI_0, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
exti_interrupt_flag_clear(EXTI_0);
}
void time_display(uint32_t timevar)
{
uint32_t thh = 0, tmm = 0, tss = 0;
/* compute hours */
thh = timevar / 3600;
/* compute minutes */
tmm = (timevar % 3600) / 60;
/* compute seconds */
tss = (timevar % 3600) % 60;
printf(" Time: %0.2d:%0.2d:%0.2d\r\n", thh, tmm, tss);
}
void RTC_IRQHandler(void)
{
//printf("6 \n");
if(rtc_flag_get(RTC_FLAG_SECOND)!= RESET)
{
//printf("7 \n");
rtc_flag_clear(RTC_FLAG_SECOND);
tmp=rtc_counter_get();
if(set==0)
{
gpio_bit_reset (GPIOA, GPIO_PIN_1);
set=1;
flag=flag+2;
printf("flag %d \n",flag);
//printf("8 \n");
}
else
{
gpio_bit_set (GPIOA, GPIO_PIN_1);
set=0;
//printf("9 \n");
}
if(flag>=10)
{
flag_p=1;
rtc_interrupt_disable(RTC_INT_SECOND);
}
}
}
int main (void)
{
cfg_init_exit ();
flag=0;
drv_cfg_init_gpio_led ();
//printf("1 \n");
gpio_bit_set (GPIOA, GPIO_PIN_1);
//printf("2 \n");
ECLIC_Register_IRQ (RTC_IRQn, ECLIC_NON_VECTOR_INTERRUPT, ECLIC_LEVEL_TRIGGER, 1, 3, NULL);
//printf("3 \n");
rtc_configuration();
//printf("4 \n");
exti_interrupt_flag_clear (EXTI_0);
rtc_interrupt_enable(RTC_INT_SECOND);
__enable_irq ();
pmu_wakeup_pin_enable();
//printf("5 \n");
while(1)
{
time_display(tmp);
if (flag_p==1)
{
gpio_bit_set (GPIOA, GPIO_PIN_1);
rtc_interrupt_disable(RTC_INT_SECOND);
printf("sleep\n");
pmu_to_sleepmode(WFI_CMD);
exti_interrupt_flag_clear (EXTI_0); // clear EXTI lines pending flag
printf ("wake\n");
rtc_interrupt_enable(RTC_INT_SECOND);
flag=0;
}
}
}