@@ -817,10 +817,10 @@ see that SysTick has four registers:
817
817
- VAL - a current counter value, decremented on each clock cycle
818
818
- CALIB - calibration register
819
819
820
- Every time VAL drops to zero, a SysTick interrupt is generated. The SysTick
821
- interrupt index in the vector table is 15, so we need to set it. Upon boot,
822
- our board Nucleo-F429ZI runs at 16Mhz. We can configure the SysTick counter
823
- to trigger interrupt each millisecond.
820
+ Every time VAL drops to zero, a SysTick interrupt is generated.
821
+ The SysTick interrupt index in the vector table is 15, so we need to set it.
822
+ Upon boot, our board Nucleo-F429ZI runs at 16Mhz. We can configure the SysTick
823
+ counter to trigger interrupt each millisecond.
824
824
825
825
First, let' s define a SysTick peripheral. We know 4 registers, and from the
826
826
datasheet we can learn that the SysTick address is 0xe000e010. So:
@@ -859,6 +859,15 @@ void SysTick_Handler(void) {
859
859
}
860
860
` ` `
861
861
862
+ With 16MHz clock, we init SysTick counter to trigger an interrupt every
863
+ 16000 cycles: the ` SYSTICK-> VAL` initial value is 15999, then it decrements
864
+ on each cycle by 1, and when it reaches 0, an interrupt is generated. The
865
+ firmware code execution gets interrupted: a `SysTick_Handler ()` function is
866
+ called to increment ` s_tick` variable. Here how it looks like on a time scale:
867
+
868
+ ! [](images/systick.svg)
869
+
870
+
862
871
The ` volatile` specifier is required here becase ` s_ticks` is modified by the
863
872
interrupt handler. ` volatile` prevents the compiler to optimise/cache ` s_ticks`
864
873
value in a CPU register: instead, generated code always accesses memory. That
0 commit comments