ELEC30x0 Lab4 Interrupts
ELEC30x0 Lab4 Interrupts
2
3
1
Hardware Interrupt
actions handler
5
4 CPU in
“Handler
main
Mode”
1 Cortex Microcontroller Software Interface Standard – Functions for all ARM Cortex-M CPUs.
5 Automatically included in your project; defined in header files: core_cmFunc.h, core_cm3.h
Prioritized, vectored interrupts
IRQ6
External
Tech. Ref. interrupts
Manual:
Table 48
Also - refer
to vector
table in Timer
startup interrupts
code
8
STM32L1 vector table in startup code (partial)
__Vectors
DCD __initial_sp ; Pointer to top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
……
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window WatchDog
DCD PVD_IRQHandler ; PVD via EXTI Line detection
DCD TAMP_STAMP_IRQHandler ; Tamper/TimeStamps via EXTI
DCD RTC_WKUP_IRQHandler ; RTC Wakeup via EXTI line
DCD FLASH_IRQHandler ; FLASH
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line0
DCD EXTI1_IRQHandler ; EXTI Line1 Use these names
DCD EXTI2_IRQHandler ; EXTI Line2 for your interrupt
DCD EXTI3_IRQHandler ; EXTI Line3 handler functions
9 DCD EXTI4_IRQHandler ; EXTI Line4
Interrupt signal: from device to CPU Peripheral Device
(“Enabled” in three places) Registers:
In each peripheral device: Enable Flag
Each potential interrupt source has a separate enable bit xIE xF
Set to enable the peripheral to send an interrupt signal to the CPU
Clear to prevent the peripheral from interrupting the CPU
&
Each potential interrupt source has a separate flag bit
Flag set by hardware when an “event” occurs IRQn
Interrupt request = (flag & enable)
Test flag in software if interrupt not desired
ISR software must clear the flag to acknowledge the request
Nested Vectored Interrupt Controller (NVIC)
Receives all interrupt requests
NVIC
Each has an enable bit and a priority within the NVIC
n
# of highest-priority enabled interrupt sent to the CPU
Within the CPU: PRIMASK
11
NVIC setup: enable interrupts
Each IRQ has its own enable bit within the NVIC
NVIC only considers IRQs whose enable bits are set
Interrupt Set Enable Register: each bit enables one interrupt
CMSIS function: NVIC_EnableIRQ(n); //set bit n to enable IRQn
Interrupt Clear Enable Register: each bit disables one interrupt
CMSIS function: NVIC_DisableIRQ(n); //set bit n to disable IRQn
If IRQn still active when exiting handler, or IRQn reactivates while executing the
handler, the pending flag remains set and triggers another interrupt
Avoid duplicate service by clearing IRQn pending flag in software:
CMSIS function: NVIC_ClearPendingIRQ(IRQn);
14
STM32L1xx external interrupt/event controller
• External devices can interrupt CPU via GPIO pins
(Some microcontrollers have dedicated interrupt pins)
• Up to 16 external interrupts (EXTI0-EXTI15), plus 7 internal events
IRQ
to
NVIC
External
interrupt
signal
(GPIO pin)
15
STM32L1xx external interrupt sources
(Select in System Configuration Module – SYSCFG)
• 16 multiplexers select GPIO pins as external interrupts EXTI0..EXTI15
• Mux inputs selected via 4-bit fields of EXTICR[k] registers (k=0..3)
• EXTIx = 0 selects PAx, 1 selects PBx, 2 selects PCx, etc.
• EXTICR[0] selects EXTI3-EXTI0; EXTICR[1] selects EXTI7-EXTI4, etc
15 12 11 8 7 4 3 0
SYSCFG_EXTICR1 is
SYSCFG->EXTICR[0] EXTI3 EXTI2 EXTI1 EXTI0
20