Skip to content

Commit

Permalink
Add systick diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Jan 4, 2023
1 parent ff5a8a0 commit b0820b5
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 4 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,10 @@ see that SysTick has four registers:
- VAL - a current counter value, decremented on each clock cycle
- CALIB - calibration register
Every time VAL drops to zero, a SysTick interrupt is generated. The SysTick
interrupt index in the vector table is 15, so we need to set it. Upon boot,
our board Nucleo-F429ZI runs at 16Mhz. We can configure the SysTick counter
to trigger interrupt each millisecond.
Every time VAL drops to zero, a SysTick interrupt is generated.
The SysTick interrupt index in the vector table is 15, so we need to set it.
Upon boot, our board Nucleo-F429ZI runs at 16Mhz. We can configure the SysTick
counter to trigger interrupt each millisecond.
First, let's define a SysTick peripheral. We know 4 registers, and from the
datasheet we can learn that the SysTick address is 0xe000e010. So:
Expand Down Expand Up @@ -859,6 +859,15 @@ void SysTick_Handler(void) {
}
```
With 16MHz clock, we init SysTick counter to trigger an interrupt every
16000 cycles: the `SYSTICK->VAL` initial value is 15999, then it decrements
on each cycle by 1, and when it reaches 0, an interrupt is generated. The
firmware code execution gets interrupted: a `SysTick_Handler()` function is
called to increment `s_tick` variable. Here how it looks like on a time scale:
![](images/systick.svg)
The `volatile` specifier is required here becase `s_ticks` is modified by the
interrupt handler. `volatile` prevents the compiler to optimise/cache `s_ticks`
value in a CPU register: instead, generated code always accesses memory. That
Expand Down
162 changes: 162 additions & 0 deletions images/systick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b0820b5

Please sign in to comment.