diff --git a/drivers/PwmOut.h b/drivers/PwmOut.h index acdd4a2e66..ed8765594a 100644 --- a/drivers/PwmOut.h +++ b/drivers/PwmOut.h @@ -68,6 +68,7 @@ public: ~PwmOut() { core_util_critical_section_enter(); + pwmout_free(&_pwm); unlock_deep_sleep(); core_util_critical_section_exit(); } diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c index ba767da6dc..3562d5e28f 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c @@ -235,9 +235,13 @@ void pwmout_init(pwmout_t *obj, PinName pin) void pwmout_free(pwmout_t *obj) { - /* Does nothing because it is not called in the MBED PWMOUT driver - * destructor. The pwmout_init handles multiple calls of constructor. - */ +#if DEVICE_SLEEP && DEVICE_LPTICKER + if (!Cy_SysPm_UnregisterCallback(&obj->pm_callback_handler)) { + error("PM callback unregistration failed!"); + } +#endif + Cy_TCPWM_PWM_Disable(obj->base, obj->counter_id); + Cy_TCPWM_PWM_DeInit(obj->base, obj->counter_id, &pwm_config); } void pwmout_write(pwmout_t *obj, float percent)