From 7b856cda3028ceb19e0c8a1aad5d17cb7c45c03c Mon Sep 17 00:00:00 2001 From: Hauke Petersen <hauke.petersen@fu-berlin.de> Date: Wed, 7 Dec 2016 14:58:28 +0100 Subject: [PATCH] boards/stm32-based: adapted PWM configuration --- boards/msbiot/include/periph_conf.h | 29 +++++----- boards/nucleo-f207/include/periph_conf.h | 32 ++++------- boards/nucleo-f303/include/periph_conf.h | 34 +++++------ boards/nucleo-f334/Makefile.features | 1 + boards/nucleo-f334/include/periph_conf.h | 19 +++++++ boards/stm32f3discovery/include/periph_conf.h | 57 +++++++------------ boards/stm32f4discovery/include/periph_conf.h | 56 +++++++----------- 7 files changed, 102 insertions(+), 126 deletions(-) diff --git a/boards/msbiot/include/periph_conf.h b/boards/msbiot/include/periph_conf.h index e6eadc1364..b617eeec60 100644 --- a/boards/msbiot/include/periph_conf.h +++ b/boards/msbiot/include/periph_conf.h @@ -76,24 +76,21 @@ static const timer_conf_t timer_config[] = { /** @} */ /** - * @name PWM configuration + * @brief PWM configuration * @{ */ -#define PWM_NUMOF (1U) -#define PWM_0_EN 1 -#define PWM_MAX_CHANNELS 1 /* Increase if Timer with more channels is used */ - -/* PWM 0 device configuration */ -#define PWM_0_DEV TIM11 -#define PWM_0_CHANNELS 1 -#define PWM_0_CLK (168000000U) -#define PWM_0_CLKEN() (RCC->APB2ENR |= RCC_APB2ENR_TIM11EN) -#define PWM_0_CLKDIS() (RCC->APB2ENR &= ~RCC_APB2ENR_TIM11EN) -/* PWM 0 pin configuration */ -#define PWM_0_PORT GPIOB -#define PWM_0_PORT_CLKEN() (RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN) -#define PWM_0_PIN_CH0 9 -#define PWM_0_PIN_AF 3 +static const pwm_conf_t pwm_config[] = { + { + .dev = TIM11, + .rcc_mask = RCC_APB2ENR_TIM11EN, + .pins = { GPIO_PIN(PORT_B, 9), GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF }, + .af = GPIO_AF3, + .chan = 1, + .bus = APB2 + } +}; + +#define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0])) /** @} */ /** diff --git a/boards/nucleo-f207/include/periph_conf.h b/boards/nucleo-f207/include/periph_conf.h index a8679b0c6a..9b4055667f 100644 --- a/boards/nucleo-f207/include/periph_conf.h +++ b/boards/nucleo-f207/include/periph_conf.h @@ -51,25 +51,22 @@ extern "C" { /** @} */ /** - * @name PWM configuration + * @brief PWM configuration * @{ */ -#define PWM_NUMOF (1U) -#define PWM_0_EN 1 - -static const pwm_conf_t pwm_config[PWM_NUMOF] = { +static const pwm_conf_t pwm_config[] = { { - .tim = 2, - .port = GPIOC, - .bus = AHB1, - .rcc_mask = RCC_AHB1ENR_GPIOCEN, - .CH0 = 6, - .CH1 = 7, - .CH2 = 8, - .CH3 = 9, - .AF = 2 + .dev = TIM3, + .rcc_mask = RCC_APB1ENR_TIM3EN, + .pins = { GPIO_PIN(PORT_C, 6), GPIO_PIN(PORT_C, 7), + GPIO_PIN(PORT_C, 8), GPIO_PIN(PORT_C, 9) }, + .af = GPIO_AF2, + .chan = 4, + .bus = APB1 } }; + +#define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0])) /** @} */ /** @@ -91,13 +88,6 @@ static const timer_conf_t timer_config[] = { .bus = APB1, .irqn = TIM5_IRQn }, - { - .dev = TIM3, - .max = 0xffffffff, - .rcc_mask = RCC_APB1ENR_TIM3EN, - .bus = APB1, - .irqn = TIM3_IRQn - }, { .dev = TIM4, .max = 0xffffffff, diff --git a/boards/nucleo-f303/include/periph_conf.h b/boards/nucleo-f303/include/periph_conf.h index 249df3fc45..617dba1866 100755 --- a/boards/nucleo-f303/include/periph_conf.h +++ b/boards/nucleo-f303/include/periph_conf.h @@ -124,28 +124,22 @@ static const timer_conf_t timer_config[] = { /** @} */ /** - * @brief PWM configuration + * @brief PWM configuration * @{ */ -#define PWM_NUMOF (1U) -#define PWM_0_EN 1 - -#define PWM_MAX_CHANNELS 4 - -/* PWM 0 device configuration */ -#define PWM_0_DEV TIM3 -#define PWM_0_CHANNELS 4 -#define PWM_0_CLK (72000000U) -#define PWM_0_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_TIM3EN) -#define PWM_0_CLKDIS() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN)) -/* PWM 0 pin configuration */ -#define PWM_0_PORT GPIOC -#define PWM_0_PORT_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOCEN) -#define PWM_0_PIN_CH0 6 -#define PWM_0_PIN_CH1 7 -#define PWM_0_PIN_CH2 8 -#define PWM_0_PIN_CH3 9 -#define PWM_0_PIN_AF 2 +static const pwm_conf_t pwm_config[] = { + { + .dev = TIM3, + .rcc_mask = RCC_APB1ENR_TIM3EN, + .pins = { GPIO_PIN(PORT_C, 6), GPIO_PIN(PORT_C, 7), + GPIO_PIN(PORT_C, 8), GPIO_PIN(PORT_C, 9) }, + .af = GPIO_AF2, + .chan = 4, + .bus = APB1 + } +}; + +#define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0])) /** @} */ /** diff --git a/boards/nucleo-f334/Makefile.features b/boards/nucleo-f334/Makefile.features index 69a6d62032..7ab9ac6290 100644 --- a/boards/nucleo-f334/Makefile.features +++ b/boards/nucleo-f334/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_gpio +FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_spi FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart diff --git a/boards/nucleo-f334/include/periph_conf.h b/boards/nucleo-f334/include/periph_conf.h index 5167710ce0..073024b07e 100644 --- a/boards/nucleo-f334/include/periph_conf.h +++ b/boards/nucleo-f334/include/periph_conf.h @@ -101,6 +101,25 @@ static const timer_conf_t timer_config[] = { #define UART_0_AF 7 /** @} */ +/** + * @brief PWM configuration + * @{ + */ +static const pwm_conf_t pwm_config[] = { + { + .dev = TIM3, + .rcc_mask = RCC_APB1ENR_TIM3EN, + .pins = { GPIO_PIN(PORT_C, 6), GPIO_PIN(PORT_C, 7), + GPIO_PIN(PORT_C, 8), GPIO_PIN(PORT_C, 9) }, + .af = GPIO_AF2, + .chan = 4, + .bus = APB1 + } +}; + +#define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0])) +/** @} */ + /** * @name SPI configuration * @{ diff --git a/boards/stm32f3discovery/include/periph_conf.h b/boards/stm32f3discovery/include/periph_conf.h index 22e3bdf5f0..7c33e85eec 100644 --- a/boards/stm32f3discovery/include/periph_conf.h +++ b/boards/stm32f3discovery/include/periph_conf.h @@ -126,44 +126,31 @@ static const timer_conf_t timer_config[] = { /** @} */ /** - * @brief PWM configuration + * @brief PWM configuration * @{ */ -#define PWM_NUMOF (2U) -#define PWM_0_EN 1 -#define PWM_1_EN 1 - -#define PWM_MAX_CHANNELS 4 - -/* PWM 0 device configuration */ -#define PWM_0_DEV TIM3 -#define PWM_0_CHANNELS 4 -#define PWM_0_CLK (72000000U) -#define PWM_0_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_TIM3EN) -#define PWM_0_CLKDIS() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM3EN)) -/* PWM 0 pin configuration */ -#define PWM_0_PORT GPIOC -#define PWM_0_PORT_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOCEN) -#define PWM_0_PIN_CH0 6 -#define PWM_0_PIN_CH1 7 -#define PWM_0_PIN_CH2 8 -#define PWM_0_PIN_CH3 9 -#define PWM_0_PIN_AF 2 +static const pwm_conf_t pwm_config[] = { + { + .dev = TIM3, + .rcc_mask = RCC_APB1ENR_TIM3EN, + .pins = { GPIO_PIN(PORT_C, 6), GPIO_PIN(PORT_C, 7), + GPIO_PIN(PORT_C, 8), GPIO_PIN(PORT_C, 9) }, + .af = GPIO_AF2, + .chan = 4, + .bus = APB1 + }, + { + .dev = TIM4, + .rcc_mask = RCC_APB1ENR_TIM4EN, + .pins = { GPIO_PIN(PORT_D, 12), GPIO_PIN(PORT_D, 13), + GPIO_PIN(PORT_D, 14), GPIO_PIN(PORT_D, 15) }, + .af = GPIO_AF2, + .chan = 4, + .bus = APB1 + } +}; -/* PWM 1 device configuration */ -#define PWM_1_DEV TIM4 -#define PWM_1_CHANNELS 4 -#define PWM_1_CLK (72000000U) -#define PWM_1_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_TIM4EN) -#define PWM_1_CLKDIS() (RCC->APB1ENR &= ~(RCC_APB1ENR_TIM4EN)) -/* PWM 1 pin configuration */ -#define PWM_1_PORT GPIOD -#define PWM_1_PORT_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIODEN) -#define PWM_1_PIN_CH0 12 -#define PWM_1_PIN_CH1 13 -#define PWM_1_PIN_CH2 14 -#define PWM_1_PIN_CH3 15 -#define PWM_1_PIN_AF 2 +#define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0])) /** @} */ /** diff --git a/boards/stm32f4discovery/include/periph_conf.h b/boards/stm32f4discovery/include/periph_conf.h index c25a03b317..ff28e41881 100644 --- a/boards/stm32f4discovery/include/periph_conf.h +++ b/boards/stm32f4discovery/include/periph_conf.h @@ -148,43 +148,31 @@ static const uart_conf_t uart_config[] = { /** @} */ /** - * @name PWM configuration + * @brief PWM configuration * @{ */ -#define PWM_NUMOF (2U) -#define PWM_0_EN 1 -#define PWM_1_EN 1 -#define PWM_MAX_CHANNELS 4 - -/* PWM 0 device configuration */ -#define PWM_0_DEV TIM1 -#define PWM_0_CHANNELS 4 -#define PWM_0_CLK (168000000U) -#define PWM_0_CLKEN() (RCC->APB2ENR |= RCC_APB2ENR_TIM1EN) -#define PWM_0_CLKDIS() (RCC->APB2ENR &= ~RCC_APB2ENR_TIM1EN) -/* PWM 0 pin configuration */ -#define PWM_0_PORT GPIOE -#define PWM_0_PORT_CLKEN() (RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN) -#define PWM_0_PIN_CH0 9 -#define PWM_0_PIN_CH1 11 -#define PWM_0_PIN_CH2 13 -#define PWM_0_PIN_CH3 14 -#define PWM_0_PIN_AF 1 +static const pwm_conf_t pwm_config[] = { + { + .dev = TIM1, + .rcc_mask = RCC_APB2ENR_TIM1EN, + .pins = { GPIO_PIN(PORT_E, 9), GPIO_PIN(PORT_E, 11), + GPIO_PIN(PORT_E, 11), GPIO_PIN(PORT_E, 14) }, + .af = GPIO_AF1, + .chan = 4, + .bus = APB2 + }, + { + .dev = TIM3, + .rcc_mask = RCC_APB1ENR_TIM3EN, + .pins = { GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_B, 5), + GPIO_PIN(PORT_B, 0), GPIO_PIN(PORT_B, 1) }, + .af = GPIO_AF2, + .chan = 4, + .bus = APB1 + } +}; -/* PWM 1 device configuration */ -#define PWM_1_DEV TIM3 -#define PWM_1_CHANNELS 3 -#define PWM_1_CLK (84000000U) -#define PWM_1_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_TIM3EN) -#define PWM_1_CLKDIS() (RCC->APB1ENR &= ~RCC_APB1ENR_TIM3EN) -/* PWM 1 pin configuration */ -#define PWM_1_PORT GPIOB -#define PWM_1_PORT_CLKEN() (RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN) -#define PWM_1_PIN_CH0 4 -#define PWM_1_PIN_CH1 5 -#define PWM_1_PIN_CH2 0 -#define PWM_1_PIN_CH3 1 -#define PWM_1_PIN_AF 2 +#define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0])) /** @} */ /** -- GitLab