diff --git a/boards/samr21-xpro/include/periph_conf.h b/boards/samr21-xpro/include/periph_conf.h index 79a9c30ae705686b33cf72e1e1042e6c6a260447..2199c060eb2c4897be85a12fa55dfe5ba63ef295 100644 --- a/boards/samr21-xpro/include/periph_conf.h +++ b/boards/samr21-xpro/include/periph_conf.h @@ -122,7 +122,7 @@ static const uart_conf_t uart_config[] = { */ #define PWM_0_EN 1 #define PWM_1_EN 1 -#define PWM_MAX_CHANNELS 2 +#define PWM_MAX_CHANNELS 3 /* for compatibility with test application */ #define PWM_0_CHANNELS PWM_MAX_CHANNELS #define PWM_1_CHANNELS PWM_MAX_CHANNELS @@ -132,16 +132,18 @@ static const pwm_conf_t pwm_config[] = { #if PWM_0_EN {TCC1, { /* GPIO pin, MUX value, TCC channel */ - {GPIO_PIN(PA, 6), GPIO_MUX_E, 0}, - {GPIO_PIN(PA, 7), GPIO_MUX_E, 1} + { GPIO_PIN(PA, 6), GPIO_MUX_E, 0 }, + { GPIO_PIN(PA, 7), GPIO_MUX_E, 1 }, + { GPIO_UNDEF, (gpio_mux_t)0, 2 } }}, #endif #if PWM_1_EN {TCC0, { /* GPIO pin, MUX value, TCC channel */ - {GPIO_PIN(PA, 18), GPIO_MUX_F, 2}, - {GPIO_PIN(PA, 19), GPIO_MUX_F, 3} - }}, + { GPIO_PIN(PA, 16), GPIO_MUX_F, 0 }, + { GPIO_PIN(PA, 18), GPIO_MUX_F, 2 }, + { GPIO_PIN(PA, 19), GPIO_MUX_F, 3 } + }} #endif }; diff --git a/cpu/samd21/include/periph_cpu.h b/cpu/samd21/include/periph_cpu.h index 1f51c56bba5c3fecfb6d8e3f75df22c3de154295..7143010238dbbe72faacd2c8db7cc61d10f7889f 100644 --- a/cpu/samd21/include/periph_cpu.h +++ b/cpu/samd21/include/periph_cpu.h @@ -48,7 +48,7 @@ typedef struct { */ typedef struct { Tcc *dev; /**< TCC device to use */ - pwm_conf_chan_t chan[2]; /**< channel configuration */ + pwm_conf_chan_t chan[3]; /**< channel configuration */ } pwm_conf_t; /** diff --git a/cpu/samd21/periph/pwm.c b/cpu/samd21/periph/pwm.c index 648a4349ad32132a51bb00f88562c27a2473dd97..af107be8704dbbf4fb4909934fd30a26005cac6f 100644 --- a/cpu/samd21/periph/pwm.c +++ b/cpu/samd21/periph/pwm.c @@ -106,8 +106,10 @@ uint32_t pwm_init(pwm_t dev, pwm_mode_t mode, uint32_t freq, uint16_t res) /* configure the used pins */ for (int i = 0; i < PWM_MAX_CHANNELS; i++) { - gpio_init(pwm_config[dev].chan[i].pin, GPIO_DIR_OUT, GPIO_NOPULL); - gpio_init_mux(pwm_config[dev].chan[i].pin, pwm_config[dev].chan[i].mux); + if (pwm_config[dev].chan[i].pin != GPIO_UNDEF) { + gpio_init(pwm_config[dev].chan[i].pin, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init_mux(pwm_config[dev].chan[i].pin, pwm_config[dev].chan[i].mux); + } } /* power on the device */ @@ -152,7 +154,8 @@ uint8_t pwm_channels(pwm_t dev) void pwm_set(pwm_t dev, uint8_t channel, uint16_t value) { - if (channel >= PWM_MAX_CHANNELS) { + if ((channel >= PWM_MAX_CHANNELS) || + (pwm_config[dev].chan[channel].pin == GPIO_UNDEF)) { return; } _tcc(dev)->CC[_chan(dev, channel)].reg = value;