#include "stm32g4xx.h" #include "tim.h" static void (*TIM7_Proc)() = 0; extern "C" void TIM7_IRQHandler() { TIM7->SR = 0; TIM7_Proc(); } //------------------------------------------------------------------------------ void TIM7_Init(long Priority) { RCC->APB1ENR1 |= RCC_APB1ENR1_TIM7EN; TIM7->CR1 = 0; TIM7->ARR = 1000 - 1; TIM7->DIER = TIM_DIER_UIE; NVIC_SetPriority(TIM7_IRQn, Priority); NVIC_EnableIRQ(TIM7_IRQn); } //------------------------------------------------------------------------------ void TIM7_Update(unsigned long Freq, void (*Proc)()) { TIM7->CR1 = 0; TIM7->PSC = (SystemCoreClock / 1000 / Freq) - 1; TIM7_Proc = Proc; TIM7->CR1 = TIM_CR1_CEN; } //------------------------------------------------------------------------------