STM32F042-Drivers-Pub/tim1.c
Francesco Gritti fe64f5342d initial commit
2024-05-02 12:18:04 +02:00

48 lines
573 B
C

/*
* tim1.c
*
* Created on: Mar 24, 2024
* Author: Francesco Gritti
*/
#include "mcu.h"
#ifdef tim1_timebase
void TIM1_init (void) {
RCC_TIM1_CLK_ENABLE ();
TIM1->CR1 = 0x0000;
TIM1->DIER |= TIM_DIER_UIE_Msk;
TIM1->CNT = 0x0000;
TIM1->PSC = 23;
TIM1->ARR = 333;
NVIC_SetPriority (TIM1_BRK_UP_TRG_COM_IRQn, 3);
NVIC_EnableIRQ (TIM1_BRK_UP_TRG_COM_IRQn);
// enable timer
TIM1->CR1 |= TIM_CR1_CEN_Msk;
}
__attribute__ ((weak)) void tim1_callback (void);
void TIM1_IRQHandler (void) {
TIM1->SR &= ~TIM_SR_UIF;
tim1_callback ();
}
#endif