Developing a driver for the SysTick timer
In this section, we will develop a driver for the SysTick timer to generate precise delays.
Let’s start by making a copy of our last project in our IDE, following the steps we learned in Chapter 7. Rename the copied project to SysTick
. Next, create a new file named systick.c
in the Src
folder and another file named systick.h
in the Inc
folder, just like we did for the GPIO drivers in the previous lesson.
Populate your systick.c
file with the following code:
#include "systick.h" #define CTRL_ENABLE (1U<<0) #define CTRL_CLCKSRC (1U<<2) #define CTRL_COUNTFLAG (1U<<16) /*By default, the frequency of the MCU is 16Mhz*/ #define ONE_MSEC_LOAD 16000 void systick_msec_delay(uint32_t delay) { /*Load number of clock cycles per millisecond*/ ...