Skip to content

Commit 0395150

Browse files
author
Cruz Monrreal
authored
Merge pull request #10074 from morser499/cy-mbed-os-5.12.0-pwm-free
Fixed issue with PWM not being freed when the object is destroyed
2 parents a6c9c8c + 51a4713 commit 0395150

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

drivers/PwmOut.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PwmOut {
6868
~PwmOut()
6969
{
7070
core_util_critical_section_enter();
71+
pwmout_free(&_pwm);
7172
unlock_deep_sleep();
7273
core_util_critical_section_exit();
7374
}

targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,13 @@ void pwmout_init(pwmout_t *obj, PinName pin)
235235

236236
void pwmout_free(pwmout_t *obj)
237237
{
238-
/* Does nothing because it is not called in the MBED PWMOUT driver
239-
* destructor. The pwmout_init handles multiple calls of constructor.
240-
*/
238+
#if DEVICE_SLEEP && DEVICE_LPTICKER
239+
if (!Cy_SysPm_UnregisterCallback(&obj->pm_callback_handler)) {
240+
error("PM callback unregistration failed!");
241+
}
242+
#endif
243+
Cy_TCPWM_PWM_Disable(obj->base, obj->counter_id);
244+
Cy_TCPWM_PWM_DeInit(obj->base, obj->counter_id, &pwm_config);
241245
}
242246

243247
void pwmout_write(pwmout_t *obj, float percent)

0 commit comments

Comments
 (0)