Skip to content

Commit bb30acf

Browse files
drivers: counter: stm32: add counter reset
Add a reset counter api to set the time back to 0. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
1 parent f412cc6 commit bb30acf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/counter/counter_ll_stm32_timer.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,16 @@ static uint32_t counter_stm32_get_freq(const struct device *dev)
540540
return data->freq;
541541
}
542542

543+
static int counter_stm32_reset_timer(const struct device *dev)
544+
{
545+
const struct counter_stm32_config *config = dev->config;
546+
TIM_TypeDef *timer = config->timer;
547+
548+
LL_TIM_SetCounter(timer, 0);
549+
550+
return 0;
551+
}
552+
543553
static void counter_stm32_top_irq_handle(const struct device *dev)
544554
{
545555
struct counter_stm32_data *data = dev->data;
@@ -585,6 +595,7 @@ static DEVICE_API(counter, counter_stm32_driver_api) = {
585595
.get_guard_period = counter_stm32_get_guard_period,
586596
.set_guard_period = counter_stm32_set_guard_period,
587597
.get_freq = counter_stm32_get_freq,
598+
.reset = counter_stm32_reset_timer,
588599
};
589600

590601
#define TIM_IRQ_HANDLE_CC(timx, cc) \

0 commit comments

Comments
 (0)