Electrical – How to set SysTick to 1 ms

armstm32

I am using STM32F100xx and want to set the SysTick timer to 1 ms. How could I do it?

I am reading this part from the reference manual, but I can't understand fully.

SysTick calibration value register

The SysTick calibration value is set to 9000, which gives a reference
time base of 3 ms with the SysTick clock set to 3 MHz (max HCLK/8).

Best Answer

Systick is a feature of the Cortex-M core, therefore it's usage is covered in PM0056 Programming manual STM32F10xxx/20xxx/21xxx/L1xxxx Cortex-M3.

First, set the preload register, the value should be your clock frequency in kHz minus 1.

SysTick->LOAD = 72000 - 1;

then set the control register: source is AHB clock, enable interrupt (if you want to), enable clock.

SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;

Then it's up and running. Leave the calibration value alone.