Skip to content

Commit 5d9cbbc

Browse files
FRASTMMaureenHelm
authored andcommitted
drivers: pwm capture with stm32 can have no callback
When configuring the pwm capture, the callback function might be reset, this i not an error. However the isr should not call it and enabling the capture should always provide a callback function. Signed-off-by: Francois Ramu <[email protected]>
1 parent 965d41a commit 5d9cbbc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/pwm/pwm_stm32.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,6 @@ static int pwm_stm32_pin_configure_capture(const struct device *dev,
371371
return -EBUSY;
372372
}
373373

374-
if (cb == NULL) {
375-
LOG_ERR("No PWM capture callback specified");
376-
return -EINVAL;
377-
}
378-
379374
if (!(flags & PWM_CAPTURE_TYPE_MASK)) {
380375
LOG_ERR("No PWM capture type specified");
381376
return -EINVAL;
@@ -386,7 +381,7 @@ static int pwm_stm32_pin_configure_capture(const struct device *dev,
386381
return -ENOTSUP;
387382
}
388383

389-
cpt->callback = cb;
384+
cpt->callback = cb; /* even if the cb is reset, this is not an error */
390385
cpt->user_data = user_data;
391386
cpt->capture_period = (flags & PWM_CAPTURE_TYPE_PERIOD) ? true : false;
392387
cpt->capture_pulse = (flags & PWM_CAPTURE_TYPE_PULSE) ? true : false;
@@ -439,6 +434,11 @@ static int pwm_stm32_pin_enable_capture(const struct device *dev, uint32_t pwm)
439434
return -EBUSY;
440435
}
441436

437+
if (!data->capture.callback) {
438+
LOG_ERR("PWM capture not configured");
439+
return -EINVAL;
440+
}
441+
442442
data->capture.skip_irq = SKIPPED_PWM_CAPTURES;
443443
data->capture.overflows = 0u;
444444
LL_TIM_ClearFlag_CC1(cfg->timer);
@@ -527,10 +527,12 @@ static void pwm_stm32_isr(const struct device *dev)
527527
cpt->overflows = 0u;
528528
}
529529

530-
cpt->callback(dev, in_ch,
530+
if (cpt->callback != NULL) {
531+
cpt->callback(dev, in_ch,
531532
cpt->capture_period ? cpt->period : 0u,
532533
cpt->capture_pulse ? cpt->pulse : 0u,
533534
status, cpt->user_data);
535+
}
534536
}
535537
} else {
536538
if (LL_TIM_IsActiveFlag_UPDATE(cfg->timer)) {

0 commit comments

Comments
 (0)