From ab19a2821ec60b501ec9f84722044977deb31ddc Mon Sep 17 00:00:00 2001 From: Lea Date: Mon, 3 Nov 2025 01:35:53 +0000 Subject: [PATCH] stm32: Enable MOE bit unconditionally for F0/F1/F4 STM32 advanced timers (TIM1 and TIM8) require the Main Output Enable (MOE) bit in the BDTR register to be set for PWM output to function properly. This was already implemented for STM32H7 and STM32G0, but was missing for STM32F0, STM32F1 and STM32F4. This commit adds MOE bit configuration for STM32F0, STM32F1 and STM32F4, and simplifies the implementation by unconditionally enabling MOE for all timers on these platforms. This is safe because MOE is a NOOP (no operation) for non-advanced timers, as confirmed by the STM32 reference manuals. The change unifies the MOE handling across all supported STM32 platforms (F0, F1, F4, H7, G0), making the code simpler and more maintainable. Signed-off-by: Lea --- src/stm32/hard_pwm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stm32/hard_pwm.c b/src/stm32/hard_pwm.c index 6ed27a305..96ce63c83 100644 --- a/src/stm32/hard_pwm.c +++ b/src/stm32/hard_pwm.c @@ -384,7 +384,10 @@ gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint32_t val) } // Enable PWM output p->timer->CR1 |= TIM_CR1_CEN; -#if CONFIG_MACH_STM32H7 || CONFIG_MACH_STM32G0 + // Advanced timers (TIM1/TIM8) require MOE (Main Output Enable) bit + // For non-advanced timers, MOE is a NOOP +#if CONFIG_MACH_STM32F0 || CONFIG_MACH_STM32F1 || CONFIG_MACH_STM32F4 || \ + CONFIG_MACH_STM32H7 || CONFIG_MACH_STM32G0 p->timer->BDTR |= TIM_BDTR_MOE; #endif return channel;