31 #include "generated/airframe.h"
33 #include <libopencm3/stm32/rcc.h>
34 #include <libopencm3/stm32/gpio.h>
35 #include <libopencm3/stm32/timer.h>
36 #include <libopencm3/cm3/nvic.h>
44 #define ONE_MHZ_CLK 1000000
45 #ifdef NVIC_TIM_IRQ_PRIO
46 #define PWM_INPUT_IRQ_PRIO NVIC_TIM_IRQ_PRIO
48 #define PWM_INPUT_IRQ_PRIO 2
59 timer_set_mode(tim, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
60 timer_set_period(tim, 0xFFFF);
62 timer_set_prescaler(tim, (timer_clk / (ticks_per_usec *
ONE_MHZ_CLK)) - 1);
63 timer_enable_counter(tim);
82 #if USE_PWM_INPUT_TIM1
83 rcc_periph_clock_enable(RCC_TIM1);
86 #if USE_PWM_INPUT_TIM2
87 rcc_periph_clock_enable(RCC_TIM2);
90 #if USE_PWM_INPUT_TIM3
91 rcc_periph_clock_enable(RCC_TIM3);
94 #if USE_PWM_INPUT_TIM5
95 rcc_periph_clock_enable(RCC_TIM5);
98 #if USE_PWM_INPUT_TIM8
99 rcc_periph_clock_enable(RCC_TIM8);
102 #if USE_PWM_INPUT_TIM9
103 rcc_periph_clock_enable(RCC_TIM9);
107 #ifdef USE_PWM_INPUT1
116 #if USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_LOW
119 #elif USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_HIGH
132 #ifdef PWM_INPUT1_IRQ2
145 #ifdef USE_PWM_INPUT2
154 #if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
157 #elif USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_HIGH
170 #ifdef PWM_INPUT2_IRQ2
172 nvic_enable_irq(PWM_INPUT2_IRQ2);
193 #if USE_PWM_INPUT_TIM1
196 void tim1_up_isr(
void)
198 #elif defined(STM32F4)
201 if ((TIM1_SR & TIM_SR_UIF) != 0) {
222 #if USE_PWM_INPUT_TIM2
225 if ((TIM2_SR & TIM2_CC_IF_PERIOD) != 0) {
230 if ((TIM2_SR & TIM2_CC_IF_DUTY) != 0) {
235 if ((TIM2_SR & TIM_SR_UIF) != 0) {
243 #if USE_PWM_INPUT_TIM3
246 if ((TIM3_SR & TIM3_CC_IF_PERIOD) != 0) {
251 if ((TIM3_SR & TIM3_CC_IF_DUTY) != 0) {
256 if ((TIM3_SR & TIM_SR_UIF) != 0) {
264 #if USE_PWM_INPUT_TIM5
267 if ((TIM5_SR & TIM5_CC_IF_PERIOD) != 0) {
272 if ((TIM5_SR & TIM5_CC_IF_DUTY) != 0) {
277 if ((TIM5_SR & TIM_SR_UIF) != 0) {
285 #if USE_PWM_INPUT_TIM8
288 void tim8_up_isr(
void)
290 #elif defined(STM32F4)
293 if ((TIM8_SR & TIM_SR_UIF) != 0) {
300 if ((TIM8_SR & TIM8_CC_IF_PERIOD) != 0) {
305 if ((TIM8_SR & TIM8_CC_IF_DUTY) != 0) {
314 #if USE_PWM_INPUT_TIM9
328 if ((TIM9_SR & TIM_SR_UIF) != 0) {
#define PWM_INPUT2_GPIO_AF
CM3_WEAK tim8_cc_isr(void)
#define PWM_INPUT1_GPIO_PIN
timer_clear_flag(TIM6, TIM_SR_UIF)
Some architecture independent helper functions for GPIOs.
CM3_WEAK tim1_cc_isr(void)
uint32_t timer_get_frequency(uint32_t timer_peripheral)
Get Timer clock frequency (before prescaling) Only valid if using the internal clock for the timer...
#define PWM_INPUT1_TIMER_INPUT
#define PWM_INPUT2_CHANNEL_DUTY
CM3_WEAK tim1_up_tim10_isr(void)
#define TIM1_PWM_INPUT_IDX
Architecture independent timing functions.
#define PWM_INPUT2_TIMER_INPUT
#define PWM_INPUT1_CHANNEL_DUTY
#define PWM_INPUT2_CHANNEL_PERIOD
#define PWM_INPUT1_GPIO_AF
void gpio_setup_pin_af(uint32_t port, uint16_t pin, uint8_t af, bool_t is_output)
Setup a gpio for input or output with alternate function.
#define PWM_INPUT2_SLAVE_TRIG
#define PWM_INPUT1_SLAVE_TRIG
#define PWM_INPUT2_GPIO_PIN
#define PWM_INPUT1_GPIO_PORT
CM3_WEAK tim8_up_tim13_isr(void)
CM3_WEAK tim1_brk_tim9_isr(void)
#define TIM9_PWM_INPUT_IDX
#define PWM_INPUT2_GPIO_PORT
#define TIM1_CC_IF_PERIOD
#define TIM9_CC_IF_PERIOD
#define PWM_INPUT1_CHANNEL_PERIOD