I'm experimenting on the STM32F103 MCU and I'am surprised about what
this code does (in examples/other/systick/systick.c):
/* 72MHz / 8 => 9000000 counts per second */
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
systick_set_reload(9000);
I've found that the LED does not toggle every 1s...
According to the comment and the symbol STK_CTRL_CLKSOURCE_AHB_DIV8,
systick'c clock source is core clock divided by 8.
Diving into the Core M3 datasheet, I've found that bit 2 of SysTick
control and status register selects the clock source, not a divider:
stk clk src = (STK_CTRL bit 2 == 1) ? core clock : ext ref clk
I do not know yet what is this external reference clock but I've tried:
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB);
systick_set_reload(72000);
and now the LED does toggle every 1s.
Maybe it would be wise to rename:
STK_CTRL_CLKSOURCE_AHB_DIV8 as STK_CTRL_CLKSOURCE_EXT
and
STK_CTRL_CLKSOURCE_AHB as STK_CTRL_CLKSOURCE_CORE
or something like that.
Tell me if I'm completely wrong, I need to learn!
--
Christophe
|