ch32L103用LPTIM从STOP唤醒失败(插拔电源)

用复位键启动程序可正常运行 

拔电源再插会失败导致一直在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);
     }

}

用的是标准开发板 LPTIM例程也出现同样的问题


简化了一下 SW软启动后正常 再用复位键也正常 拔掉电源再插上又失灵。现在想知道SW软启动写了那些寄存器 和硬插电后复位有啥区别?

void LPTIM_Init(u16 arr)
{
    NVIC_InitTypeDef NVIC_InitStructure = {0};
    LPTIM_TimeBaseInitTypeDef   LPTIM_TimeBaseInitStruct = {0};
    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);

    RCC_LSICmd(ENABLE);
    while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY)!=SET);

    LPTIM_Cmd(ENABLE);

    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_ContinuousMode = ENABLE;
    LPTIM_TimeBaseInitStruct.LPTIM_Period = arr;

    LPTIM_TimeBaseInit( & LPTIM_TimeBaseInitStruct);
    LPTIM_ITConfig(LPTIM_IT_ARRM, ENABLE);

}


您好,目前这边已经复现了你的问题,这边具体看一下,有结论后会及时给予你回复。后续若有问题,也可邮箱(lzs@wch.cn)和我进行沟通。


您好,关于LPTIM唤醒,在使用时需要对EXTI21进行配置,EVT后面会修改更新,可参考一下附件例程。后面若有问题,可邮箱(lzs@wch.cn)沟通。

icon_rar.gifCH32L103 LPTIM.zip



只有登录才能回复,可以选择微信账号登录