From d8c3ae02864d23dd85eb98a744926ffd87a51176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 12 Aug 2024 14:34:31 +0200 Subject: [PATCH] drivers: counter: nrfx_timer: Add barrier when reading CC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add barrier between triggering Capture task and reading CC as otherwise it is possible that CC read will occur before task is triggered when bus is busy. Add barrier between reading previous CC value and writing the new one. Signed-off-by: Krzysztof Chruściński --- drivers/counter/counter_nrfx_timer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/counter/counter_nrfx_timer.c b/drivers/counter/counter_nrfx_timer.c index bd6af3c5d3c..a9f0ed1d0bf 100644 --- a/drivers/counter/counter_nrfx_timer.c +++ b/drivers/counter/counter_nrfx_timer.c @@ -89,6 +89,7 @@ static uint32_t read(const struct device *dev) nrf_timer_task_trigger(timer, nrf_timer_capture_task_get(COUNTER_READ_CC)); + nrf_barrier_w(); return nrf_timer_cc_get(timer, COUNTER_READ_CC); } @@ -160,6 +161,7 @@ static int set_cc(const struct device *dev, uint8_t id, uint32_t val, */ now = read(dev); prev_val = nrf_timer_cc_get(reg, chan); + nrf_barrier_r(); nrf_timer_cc_set(reg, chan, now); nrf_timer_event_clear(reg, evt);