Interrupt and Clock PDF
Interrupt and Clock PDF
AND CLOCK
CONFIGURATION
Lecturer: Dr. Bui Ha Duc
Dept. of Mechatronics
Email: [email protected]
1
Outline
• Memory organization
• Clock configuration
• Interrupt handling
2
3
Bus Systems in the Cortex-M0+
4
Bus Systems in the Cortex-M0+
• Bus system in Cortex-M consists:
• 32-bit system bus
• 32-bit peripheral bus
• The system bus
• Based on a AHB protocol
• Connect the processor with different types of memories
• support read/write transfers with 32-, 16-, and 8-bit data
• The peripheral bus
• Based on APB protocol
• The APB is connected to the AHB-Lite via a bus bridge
• Can run at a different clock speed compared to the AHB system
bus
5
Bus Systems in the Cortex-M0+
• In real applications
• Peripheral bus segments may run at different clock frequencies
• Some part of the system may run in a slower speed to achieve
power reduction
• Application might need to initialize clock control hardware
before accessing main program
6
Memory map
• Code Region (0x00000000 - 0x1FFFFFFF)
• Up to 512MB
• Store program code, can also put data here
• Store vector table at address 0x00000000
7
Memory map
• Device Region (0xA0000000 - 0xDFFFFFF)
• consists of two 512 MB memory blocks
• primarily used for peripherals
• two halves of the device region have different memory
attributes.
• Internal Private Peripheral Bus (0xE0000000
- 0xE00FFFFF)
• allocated for peripherals inside the processor
• Size is 1 MB
8
Memory map
9
Holtek HT32F
memory map
10
11
Objectives
• All MCU modules are driven by the clock
• In Cortex-M microcontroller, every module uses
independent clock
• to meet the low-power requirement
• more flexible and precise in control
• It is crucial to understand MCU Clock system in detail
12
HT32F Clock system
• There are 5 clock sources in HT32F MCU
• HSI (High Speed Internal): internal 8 MHz RC oscillator
13
External Oscillator Circuit
14
Clock System Block Diagram 15
Phase Locked Loop – PLL
• PLL Block Diagram
16
Control Register
17
Clock configuration
• In theory, Clock can be configured by setting control
registers.
• However, each ARM vendor has different control register
names for its MCU.
• ARM licenses the processor designs to >160 partners.
18
Cortex Microcontroller System
Interface Standard
19
CMSIS CORE
startup_<device>.s
20
Create a project in Keil MDK
• Refer to Keil MDK-ARM Quick Start for Holtek MCU for
more detail
21
CMSIS device startup file
• startup_<device>.s : define what will be done before
main code
• Interrupt vector
• Interrupt handler
• System Initialization
• startup_ht32f5xxxx_01.s:
System clock is
configured here
22
System initialization
• system_<device>.c : Code for system clock cpnfiguration
• system_ht32f5xxxx_01.c:
23
24
Communicate with physical world
inputs
Physical Microcontroller
world
outputs
25
Software flow
Method 1: Polling
• Simple, easy to
setup
• Work well for
simple tasks
26
Software flow
• Can be expanded to
support multiple
processes
Disavantages?
• Hard to apply to
complex task
• difficult to define
priorities between
different services
• poor responsiveness
• Waste energy Polling method for application with
multiple devices that need processing
27
Interrupt Driven
Method 2: Interrupt
• Waste energy -> sleep
mode, peripheral can
wake up the processor
when it requires a service
http://learn.mikroe.com/ebooks/piccprogramming/chapter/pic16f887-basic-features/ 32
Interrupt Service Routine (ISR)
• Subroutines used to service an interrupt are call
IRQHandler
e.g. ADC_IRQHandler, UART0_IRQHandler
• Each interrupt has an IRQHandler which has an address
listed in Interrupt Vector Table
• Processor obtains the subroutine address from the vector
table and directs the execution to the ISR
• Nested Interrupts: divide interrupts and exceptions into
multiple levels of priority,
• Nested Vectored Interrupt Controller (NVIC): A
programmable hardware unit inside the Cortex-M
processors to handle the management of interrupts and
exception requests
33
Cortex M NVIC
34
Cortex-M CPU and peripheral exceptions
35
Holtek HT32F523352 exception types (partial)
36
Vector table
• 32-bit vector (handler address)
• Declare in startup_<device>.s
37
Vector table from startup code
38
Priority Levels
• IRQ priority is programmable
39
Interrupt Priority Registers
• The NVIC_IPR0-NVIC_IPR7 registers provide an 8-bit
priority field for each interrupt.
40
Interrupt Priority
41
Interrupt Signal Flow
In each peripheral device:
• Each potential interrupt source has a separate enable bit
• Set for devices from which interrupts are to be accepted
• Clear to prevent the peripheral from interrupting the CPU
42
Nested Vectored Interrupt Controller
• NVIC manages and prioritizes external interrupts in
Cortex-M0+
• 32 IRQ sources from peripherals
• NVIC interrupts CPU with IRQ# of highest-priority IRQ
signal
• CPU uses IRQ# to access the vector table & get intr. handler start
address
43
NVIC Register
44
CMSIS functions for NVIC control
CMSIS provides functions for enable/disable Interrupts
46
Example
47