用复位键启动程序可正常运行
拔电源再插会失败导致一直在stop模式无法唤醒
void LPTIM_Init(u16 arr)
{
NVIC_InitTypeDef NVIC_InitStructure = {0};
LPTIM_TimeBaseInitTypeDef LPTIM_TimeBaseInitStruct = {0};
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
RCC_PB1PeriphClockCmd(RCC_PB1Periph_LPTIM, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = LPTIM_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
LPTIM_Cmd(ENABLE);
RCC_LSICmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY)!=SET);
LPTIM_TimeBaseInitStruct.LPTIM_ClockSource = LPTIM_ClockSource_In;
LPTIM_TimeBaseInitStruct.LPTIM_CountSource = LPTIM_CountSource_Internal;
LPTIM_TimeBaseInitStruct.LPTIM_ClockPrescaler = LPTIM_TClockPrescaler_DIV128;
LPTIM_TimeBaseInitStruct.LPTIM_InClockSource = LPTIM_InClockSource_LSI;
LPTIM_TimeBaseInitStruct.LPTIM_ClockPolarity = LPTIM_ClockPolarity_Falling;
LPTIM_TimeBaseInitStruct.LPTIM_ClockSampleTime = LPTIM_ClockSampleTime_0T;
LPTIM_TimeBaseInitStruct.LPTIM_TriggerSampleTime = LPTIM_TriggerSampleTime_0T;
LPTIM_TimeBaseInitStruct.LPTIM_ExTriggerPolarity = LPTIM_ExTriggerPolarity_Disable;
LPTIM_TimeBaseInitStruct.LPTIM_TimeOut = DISABLE;
LPTIM_TimeBaseInitStruct.LPYIM_OutputPolarity = LPYIM_OutputPolarity_High;
LPTIM_TimeBaseInitStruct.LPYIM_UpdateMode = LPYIM_UpdateMode0;
LPTIM_TimeBaseInitStruct.LPTIM_Encoder = DISABLE;
LPTIM_TimeBaseInitStruct.LPTIM_ForceOutHigh = DISABLE;
LPTIM_TimeBaseInitStruct.LPTIM_SingleMode = DISABLE;
LPTIM_TimeBaseInitStruct.LPTIM_ContinuousMode = ENABLE;
LPTIM_TimeBaseInitStruct.LPTIM_PWMOut = DISABLE;
LPTIM_TimeBaseInitStruct.LPTIM_CounterDirIndicat = DISABLE;
LPTIM_TimeBaseInitStruct.LPTIM_Pulse = 0;
LPTIM_TimeBaseInitStruct.LPTIM_Period = arr;
LPTIM_TimeBaseInit( & LPTIM_TimeBaseInitStruct);
LPTIM_ITConfig(LPTIM_IT_ARRM, ENABLE);
}
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
SystemCoreClockUpdate();
Delay_Init();
Delay_Ms(5000);
USART_Printf_Init(9600);
printf("SystemClk:%d\r\n", SystemCoreClock);
printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
RCC_PB1PeriphClockCmd(RCC_PB1Periph_PWR, ENABLE);
gpioinit();
LPTIM_Init(2000);
while(1)
{
printf("Welcome to WCH\r\n");
GPIO_WriteBit(GPIOA, GPIO_Pin_15, 0);
Delay_Ms(1000);
GPIO_WriteBit(GPIOA, GPIO_Pin_15, 1);
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
}
}
void LPTIM_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void LPTIM_IRQHandler(void)
{
if((LPTIM_GetFlagStatus(LPTIM_FLAG_ARRM)==SET))
{
LPTIM_ClearFlag(LPTIM_FLAG_ARRM);
}
}