From 8ff49301e5c57fa12f88b8928c93b14cf5ee70e2 Mon Sep 17 00:00:00 2001 From: Andrey G Date: Mon, 12 Sep 2022 14:35:31 +0300 Subject: [PATCH] stm32: microsecond timer: set correct period value (#4567) Driver sets (period - 1) to ARR (auto-reload register) So we need to set period to (1 << 32) to get maximum 0xffffffff value in ARR. But period is uint32_t. So set it to 0 and it will ovelap to UINT32_MAX at pwmp->tim->ARR = pwmp->period - 1; --- .../ports/stm32/microsecond_timer_stm32.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/firmware/hw_layer/ports/stm32/microsecond_timer_stm32.cpp b/firmware/hw_layer/ports/stm32/microsecond_timer_stm32.cpp index dcea8be757..a5235fa726 100644 --- a/firmware/hw_layer/ports/stm32/microsecond_timer_stm32.cpp +++ b/firmware/hw_layer/ports/stm32/microsecond_timer_stm32.cpp @@ -33,17 +33,24 @@ static void hwTimerCallback(PWMDriver*) { } static constexpr PWMConfig timerConfig = { - SCHEDULER_TIMER_FREQ, - UINT32_MAX, // timer period = 2^32 counts - nullptr, // No update callback - { + .frequency = SCHEDULER_TIMER_FREQ, + /* wanted timer period = 2^32 counts, + * but driver set (period - 1) value to register + * also period is uint32_t + * So set it to zero so it will overlap to 0xffffffff when writen to register */ + .period = 0, + .callback = nullptr, // No update callback + .channels = { {PWM_OUTPUT_DISABLED, hwTimerCallback}, // Channel 0 = timer callback, others unused {PWM_OUTPUT_DISABLED, nullptr}, {PWM_OUTPUT_DISABLED, nullptr}, {PWM_OUTPUT_DISABLED, nullptr} }, - 0, // CR1 - 0 // CR2 + .cr2 = 0, +#if STM32_PWM_USE_ADVANCED + .bdtr = 0, +#endif + .dier = 0 }; void portInitMicrosecondTimer() {