From 6d1fdde1ffc2ac4085457b8afcc1651952843ebb Mon Sep 17 00:00:00 2001 From: Supper Thomas <78900636@qq.com> Date: Mon, 18 Dec 2023 08:40:14 +0800 Subject: [PATCH] add tim8 --- .../libraries/HAL_Drivers/drivers/drv_tim.c | 16 +++++++++++++ .../board/CubeMX_Config/CubeMX_Config.ioc | 23 ++++++++++++------- bsp/stm32/stm32g491-st-nucleo/board/Kconfig | 4 +++- bsp/stm32/stm32g491-st-nucleo/board/board.c | 9 +++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drivers/drv_tim.c b/bsp/stm32/libraries/HAL_Drivers/drivers/drv_tim.c index c1d2cedb9b..629109fd8d 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drivers/drv_tim.c +++ b/bsp/stm32/libraries/HAL_Drivers/drivers/drv_tim.c @@ -571,6 +571,16 @@ void TIM7_IRQHandler(void) rt_interrupt_leave(); } #endif +#ifdef BSP_USING_TIM8 +void TIM8_UP_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + HAL_TIM_IRQHandler(&stm32_hwtimer_obj[TIM8_INDEX].tim_handle); + /* leave interrupt */ + rt_interrupt_leave(); +} +#endif #ifdef BSP_USING_TIM11 void TIM1_TRG_COM_TIM11_IRQHandler(void) { @@ -682,6 +692,12 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) rt_device_hwtimer_isr(&stm32_hwtimer_obj[TIM7_INDEX].time_device); } #endif +#ifdef BSP_USING_TIM8 + if (htim->Instance == TIM8) + { + rt_device_hwtimer_isr(&stm32_hwtimer_obj[TIM8_INDEX].time_device); + } +#endif #ifdef BSP_USING_TIM11 if (htim->Instance == TIM11) { diff --git a/bsp/stm32/stm32g491-st-nucleo/board/CubeMX_Config/CubeMX_Config.ioc b/bsp/stm32/stm32g491-st-nucleo/board/CubeMX_Config/CubeMX_Config.ioc index 497c03d7c3..187909850a 100644 --- a/bsp/stm32/stm32g491-st-nucleo/board/CubeMX_Config/CubeMX_Config.ioc +++ b/bsp/stm32/stm32g491-st-nucleo/board/CubeMX_Config/CubeMX_Config.ioc @@ -11,15 +11,16 @@ Mcu.CPN=STM32G491RET6 Mcu.Family=STM32G4 Mcu.IP0=IWDG Mcu.IP1=LPUART1 +Mcu.IP10=TIM17 Mcu.IP2=NVIC Mcu.IP3=RCC Mcu.IP4=RTC Mcu.IP5=SYS Mcu.IP6=TIM7 -Mcu.IP7=TIM15 -Mcu.IP8=TIM16 -Mcu.IP9=TIM17 -Mcu.IPNb=10 +Mcu.IP7=TIM8 +Mcu.IP8=TIM15 +Mcu.IP9=TIM16 +Mcu.IPNb=11 Mcu.Name=STM32G491R(C-E)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13 @@ -30,9 +31,10 @@ Mcu.Pin12=VP_RTC_VS_RTC_Activate Mcu.Pin13=VP_SYS_VS_Systick Mcu.Pin14=VP_SYS_VS_DBSignals Mcu.Pin15=VP_TIM7_VS_ClockSourceINT -Mcu.Pin16=VP_TIM15_VS_ClockSourceINT -Mcu.Pin17=VP_TIM16_VS_ClockSourceINT -Mcu.Pin18=VP_TIM17_VS_ClockSourceINT +Mcu.Pin16=VP_TIM8_VS_ClockSourceINT +Mcu.Pin17=VP_TIM15_VS_ClockSourceINT +Mcu.Pin18=VP_TIM16_VS_ClockSourceINT +Mcu.Pin19=VP_TIM17_VS_ClockSourceINT Mcu.Pin2=PC15-OSC32_OUT Mcu.Pin3=PF0-OSC_IN Mcu.Pin4=PF1-OSC_OUT @@ -41,7 +43,7 @@ Mcu.Pin6=PA3 Mcu.Pin7=PA5 Mcu.Pin8=PA13 Mcu.Pin9=PA14 -Mcu.PinsNb=19 +Mcu.PinsNb=20 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G491RETx @@ -187,6 +189,9 @@ RCC.VCOInputFreq_Value=4000000 RCC.VCOOutputFreq_Value=340000000 SH.GPXTI13.0=GPIO_EXTI13 SH.GPXTI13.ConfNb=1 +TIM8.IPParameters=Prescaler,PeriodNoDither +TIM8.PeriodNoDither=10625-1 +TIM8.Prescaler=16-1 VP_IWDG_VS_IWDG.Mode=IWDG_Activate VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled @@ -203,5 +208,7 @@ VP_TIM17_VS_ClockSourceINT.Mode=Enable_Timer VP_TIM17_VS_ClockSourceINT.Signal=TIM17_VS_ClockSourceINT VP_TIM7_VS_ClockSourceINT.Mode=Enable_Timer VP_TIM7_VS_ClockSourceINT.Signal=TIM7_VS_ClockSourceINT +VP_TIM8_VS_ClockSourceINT.Mode=Internal +VP_TIM8_VS_ClockSourceINT.Signal=TIM8_VS_ClockSourceINT board=NUCLEO-G491RE boardIOC=true diff --git a/bsp/stm32/stm32g491-st-nucleo/board/Kconfig b/bsp/stm32/stm32g491-st-nucleo/board/Kconfig index 79793765ff..2681e8eb07 100644 --- a/bsp/stm32/stm32g491-st-nucleo/board/Kconfig +++ b/bsp/stm32/stm32g491-st-nucleo/board/Kconfig @@ -163,7 +163,9 @@ menu "On-chip Peripheral Drivers" config BSP_USING_TIM7 bool "Enable TIM7" default n - + config BSP_USING_TIM8 + bool "Enable TIM8" + default n config BSP_USING_TIM15 bool "Enable TIM15" default n diff --git a/bsp/stm32/stm32g491-st-nucleo/board/board.c b/bsp/stm32/stm32g491-st-nucleo/board/board.c index ecedd64035..c2eb22e33f 100644 --- a/bsp/stm32/stm32g491-st-nucleo/board/board.c +++ b/bsp/stm32/stm32g491-st-nucleo/board/board.c @@ -20,10 +20,17 @@ void SystemClock_Config(void) */ HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); + /** Configure LSE Drive Capability + */ + HAL_PWR_EnableBkUpAccess(); + __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); + /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI + |RCC_OSCILLATORTYPE_LSE; + RCC_OscInitStruct.LSEState = RCC_LSE_ON; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.LSIState = RCC_LSI_ON;