From 4e65d543d869b9236dc86d20f1b21bd8c6a91458 Mon Sep 17 00:00:00 2001 From: Andrey Zabolotnyi Date: Wed, 11 Mar 2020 15:18:43 +0300 Subject: [PATCH] Add OUTTOGGLE mode to STM32H7 timer driver (#541) * stm32h7: New timer output mode STM32_TIM_CH_OUTTOGGLE. In this mode timer generates a square waveform on given timer channel. The maximal waveform freq is timer clock divided by 4 (prescaler 1, period 1 results in 2 clocks '0' and 2 clocks '1'). * stm32_tim.h styling fixes. --- arch/arm/src/stm32h7/stm32_tim.c | 5 +++++ arch/arm/src/stm32h7/stm32_tim.h | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/stm32h7/stm32_tim.c b/arch/arm/src/stm32h7/stm32_tim.c index 6761cfdf8e..464d1f6c43 100644 --- a/arch/arm/src/stm32h7/stm32_tim.c +++ b/arch/arm/src/stm32h7/stm32_tim.c @@ -904,6 +904,11 @@ static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, case STM32_TIM_CH_DISABLED: break; + case STM32_TIM_CH_OUTTOGGLE: + ccmr_val = (ATIM_CCMR_MODE_OCREFTOG << ATIM_CCMR1_OC1M_SHIFT); + ccer_val |= ATIM_CCER_CC1E << (channel << 2); + break; + case STM32_TIM_CH_OUTPWM: ccmr_val = (ATIM_CCMR_MODE_PWM1 << ATIM_CCMR1_OC1M_SHIFT) + ATIM_CCMR1_OC1PE; diff --git a/arch/arm/src/stm32h7/stm32_tim.h b/arch/arm/src/stm32h7/stm32_tim.h index ab935cdbbf..f1b3a99c0a 100644 --- a/arch/arm/src/stm32h7/stm32_tim.h +++ b/arch/arm/src/stm32h7/stm32_tim.h @@ -137,11 +137,12 @@ typedef enum /* MODES: */ - STM32_TIM_CH_MODE_MASK = 0x06, + STM32_TIM_CH_MODE_MASK = 0x0e, /* Output Compare Modes */ STM32_TIM_CH_OUTPWM = 0x04, /* Enable standard PWM mode, active high when counter < compare */ + STM32_TIM_CH_OUTTOGGLE = 0x08, /* Toggle TIM_CHx output on UEV */ #if 0 STM32_TIM_CH_OUTCOMPARE = 0x06, @@ -181,7 +182,7 @@ struct stm32_tim_ops_s }; /**************************************************************************** - * Public Functions + * Public Function Prototypes ****************************************************************************/ /* Power-up timer and get its structure */