主要代码:int main(void)
{
systick_config();
rcu_periph_clock_enable(RCU_GPIOA);
gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_8);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_8 );
/* reset LED GPIO pin */
gpio_bit_reset(GPIOA, GPIO_PIN_8);
rcu_periph_clock_enable(RCU_SYSCFG);
/* USART configuration the CK_IRC16M as USART clock */
rcu_usart_clock_config(IDX_USART1, RCU_USARTSRC_IRC16MDIV);
gd_eval_com_init(EVAL_COM);
nvic_irq_enable(USART1_WKUP_IRQn, 0);
/* USART1 Wakeup EXTI line configuretion */
exti_init(EXTI_26, EXTI_INTERRUPT, EXTI_TRIG_RISING);//EXTI_26 USART1唤醒
delay_1ms(5000);//5S后进入低功耗
/* use start bit wakeup MCU */
usart_wakeup_mode_config(EVAL_COM, USART_WUM_STARTB);
/* enable USART */
usart_enable(EVAL_COM);
/* ensure USART is enabled */
while(RESET == usart_flag_get(EVAL_COM, USART_FLAG_REA)) {
}
/* check USART is not transmitting */
while(SET == usart_flag_get(EVAL_COM, USART_FLAG_BSY)) {
}
usart_wakeup_enable(EVAL_COM);
/* enable the WUIE interrupt */
usart_interrupt_enable(EVAL_COM, USART_INT_WU);
printf(" enter deep-sleep mode");
/* enable PWU APB clock */
rcu_periph_clock_enable(RCU_PMU);
/* enter deep-sleep mode */
pmu_to_deepsleepmode(PMU_LDNPDSP_NORMALDRIVE, WFI_CMD, PMU_DEEPSLEEP);
/* wait a WUIE interrupt event */
while(0x00 == counter0);
/* disable USART peripheral in deepsleep mode */
usart_wakeup_disable(EVAL_COM);
while(RESET == usart_flag_get(EVAL_COM, USART_FLAG_RBNE));
usart_data_receive(EVAL_COM);
usart_receive_config(EVAL_COM, USART_RECEIVE_ENABLE);
while(RESET == usart_flag_get(EVAL_COM, USART_FLAG_TC));
/* disable the USART */
// usart_disable(EVAL_COM);
/* reconfigure systemclock */
system_clock_reconfig();
systick_config();
while(1) {
}
}
|