Merged in raiden00/nuttx_pe (pull request #877)

Improvements for STM32 PWM

arch/arm/src/stm32/stm32_pwm: add support for all PWM modes

arch/arm/src/stm32/stm32_pwm: add interface to change PWM mode

arch/arm/src/stm32/stm32_pwm: refactor pwm_mode_configure()

arch/arm/src/stm32/stm32_pwm: STM32_PWM_CHANx corresponds to the timer channel and STM32_PWM_OUTx corresponds to the timer channel output

arch/arm/src/stm32/stm32_pwm: add CHAN5 and CHAN6 to PWM_TIMx_NCHANNELS

arch/arm/src/stm32/stm32_pwm: calculate the PWM_TIMx_NCHANNELS if CONFIG_STM32_PWM_MULTICHAN is selected

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
raiden00pl
2019-05-28 15:07:43 +00:00
committed by Gregory Nutt
parent cc2d97f942
commit f4caf4b3ec
7 changed files with 474 additions and 518 deletions
+218 -247
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+78 -30
View File
@@ -123,11 +123,9 @@
#include <arch/board/board.h>
#include "hardware/stm32_tim.h"
/* Configuration needed by upper-half PWM driver */
/* PWM driver channels configuration */
#ifdef CONFIG_PWM
#ifdef CONFIG_PWM_MULTICHAN
#ifdef CONFIG_STM32_PWM_MULTICHAN
#ifdef CONFIG_STM32_TIM1_CHANNEL1
# define PWM_TIM1_CHANNEL1 1
@@ -149,8 +147,19 @@
#else
# define PWM_TIM1_CHANNEL4 0
#endif
#ifdef CONFIG_STM32_TIM1_CHANNEL5
# define PWM_TIM1_CHANNEL5 1
#else
# define PWM_TIM1_CHANNEL5 0
#endif
#ifdef CONFIG_STM32_TIM1_CHANNEL6
# define PWM_TIM1_CHANNEL6 1
#else
# define PWM_TIM1_CHANNEL6 0
#endif
#define PWM_TIM1_NCHANNELS (PWM_TIM1_CHANNEL1 + PWM_TIM1_CHANNEL2 + \
PWM_TIM1_CHANNEL3 + PWM_TIM1_CHANNEL4)
PWM_TIM1_CHANNEL3 + PWM_TIM1_CHANNEL4 + \
PWM_TIM1_CHANNEL5 + PWM_TIM1_CHANNEL6)
#ifdef CONFIG_STM32_TIM2_CHANNEL1
# define PWM_TIM2_CHANNEL1 1
@@ -264,8 +273,19 @@
#else
# define PWM_TIM8_CHANNEL4 0
#endif
#ifdef CONFIG_STM32_TIM8_CHANNEL5
# define PWM_TIM8_CHANNEL5 1
#else
# define PWM_TIM8_CHANNEL5 0
#endif
#ifdef CONFIG_STM32_TIM8_CHANNEL6
# define PWM_TIM8_CHANNEL6 1
#else
# define PWM_TIM8_CHANNEL6 0
#endif
#define PWM_TIM8_NCHANNELS (PWM_TIM8_CHANNEL1 + PWM_TIM8_CHANNEL2 + \
PWM_TIM8_CHANNEL3 + PWM_TIM8_CHANNEL4)
PWM_TIM8_CHANNEL3 + PWM_TIM8_CHANNEL4 + \
PWM_TIM8_CHANNEL5 + PWM_TIM8_CHANNEL6)
#ifdef CONFIG_STM32_TIM9_CHANNEL1
# define PWM_TIM9_CHANNEL1 1
@@ -603,9 +623,7 @@
# define PWM_TIM17_NCHANNELS 1
#endif
#endif /* CONFIG_PWM_MULTICHAN */
#endif /* CONFIG_PWM */
#endif /* CONFIG_STM32_PWM_MULTICHAN */
#ifdef CONFIG_STM32_TIM1_CH1OUT
# define PWM_TIM1_CH1CFG GPIO_TIM1_CH1OUT
@@ -876,6 +894,8 @@
/* Low-level ops helpers ************************************************************/
#ifdef CONFIG_STM32_PWM_LL_OPS
/* NOTE: low-level ops accept pwm_lowerhalf_s as first argument, but llops access
* can be found in stm32_pwm_dev_s
*/
@@ -886,6 +906,8 @@
(dev)->ops->shutdown((FAR struct pwm_lowerhalf_s *)dev)
#define PWM_CCR_UPDATE(dev, index, ccr) \
(dev)->llops->ccr_update((FAR struct pwm_lowerhalf_s *)dev, index, ccr)
#define PWM_MODE_UPDATE(dev, index, mode) \
(dev)->llops->mode_update((FAR struct pwm_lowerhalf_s *)dev, index, mode)
#define PWM_CCR_GET(dev, index) \
(dev)->llops->ccr_get((FAR struct pwm_lowerhalf_s *)dev, index)
#define PWM_ARR_UPDATE(dev, arr) \
@@ -913,6 +935,8 @@
#define PWM_DT_UPDATE(dev, dt) \
(dev)->llops->dt_update((FAR struct pwm_lowerhalf_s *)dev, dt)
#endif
/************************************************************************************
* Public Types
************************************************************************************/
@@ -946,37 +970,57 @@ enum stm32_pwm_idle_e
/* PWM channel mode */
enum stm32_chan_mode_e
enum stm32_pwm_chanmode_e
{
STM32_CHANMODE_PWM1 = 0,
STM32_CHANMODE_PWM2 = 1,
STM32_CHANMODE_FRZN = 0, /* CCRx matches has no effects on outputs */
STM32_CHANMODE_CHACT = 1, /* OCxREF active on match */
STM32_CHANMODE_CHINACT = 2, /* OCxREF inactive on match */
STM32_CHANMODE_OCREFTOG = 3, /* OCxREF toggles when TIMy_CNT=TIMyCCRx */
STM32_CHANMODE_OCREFLO = 4, /* OCxREF is forced low */
STM32_CHANMODE_OCREFHI = 5, /* OCxREF is forced high */
STM32_CHANMODE_PWM1 = 6, /* PWM mode 1 */
STM32_CHANMODE_PWM2 = 7, /* PWM mode 2 */
#ifdef HAVE_IP_TIMERS_V2
STM32_CHANMODE_COMBINED1 = 2,
STM32_CHANMODE_COMBINED2 = 3,
STM32_CHANMODE_ASYMMETRIC1 = 4,
STM32_CHANMODE_ASYMMETRIC2 = 5
STM32_CHANMODE_COMBINED1 = 8, /* Combined PWM mode 1 */
STM32_CHANMODE_COMBINED2 = 9, /* Combined PWM mode 2 */
STM32_CHANMODE_ASYMMETRIC1 = 10, /* Asymmetric PWM mode 1 */
STM32_CHANMODE_ASYMMETRIC2 = 11, /* Asymmetric PWM mode 2 */
#endif
};
/* Timer channel */
/* PWM timer channel */
enum stm32_chan_e
enum stm32_pwm_chan_e
{
STM32_CHAN1 = (1 << 0),
STM32_CHAN1N = (1 << 1),
STM32_CHAN2 = (1 << 2),
STM32_CHAN2N = (1 << 3),
STM32_CHAN3 = (1 << 4),
STM32_CHAN3N = (1 << 5),
STM32_CHAN4 = (1 << 6),
/* No complementary output for CH4 */
STM32_PWM_CHAN1 = 1,
STM32_PWM_CHAN2 = 2,
STM32_PWM_CHAN3 = 3,
STM32_PWM_CHAN4 = 4,
#ifdef HAVE_IP_TIMERS_V2
STM32_PWM_CHAN5 = 5,
STM32_PWM_CHAN6 = 6,
#endif
};
/* PWM timer channel output */
enum stm32_pwm_output_e
{
STM32_PWM_OUT1 = (1 << 0),
STM32_PWM_OUT1N = (1 << 1),
STM32_PWM_OUT2 = (1 << 2),
STM32_PWM_OUT2N = (1 << 3),
STM32_PWM_OUT3 = (1 << 4),
STM32_PWM_OUT3N = (1 << 5),
STM32_PWM_OUT4 = (1 << 6),
/* 1 << 7 reserved - no complementary output for CH4 */
#ifdef HAVE_IP_TIMERS_V2
/* Only available inside micro */
STM32_CHAN5 = (1 << 7),
/* 1<<8 reserved */
STM32_CHAN6 = (1 << 9),
/* 1<<10 reserved */
STM32_PWM_OUT5 = (1 << 8),
/* 1 << 9 reserved - no complementary output for CH5 */
STM32_PWM_OUT6 = (1 << 10),
/* 1 << 11 reserved - no complementary output for CH6 */
#endif
};
@@ -1010,6 +1054,10 @@ struct stm32_pwm_ops_s
int (*ccr_update)(FAR struct pwm_lowerhalf_s *dev, uint8_t index, uint32_t ccr);
/* Update PWM mode */
int (*mode_update)(FAR struct pwm_lowerhalf_s *dev, uint8_t index, uint32_t mode);
/* Get CCR register */
uint32_t (*ccr_get)(FAR struct pwm_lowerhalf_s *dev, uint8_t index);
+2 -2
View File
@@ -405,9 +405,9 @@ int highpri_main(int argc, char *argv[])
PWM_CCR_UPDATE(pwm1, 1, 0x0f00);
/* Enable TIM1 CHAN1 */
/* Enable TIM1 OUT1 */
PWM_OUTPUTS_ENABLE(pwm1, STM32_CHAN1, true);
PWM_OUTPUTS_ENABLE(pwm1, STM32_PWM_OUT1, true);
#else
# error T1CC1 only supported for now
#endif
-2
View File
@@ -284,8 +284,6 @@
/* TIM1 PWM configuration ***************************************************/
# define PWM_TIM1_NCHANNELS 4
# define GPIO_TIM1_CH1OUT GPIO_TIM1_CH1OUT_1 /* TIM1 CH1 - PA8 */
# define GPIO_TIM1_CH1NOUT GPIO_TIM1_CH1N_3 /* TIM1 CH1N - PA7 */
/* TIM1 CH2 - PA9 */
+2 -2
View File
@@ -441,9 +441,9 @@ int highpri_main(int argc, char *argv[])
PWM_CCR_UPDATE(pwm1, 1, 0x0f00);
/* Enable TIM1 CHAN1 */
/* Enable TIM1 OUT1 */
PWM_OUTPUTS_ENABLE(pwm1, STM32_CHAN1, true);
PWM_OUTPUTS_ENABLE(pwm1, STM32_PWM_OUT1, true);
#else
# error T1CC1 only supported for now
#endif
+2 -2
View File
@@ -389,9 +389,9 @@ int highpri_main(int argc, char *argv[])
PWM_CCR_UPDATE(pwm1, 1, 0x0f00);
/* Enable TIM1 CHAN1 */
/* Enable TIM1 OUT1 */
PWM_OUTPUTS_ENABLE(pwm1, STM32_CHAN1, true);
PWM_OUTPUTS_ENABLE(pwm1, STM32_PWM_OUT1, true);
#else
# error T1CC1 only supported for now
#endif