STM32 Arm Programming for Embedded Systems by Mazidi Muhammad Ali & Chen Shujen & Ghaemi Eshragh
Author:Mazidi, Muhammad Ali & Chen, Shujen & Ghaemi, Eshragh
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2019-08-11T16:00:00+00:00
Section 6.5: SysTick Programming and Interrupt
Another useful interrupt in Arm is the SysTick. The SysTick timer was discussed in Chapter 5. Next, you learn how to use the SysTick interrupt. See figure below.
Figure 6-15: SysTick Internal Structure
If TICKINT=1, when the COUNT flag is set, it generates an interrupt. TICKINT is D1 of the CSR register, as shown in Figure 6-16.
Figure 6-16: SysTick Control and Status Register (SYST_CSR) The SysTick interrupt can be used to initiate an action on a periodic basis. This action is performed at a fixed rate without external signal. For example, in a given application we can use SysTick to read a sensor every 200 msec. SysTick is used widely for an operating system so that the system software may interrupt the application software periodically (often at 10 ms interval) to monitor and control the system operations.
Using SysTick with Interrupt The Program 6-4 uses the SysTick to toggle an LED every second. We need the RELOAD value of 16,000,000-1. The CLK_SRC bit of CTRL register is set so the system clock is used as the clock source of SysTick. In the STM32F4xx Arm, the alternative clock for SysTick is connected to a prescaler that divides the system clock by 16. The system clock is running at 16 MHz. The COUNT flag is raised every 16,000,000 clocks and an interrupt occurs. Then the RELOAD register is loaded with 16,000,000-1 automatically.
The interrupt is enabled in SysTick Control and Status register. Examining interrupt vector table for Arm Cortex, we see that the SysTick is assigned to INT15. Because SysTick is an interrupt below INT16, the enable/disable and the priority are not managed by the NVIC. Its priority is controlled by a System Handler Priority register (SHPR) of System Control Block (SCB). Instead for finding out which register to use, we may use NVIC_SetPriority(SysTick_IRQn, prio) function defined in core_cm4.h to change the priority. Although the function name has NVIC in it, it modifies SHP registers for interrupts below 16. There is no need to clear interrupt flag in the interrupt handler for SysTick.
Program 6-4: SysTick interrupt /* p6_4.c Toggle the LED using the SysTick interrupt
*
* This program sets up the SysTick to interrupt at 1 Hz. * The system clock is running at 16 MHz.
* 1 sec/1 us = 16,000,000-1 for RELOAD register.
* In the interrupt handler, the LED is toggled.
*
* This program was tested with Keil uVision v5.24a with DFP v2.11.0 */
#include "stm32F4xx.h"
int main(void) {
__disable_irq(); /* global disable IRQs */ RCC->AHB1ENR |= 1; /* enable GPIOA clock */ GPIOA->MODER &= ~0x00000C00; /* clear pin mode */ GPIOA->MODER |= 0x00000400; /* set pin to output mode */
/* Configure SysTick */
SysTick->LOAD = 16000000-1; /* reload with number of clocks per second */ SysTick->VAL = 0;
SysTick->CTRL = 7; /* enable SysTick interrupt, use system clock */ __enable_irq();
void SysTick_Handler(void) {
while (1) { }
}
GPIOA->ODR ^= 0x00000020; /* turn on LED */ }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7808)
Grails in Action by Glen Smith Peter Ledbrook(7719)
Azure Containers Explained by Wesley Haakman & Richard Hooper(6807)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(6803)
Running Windows Containers on AWS by Marcio Morales(6323)
Kotlin in Action by Dmitry Jemerov(5089)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(5051)
Combating Crime on the Dark Web by Nearchos Nearchou(4623)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(4575)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4437)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(4314)
The Age of Surveillance Capitalism by Shoshana Zuboff(3977)
Python for Security and Networking - Third Edition by José Manuel Ortega(3875)
The Ultimate Docker Container Book by Schenker Gabriel N.;(3534)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3528)
Learn Wireshark by Lisa Bock(3491)
Mastering Python for Networking and Security by José Manuel Ortega(3376)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3353)
Blockchain Basics by Daniel Drescher(3322)
