From 907b487eb74d1c755c6df722a14cea18ba528eba Mon Sep 17 00:00:00 2001 From: Martin Vajnar Date: Fri, 6 Jun 2025 16:54:03 +0200 Subject: [PATCH] arch/xtensa/src/common/espressif/esp_pcnt.c: counter accumulation fix Port fix from risc-v code. Providing original description: Even when enabled, the PCNT counter doesn't accumulate into the 32-bit value. Instead, a value in range [PCNT_LOW_LIMIT, PCNT_HIGH_LIMIT] is always returned. This is due to interrupt events associated with limit overflows are disabled on the periphery, therefore the ISR responsible for the accumulation never gets called. Fixed by enabling the associated interrupt events. Signed-off-by: Martin Vajnar Original-fix-by: michal matias --- arch/xtensa/src/common/espressif/esp_pcnt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/xtensa/src/common/espressif/esp_pcnt.c b/arch/xtensa/src/common/espressif/esp_pcnt.c index 1f1156b3fd0..62c3f320cde 100644 --- a/arch/xtensa/src/common/espressif/esp_pcnt.c +++ b/arch/xtensa/src/common/espressif/esp_pcnt.c @@ -304,7 +304,7 @@ static int esp_pcnt_ioctl(struct cap_lowerhalf_s *dev, int cmd, ret = esp_pcnt_unit_get_count(dev, (int *)arg); if (ret != OK) { - cperr("Could not clear pcnt-%d!\n", priv->unit_id); + cperr("Could not get count from pcnt-%d!\n", priv->unit_id); } break; @@ -894,6 +894,10 @@ struct cap_lowerhalf_s *esp_pcnt_new_unit( } pcnt_ll_disable_all_events(ctx.dev, unit_id); + + pcnt_ll_enable_high_limit_event(ctx.dev, unit_id, config->accum_count); + pcnt_ll_enable_low_limit_event(ctx.dev, unit_id, config->accum_count); + pcnt_ll_enable_glitch_filter(ctx.dev, unit_id, false); pcnt_ll_set_high_limit_value(ctx.dev, unit_id, config->high_limit); pcnt_ll_set_low_limit_value(ctx.dev, unit_id, config->low_limit);