drivers: pwm: stm32: add support for L0 series

The STM32L0 series MCUs have quite basic timer features only, so we
remove some unavailable configuration options. They were properly
initilized by the LL StructInit functions for other MCUs anyway.

Signed-off-by: Martin Jäger <martin@libre.solar>
This commit is contained in:
Martin Jäger 2020-12-15 15:19:39 +01:00 committed by Anas Nashif
commit d6648b6124

View file

@ -23,6 +23,11 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(pwm_stm32, CONFIG_PWM_LOG_LEVEL);
/* L0 series MCUs only have 16-bit timers and don't have below macro defined */
#ifndef IS_TIM_32B_COUNTER_INSTANCE
#define IS_TIM_32B_COUNTER_INSTANCE(INSTANCE) (0)
#endif
/** PWM data. */
struct pwm_stm32_data {
/** Timer clock (Hz). */
@ -233,7 +238,6 @@ static int pwm_stm32_pin_set(const struct device *dev, uint32_t pwm,
oc_init.OCState = LL_TIM_OCSTATE_ENABLE;
oc_init.CompareValue = pulse_cycles;
oc_init.OCPolarity = get_polarity(flags);
oc_init.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
if (LL_TIM_OC_Init(cfg->timer, channel, &oc_init) != SUCCESS) {
LOG_ERR("Could not initialize timer channel output");
@ -250,8 +254,6 @@ static int pwm_stm32_pin_set(const struct device *dev, uint32_t pwm,
LL_TIM_SetAutoReload(cfg->timer, period_cycles - 1u);
}
return 0;
}
@ -313,16 +315,18 @@ static int pwm_stm32_init(const struct device *dev)
init.CounterMode = LL_TIM_COUNTERMODE_UP;
init.Autoreload = 0u;
init.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
init.RepetitionCounter = 0u;
if (LL_TIM_Init(cfg->timer, &init) != SUCCESS) {
LOG_ERR("Could not initialize timer");
return -EIO;
}
#ifndef CONFIG_SOC_SERIES_STM32L0X
/* enable outputs and counter */
if (IS_TIM_BREAK_INSTANCE(cfg->timer)) {
LL_TIM_EnableAllOutputs(cfg->timer);
}
#endif
LL_TIM_EnableCounter(cfg->timer);