代码如下, 根据官方例子等都不能进入中断,LSE可以使用(LPUART使用LSE能正常工作),调试过程中进入过2次, 手贱没保存。 求救。
#include "lptim.h"
LPTIM_HandleTypeDef LptimHandle;
void LPTIM1_IRQHandler(void)
{
HAL_LPTIM_IRQHandler(&LptimHandle);
log(DEBUG,"lptim count=%u\n" , HAL_LPTIM_ReadCounter(&LptimHandle));
}
void HAL_LPTIM1_MspInit(LPTIM_HandleTypeDef *lptimHandle)
{
__HAL_RCC_LPTIM1_CLK_ENABLE();
HAL_NVIC_SetPriority(LPTIM1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(LPTIM1_IRQn);
}
#define Period (uint32_t) 65535
#define Timeout (uint32_t) (32768 - 1)
int lptim_hal_init(void)
{
RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct;
HAL_Delay(2000);
/* Select the LSE clock as LPTIM peripheral clock */
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;
RCC_PeriphCLKInitStruct.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSE;
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
LptimHandle.Instance = LPTIM1;
LptimHandle.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
LptimHandle.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
LptimHandle.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
LptimHandle.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
LptimHandle.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
LptimHandle.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
LptimHandle.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
if (HAL_LPTIM_Init(&LptimHandle) != HAL_OK)
{
Error_Handler(__FILE__,__LINE__);
}
INIT_PRINT(INIT_OK,"LPTIM1 init");
if (HAL_LPTIM_Counter_Start(&LptimHandle, 1000) != HAL_OK)
{
Error_Handler(__FILE__,__LINE__);
}
HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
log(DEBUG,"lptime init\n");
return 0;
}
|