diff --git a/include/libopencm3/cm3/systick.h b/include/libopencm3/cm3/systick.h index 4699e78e..a355b0f8 100644 --- a/include/libopencm3/cm3/systick.h +++ b/include/libopencm3/cm3/systick.h @@ -123,6 +123,7 @@ void systick_interrupt_disable(void); void systick_counter_enable(void); void systick_counter_disable(void); uint8_t systick_get_countflag(void); +void systick_clear(void); uint32_t systick_get_calib(void); diff --git a/lib/cm3/systick.c b/lib/cm3/systick.c index 219104af..a99593b6 100644 --- a/lib/cm3/systick.c +++ b/lib/cm3/systick.c @@ -46,6 +46,10 @@ * The counter is set to the reload value when the counter starts and after it * reaches zero. * + * @note The systick counter value might be undefined upon startup. To get + * predictable behavior, it is a good idea to set or clear the counter after + * set reload. @seealso systick_clear + * * @param[in] value uint32_t. 24 bit reload value. */ @@ -175,6 +179,17 @@ uint8_t systick_get_countflag(void) return (STK_CSR & STK_CSR_COUNTFLAG) ? 1 : 0; } +/*---------------------------------------------------------------------------*/ +/** @brief SysTick Clear counter Value. + * + * The counter value is cleared. Useful for well defined startup. + */ + +void systick_clear(void) +{ + STK_CVR = 0; +} + /*---------------------------------------------------------------------------*/ /** @brief SysTick Get Calibration Value *