From d214a36e0aee14c49d91ae3f9c1cd19424df62c4 Mon Sep 17 00:00:00 2001 From: Georgii Staroselskii Date: Sat, 14 Oct 2017 00:04:05 +0300 Subject: [PATCH] AP_HAL_Linux: reset duty cycle before setting period On kernels 4.7+ duty_cycle should always be less than period. Otherways, we'll get a EINVAL. It makes sense to set duty_cycle to 0, as duty_cycle doesn't really make sense without a proper period. A proper way to handle these errors might be to call pwm_adjust_config in every pwmchip backend but it's unrealistic to hope that all vendors will do it quickly. --- libraries/AP_HAL_Linux/PWM_Sysfs.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/AP_HAL_Linux/PWM_Sysfs.cpp b/libraries/AP_HAL_Linux/PWM_Sysfs.cpp index b2fdca1137..fad21d72fe 100644 --- a/libraries/AP_HAL_Linux/PWM_Sysfs.cpp +++ b/libraries/AP_HAL_Linux/PWM_Sysfs.cpp @@ -94,6 +94,8 @@ bool PWM_Sysfs_Base::is_enabled() void PWM_Sysfs_Base::set_period(uint32_t nsec_period) { + set_duty_cycle(0); + if (Util::from(hal.util)->write_file(_period_path, "%u", nsec_period) < 0) { hal.console->printf("LinuxPWM_Sysfs: %s Unable to set period\n", _period_path);