Skip to content

Commit 3868a7f

Browse files
committed
cpu/stm32: implement periph_timer_query_freqs
1 parent 5dc3d9c commit 3868a7f

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

cpu/stm32/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ config CPU_STM32
1212
select HAS_PERIPH_GPIO
1313
select HAS_PERIPH_GPIO_IRQ
1414
select HAS_PERIPH_TIMER_PERIODIC
15+
select HAS_PERIPH_TIMER_QUERY_FREQS
1516
select HAS_PERIPH_RTT_OVERFLOW
1617
select HAS_PERIPH_UART_MODECFG
1718
select HAS_PERIPH_UART_NONBLOCKING

cpu/stm32/Makefile.features

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ FEATURES_PROVIDED += cpu_stm32$(CPU_FAM)
88
FEATURES_PROVIDED += periph_cpuid
99
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
1010
FEATURES_PROVIDED += periph_timer_periodic
11+
FEATURES_PROVIDED += periph_timer_query_freqs
1112
FEATURES_PROVIDED += periph_rtt_overflow
1213
FEATURES_PROVIDED += periph_uart_modecfg
1314
FEATURES_PROVIDED += periph_uart_nonblocking

cpu/stm32/periph/timer.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ int timer_set_absolute(tim_t tim, int channel, unsigned int value)
161161
return 0;
162162
}
163163

164+
uword_t timer_query_freqs_numof(tim_t dev)
165+
{
166+
(void)dev;
167+
/* Prescaler values from 0 to UINT16_MAX are supported */
168+
return UINT16_MAX + 1;
169+
}
170+
171+
uint32_t timer_query_freqs(tim_t dev, uword_t index)
172+
{
173+
174+
if (index > UINT16_MAX) {
175+
return 0;
176+
}
177+
178+
return periph_timer_clk(timer_config[dev].bus) / (index + 1);
179+
}
180+
164181
int timer_set(tim_t tim, int channel, unsigned int timeout)
165182
{
166183
unsigned value = (dev(tim)->CNT + timeout) & timer_config[tim].max;

0 commit comments

Comments
 (0)