motor_f103/User/system/bsp/bsp.c

59 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "stm32l4xx_ll_pwr.h"
#include "stm32l4xx_ll_bus.h"
#include "stm32l4xx_ll_exti.h"
#include "stm32l4xx_ll_system.h"
#include "bsp.h"
#define EXIT_LINE LL_EXTI_LINE_16
pvd_irq_handle_cb pvd_irq_handle_cb_func = NULL;
/**
* @brief 配置PVD电源电压检测
*
* 根据给定的电源电压等级配置PVD电源电压检测
*
* @param pwr_level 电源电压等级
* @param call PVD中断处理回调函数
*/
void pvd_configuration(uint32_t pwr_level, pvd_irq_handle_cb call)
{
pvd_irq_handle_cb_func = call;
// 启用电源时钟
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
// 设置PVD电平阈值例如设置为2.2V LL_PWR_PVDLEVEL_1
LL_PWR_SetPVDLevel(pwr_level);
// 启用PVD
LL_PWR_EnablePVD();
// 配置PVD中断
LL_EXTI_EnableIT_0_31(EXIT_LINE); // PVD连接到EXTI Line
LL_EXTI_EnableRisingTrig_0_31(EXIT_LINE);
LL_EXTI_EnableFallingTrig_0_31(EXIT_LINE);
// 启用PVD中断向量
NVIC_EnableIRQ(PVD_PVM_IRQn);
NVIC_SetPriority(PVD_PVM_IRQn, 0);
}
/**
* @brief 处理PVD中断
*
* 当PVD中断触发时该函数将被调用以处理中断事件。
*
* @note 无返回值
*/
void pvd_irq_handle(void)
{
if (LL_EXTI_IsActiveFlag_0_31(EXIT_LINE))
{
LL_EXTI_ClearFlag_0_31(EXIT_LINE);
if (pvd_irq_handle_cb_func != NULL)
{
pvd_irq_handle_cb_func();
}
}
}