add firmware
This commit is contained in:
34
drv/tim.cpp
Normal file
34
drv/tim.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
Reference in New Issue
Block a user