Timers
STM32F072
has multiple timers, including TIM2 and TIM3. TIM2 is a 32-bit timer and TIM3 is a 16-bit timer.
We will create a template class timer that will depend on timer traits structures containing timer-specific details. Here is the code for timer traits structures:
struct timer2_traits {
constexpr static std::uintptr_t base_address = 0x40000000;
constexpr static IRQn_Type irqn = TIM2_IRQn;
constexpr static std::uint32_t arr_bit_mask = 0xFFFFFFFF;
};
struct timer3_traits {
constexpr static std::uintptr_t base_address = 0x40000400;
constexpr static IRQn_Type irqn = TIM3_IRQn;
constexpr static std::uint32_t arr_bit_mask = 0xFFFF;
};
In this code, timer2_traits
and timer3_traits
are traits structures that encapsulate the hardware-specific details of TIM2 and TIM3 timers, respectively. They have the following members:
base_address
: The base memory address of the timer’s register mapirqn
: The interrupt request number...