feat: ll lptim wakeup example

This commit is contained in:
IOsetting 2023-02-18 15:49:16 +08:00
parent 8126b00838
commit 994d851c82
4 changed files with 176 additions and 0 deletions

View File

@ -0,0 +1,88 @@
/**
* Demo of Low Power Timer Wakeup
*/
#include "main.h"
#include "py32f0xx_bsp_clock.h"
#include "py32f0xx_bsp_printf.h"
static void APP_GPIO_Config(void);
static void APP_ConfigLPTIMOneShot(void);
int main(void)
{
// Set HSI 24MHz as system clock source
BSP_RCC_HSI_24MConfig();
// Initialize UART on PA2:TX PA3:RX
BSP_USART_Config(115200);
printf("PY32F0 LPTIM Wakeup Demo\r\nClock: %ld\r\n", SystemCoreClock);
APP_GPIO_Config();
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPTIM1);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
APP_ConfigLPTIMOneShot();
while (1)
{
LL_PWR_EnableLowPowerRunMode();
LL_LPTIM_Disable(LPTIM1);
LL_LPTIM_Enable(LPTIM1);
LL_mDelay(1);
LL_LPTIM_StartCounter(LPTIM1, LL_LPTIM_OPERATING_MODE_ONESHOT);
printf("Entering stop mode ...");
LL_LPM_EnableDeepSleep();
__WFI();
printf("wakeup\r\n");
}
}
static void APP_GPIO_Config(void)
{
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT);
}
static void APP_ConfigLPTIMOneShot(void)
{
LL_RCC_LSI_Enable();
while(LL_RCC_LSI_IsReady() == 0);
// Set LSI as LPTIM1 clock source
LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM1_CLKSOURCE_LSI);
// Prescaler = 64
LL_LPTIM_SetPrescaler(LPTIM1, LL_LPTIM_PRESCALER_DIV128);
LL_LPTIM_SetUpdateMode(LPTIM1, LL_LPTIM_UPDATE_MODE_ENDOFPERIOD);
LL_LPTIM_EnableIT_ARRM(LPTIM1);
LL_LPTIM_Enable(LPTIM1);
/* 32768 / 128 = 256 */
LL_LPTIM_SetAutoReload(LPTIM1, 255);
NVIC_EnableIRQ(LPTIM1_IRQn);
NVIC_SetPriority(LPTIM1_IRQn, 0);
}
void LPTIM1_IRQHandler(void)
{
if (LL_LPTIM_IsActiveFlag_ARRM(LPTIM))
{
LL_LPTIM_ClearFLAG_ARRM(LPTIM);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_5);
LL_LPTIM_StartCounter(LPTIM1, LL_LPTIM_OPERATING_MODE_ONESHOT);
}
}
void APP_ErrorHandler(void)
{
while (1);
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
while (1);
}
#endif /* USE_FULL_ASSERT */

View File

@ -0,0 +1,28 @@
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
#include "py32f0xx_ll_rtc.h"
#include "py32f0xx_ll_bus.h"
#include "py32f0xx_ll_cortex.h"
#include "py32f0xx_ll_dma.h"
#include "py32f0xx_ll_exti.h"
#include "py32f0xx_ll_gpio.h"
#include "py32f0xx_ll_lptim.h"
#include "py32f0xx_ll_pwr.h"
#include "py32f0xx_ll_rcc.h"
#include "py32f0xx_ll_system.h"
#include "py32f0xx_ll_tim.h"
#include "py32f0xx_ll_utils.h"
void APP_ErrorHandler(void);
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */

View File

@ -0,0 +1,42 @@
#include "main.h"
#include "py32f0xx_it.h"
extern void APP_TransferCompleteCallback(void);
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
while (1)
{
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
}

View File

@ -0,0 +1,18 @@
#ifndef __PY32F0XX_IT_H
#define __PY32F0XX_IT_H
#ifdef __cplusplus
extern "C" {
#endif
void NMI_Handler(void);
void HardFault_Handler(void);
void SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
#ifdef __cplusplus
}
#endif
#endif /* __PY32F0XX_IT_H */