Skip to content

Commit b0820b5

Browse files
committed
Add systick diagram
1 parent ff5a8a0 commit b0820b5

File tree

2 files changed

+175
-4
lines changed

2 files changed

+175
-4
lines changed

README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,10 @@ see that SysTick has four registers:
817817
- VAL - a current counter value, decremented on each clock cycle
818818
- CALIB - calibration register
819819
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.
824824
825825
First, let's define a SysTick peripheral. We know 4 registers, and from the
826826
datasheet we can learn that the SysTick address is 0xe000e010. So:
@@ -859,6 +859,15 @@ void SysTick_Handler(void) {
859859
}
860860
```
861861
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+
862871
The `volatile` specifier is required here becase `s_ticks` is modified by the
863872
interrupt handler. `volatile` prevents the compiler to optimise/cache `s_ticks`
864873
value in a CPU register: instead, generated code always accesses memory. That

images/systick.svg

+162
Loading

0 commit comments

Comments
 (0)