SysTick:

    Now we'll turn our attention to a simple interrupt using the 24-Bit SysTick Timer, and to understand the ARM Cortex M3 interrupt structure, 

one has to plough through the Cortex M3 Technical Reference Manual. Heavy going to be sure, and what with upto 240 Isr's , no doubt for ex-AVR  

machine code freaks, a bit of a nightmare too ;-) Let's work our way slowly through the Source code and we'll see how it goes, ok?

In the Startup_Stmr32F10x_md.s file we can find the corresponding "C" code SysTick Handler Procedure already neatly wrapped up for us.

SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP

    To get it to function, all we have to do is to place a suitable dummy SysTick Handler Routine at the end of our little program (Line 38).

And believe it or not, that's all there's to it :-) This Interrupt handler takes care of everything and provides the RETI, so beloved by AVR freaks.

Between (Lines 9 - 13) we set up the Systick registers to function as follows:

1:    Enable the Systick Interrupt

2:    Set the 24-Bit SysTick Clock to 72 Mhz

    We then enable the clock for PortA (Line 16) and set PortA_2 as a General Purpose Output (50Mhz) for Led1 (Line 20). In the Main Routine 

we have an WFI (Wait For Interrupt) instruction (Line 24) and this puts the Cortex M3 into a Sleep Mode, which is awoken by the SysTick Timer  

timeout every 233 MilliSeconds or so. This timeout is then used to provide a 233 mS. clock to allow us to toggle Led1 on and off (Line 27). 

The routine continually loops back to Main and Led1 blinks with a frequency of approximately 2.146 Hz.

With this small and very basic routine, we've only barely scratched the surface of the Cortex M3 NVIC Interrupt Structure. An excellent introduction

to this structure can be found in the already mentioned manual " The Insider's Guide to Stm32 ARM Based Microcontroller ", page 24.

As Shakespeare once said: " Sleep, the innocent Sleep. Sleep, that knits up the ravelled sleeve of care; great nature's second death." 

Download