CortexM3 Uni Intro PDF
CortexM3 Uni Intro PDF
CortexM3 Uni Intro PDF
Introduction
ARM University Relations
1
Agenda
Cortex-M3 Overview
v7-M Architecture/Programmers Model
Data Path and Pipelines
Tools and mbed Platform
2
Whats Happening in Microcontrollers?
3
ARM Cortex-M3 Processor
ETM
NVIC Instruction
ARM
1-240 Interrupts Trace
Cortex-M3
8-256 Priorities Core (5-pins)
I D TPIU Trace Port
Trace Port Serial-Wire
DAP Viewer
JTAG/SWD ITM (1-pin)
MPU
Instrumentation
Trace
DWT
FPB Data Trace
BKPT
Bus Matrix
Code Buses System Bus
to Flash to Stack SRAM
to Code SRAM to Peripherals
4
ARM Cortex-M3 Microcontroller
18 x 32-bit registers
Excellent compiler target
Reduced pin count requirements
Efficient interrupt handling
Power management
Efficient debug and development support features
Breakpoints, Watchpoints,
Flash Patch support,
Instruction Trace
Strong OS support
User/Supervisor model
OS support features
Designed to be fully programmed in C (even reset, interrupts and
exceptions)
5
ARM Cortex-M3 Microcontroller
ARMv7M Architecture
No Cache - No MMU
Debug is optimized for microcontroller applications
Vector table contains addresses, not instructions
DIV instruction
Interrupts automatically save/restore state
Exceptions programmed in C (No Coprocessor 15 - All registers are memory-mapped)
Interrupt controller is part of Cortex-M3 macrocell
Fixed memory map
Bit-banding
Non-Maskable Interrupt (NMI)
Only one processor status reg
Thumb-2 processing core
Mix of 16 and 32 bit instructions for very high code density
Gives complete Thumb compatibility
6
ARM and Thumb Performance
30000
25000
20000
Dhrystone 2.1/sec
@ 20MHz
15000 ARM
Thumb
10000
5000
0
32-bit 16-bit 16-bit with
32-bit stack
7
The Thumb-2 instruction set
Variable-length instructions
ARM instructions are a fixed length of 32 bits
Thumb instructions are a fixed length of 16
bits
Thumb-2 instructions can be either 16-bit or
32-bit
8
Agenda
Cortex-M3 Overview
v7-M Architecture/Programmers Model
Data Path and Pipelines
Tools and mbed Platform
9
Cortex-M3 Register Set
Main
Very compiler friendly r0
Load/Store Architecture
r1
r2
32-bit registers r3
r4
Flexible register scheme r5
xPSR
10
Program Status Register
31 28 27 26 25 24 23 16 15 10 7 0
11
An Example AMBA System
High Performance
APB
ARM processor UART
High
Bandwidth AHB Timer
APB
External
Bridge
Memory Keypad
Interface
12
Memory Map
Very simple linear 4GB memory map
The Bus Matrix partitions memory access via the AHB and PPB buses
FFFFFFFF
System
E0100000
The image cannot be display ed. Your computer may not hav e enough memory to open the image,
APB Debug Components
or the image may hav e been corrupted. Restart y our computer, and then open the file again. If the
red x still appears, y ou may hav e to delete the image and then insert it again.
E0040000
CM3 Instruction SCS + NVIC
E0000000
Core Data
External Peripheral
The image cannot be display ed. Your computer may not hav e enough memory to open the image, or the image may hav e been corrupt ed. Restart y our computer, and then open the file
again. If the red x still appears, y ou may hav e to delete the image and then insert it again.
1 GB
Bus Matrix INTERNAL PPB
A0000000
with SYSTEM AHB
SYSTEM AHB External RAM
Debug Bit- Bander
Debug ICODE AHB 1 GB
Aligner
and Patch DCODE AHB 60000000
Peripheral GB
40000000
RAM
GB
20000000
Code Space GB
00000000
13
NXP LPC1311/13/42/43 Block Diagram
14
NXP LPC1311/13/42/43 Memory Map
15
Processor Privilege
ARM Cortex-M3
Privileged Aborts
Supervisor Interrupts
Reset
Handler Mode
OS
User Non-Privileged
Thread Mode Application code
Memory
16
Memory Protection Unit (MPU)
17
Cortex-M3 Bit Banding
18
Cortex-M3 Bit Banding
Writes to a word address in the
bit band alias affect a single bit in
the bit band region
The write is translated to an atomic
read-modify-write by the Cortex-M3
bus matrix
Bit 0 of the stored register is written
to the appropriate bit
31MB
31MB
19
Conditional Execution
If Then (IT) instruction added (16 bit)
Up to 3 additional then or else conditions maybe specified (T or E)
Makes up to 4 following instructions conditional
ITTET EQ MOVEQ
Inst 1 ADDEQ
Inst 2
SUBNE
Inst 3
Inst 4 ORREQ
20
Interrupt Handling
One Non-Maskable Interrupt (INTNMI) supported
1-240 prioritizable interrupts supported
Interrupts can be masked
Implementation option selects number of interrupts supported
Nested Vectored Interrupt Controller (NVIC) is tightly coupled with processor core
Interrupt inputs are active HIGH
INTNMI
Cortex-M3
21
Exception Handling
Reset
NMI
Faults
Hard Fault
Memory Manage
Bus Fault
Usage Fault
SVCall
Debug Monitor
PendSV
SysTick Interrupt
External Interrupt
22
Power Management
Multiple sleep modes supported
Controlled by NVIC
Sleep Now Wait for Interrupt/Event instructions
Sleep On Exit Sleep immediately on return from last ISR
Deep Sleep
Long duration sleep, so PLL can be stopped
Exports additional output signal SLEEPDEEP
23
Cortex-M3 Debug
Single stepping
ITM (Instrumentation Trace Module)
Support for instrumented code
Like printf debugging, but single cycle writes to ITM module can be exported via serial
interface
Optional ETM (Embedded Trace Module) which provides instruction trace
Access to all memory and registers via Debug Access Port (DAP)
Profiling Support
Helps you optimize your code
A hardware triggered PC-sampler is provided by the Cortex-M3 core
Flash patch / Breakpoints
6 instruction comparators, ARMv5T BKPT instruction is supported
2 literal comparators
Allows flash code to be remapped into SRAM or system address space
Data Watchpoint and Trace (DWT) that implements 4 h/w watchpoints
24
Agenda
Cortex-M3 Overview
v7-M Architecture/Programmers Model
Data Path and Pipelines
Tools and mbed Platform
25
Cortex-M3 Datapath
I_HRDATA Instruction
Decode
Address
Register Barrel
Incrementer Mul/Div
Bank Shifter
I_HADDR ALU
A ALU
Address
Register
Writeback
INTADDR
26
Cortex-M3 Pipeline
Cortex-M3 has 3-stage fetch-decode-execute pipeline
Similar to ARM7
Cortex-M3 does more in each stage to increase overall
performance
Instruction
Fetch
Decode & Multiply & Divide Write
(Prefetch)
Register Read
27
Optimal Pipelining
Cycle 1 2 3 4 5 6 7 8 9
Operation
ADD F D E
SUB F D E
ORR F D E
AND F D E
ORR F D E
EOR F D E
Cycle 1 2 3 4 5 6 7 8 9
Address Operation
0x8000 BX r5 F D E
0x8002 SUB F D
0x8004 ORR F
0x8FEC AND F D E
0x8FEE ORR F D E
0x8FF0 EOR F D E
29
LDR Pipeline Example
Cycle 1 2 3 4 5 6 7 8 9
Operation
ADD F D E
SUB F D E
LDR F D Ea Ed
AND F D S E
ORR F S D E
EOR F D E
30
STR-STR Pipeline Example
Cycle 1 2 3 4 5 6 7 8 9
Operation
ADD F D E
SUB F D E
STR F D Ea Ed
STR F D Ea Ed
ORR F D E
EOR F D E
31
Agenda
Cortex-M3 Overview
v7-M Architecture/Programmers Model
Data Path and Pipelines
Tools and mbed Platform
32
RVMDK Software Development Tools
33
RVMDK Software Development Tools
34
Cortex-M3 Development Platforms
35
Rapid Prototyping
Rapid Prototyping helps industries create new products
Control, communication and interaction increasingly define products
Development cycles for microelectronics have not kept pace
36
mbed
Getting Started and Rapid Prototyping with ARM MCUs
Complete Targeted Hardware, Software and Web 2.0 Platform
http://mbed.org
Rapid Prototyping
for Microcontrollers
High-level Peripheral APIs Cortex-M3 MCU in a
Prototyping Form-Factor
37
mbed Motor Controller Example
#include "mbed.h
DigitalOut leftfwd(p16);
DigitalOut leftrev(p17);
PwmOut pwm(p21);
AnalogIn pot(p20);
int main(){
pwm.period_ms(1);
while(1){
float potmod = pot - 0.5;
if (potmod >= 0){
leftfwd = 1;
leftrev = 0;
pwm=((1.8 * potmod) + 0.1);
} else {
leftfwd = 0;
leftrev = 1;
pwm = fabs((1.8 * potmod) - 0.1);
}
}
}
38
Documentation
39
University Resources
http://www.arm.com/support/university/
http://www.mbed.org/
http://www.keil.com/
40
Fin
41