Unit 5 Notes
Unit 5 Notes
Unit 5 Notes
INTRODUCTION :
ARM was formed in 1990 as Advanced RISC Machines Ltd., a joint venture of Apple
Computer, Acorn Computer Group, and VLSI Technology. In 1991, ARM introduced the
ARM6 processor family, and VLSI became the initial licensee.
The ARM Cortex™-M3 processor, the first of the Cortex generation of processors
released by ARM in 2006, was primarily designed to target the 32-bit microcontroller
market. The Cortex-M3 processor provides excellent performance at low gate count and
comes with many new features previously avail- able only in high-end processors. The
Cortex-M3 addresses the requirements for the 32-bit embedded processor market in the
following ways:
• Greater performance efficiency: allowing more work to be done without
increasing the frequency or power requirements
• Low power consumption: enabling longer battery life, especially critical in
portable products including wireless networking applications
• Enhanced determinism: guaranteeing that critical tasks and interrupts are
serviced as quickly as possible and in a known number of cycles
• Improved code density: ensuring that code fits in even the smallest memory
footprints
• Ease of use: providing easier programmability and debugging for the growing
number of 8-bit and 16-bit users migrating to 32 bits
• Lower cost solutions: reducing 32-bit-based system costs close to those of
legacy 8-bit and 16-bit devices and enabling low-end, 32-bit microcontrollers
to be priced at less than US$1 for the first time
• Wide choice of development tools: from low-cost or free compilers to full-
featured development suites from many development tool vendors
FEATURES OF ARM7 PROCESSOR:
ARM ARCHITECTURE :
Advanced RISC Machine or Acorn RISC Machine is the architecture with different
computing architectures set to be used in different environments. 32-bit and 64-bit can be
used here in different computer processors. It was developed by Arm Holdings and the
architecture is updated in between. This architecture is specified to be used with CPU,
different chips in the system, and in different registers. Reduced Instruction Set Computing
helps in creating instructions for the system to be used for several purposes. Smartphones,
microcomputers, and embedded devices also use ARM architecture for the instruction set in
the registers.
The architecture can be divided into A, R, and M profiles. A profile is mainly for
applications, R profile is for real-time and M profile is for Microcontroller. A profile helps
to maintain high performance and is designed to run the complex system in Linux or
Windows. R profile checks for systems with real-time requirements and is found in
networking equipment or embedded control systems. M profile is used in IOT devices and
can be synchronized with small and high-power devices.
CORTEX – M0:
The Cortex-M0 core is optimized for small silicon die size and use in the
lowest price chips.It consists of an ARM architecture of ARMV6-M, with Von-
Nuemann memory architecture.It follows 3 stage instruction pipeline.It uses both
Thumb 1(most) and Thumb 2(some) instructions.It takes 16 cycles for Interrupt
including Zero-wait state RAM.
CORTEX – M0+ :
CORTEX M1:
CORTEX M3:
ARMv7-M architecture is used in CORTEX M3. It has 3-stage pipeline with branch
speculation. Thumb-1 and Thumb-2 instructions are used entirely . If 32-bit hardware
integer multiply with 32-bit or 64-bit it results in signed or unsigned, add or subtract after
the multiply. 32-bit multiply is 1 cycle, but 64-bit multiply and MAC instructions require
extra cycles.32-bit hardware integer divided into (2–12 cycles). It has Optional Memory
Protection Unit (MPU): 0 or 8 regions.There are 1 to 241 interrupts including NMI. It
requires 12 cycle interrupt latency.
CORTEX M4:
The Cortex-M7 is a high-performance core with almost double the power efficiency
of the older Cortex-M4. It features a 6-stage superscalar pipeline with branch prediction and
an optional floating-point unit capable of single-precision and optionally double-
precision operations. The instruction and data buses have been enlarged to 64-bit wide over
the previous 32-bit buses. If a core contains an FPU, it is known as a Cortex-M7F, otherwise
it is a Cortex-M7. Entire Thumb 1 and Thumb 2 instructions will be used. It follows the
same specifications of CORTEX M4 for multiplication,division, saturated arithmetic,
interrupts and interrupt latency etc.
CORTEX M23:
The Cortex-M23 core was announced in October 2016 and based on the
newer ARMv8-M architecture that was previously announced in November
2015. Conceptually the Cortex-M23 is similar to a Cortex-M0+ plus integer divide
instructions and Trust Zone security features, and also has a 2-stage instruction pipeline. For
32-bit hardware integer divide it takes 17 or 34 cycles. It is much slower than divide in all
other cores. Stack limit boundaries are available only with SAU option(available in
M23/M33/M35P).
The Cortex-M33 core was announced in October 2016 and based on the
newer ARMv8-M architecture that was previously announced in November
2015. Conceptually the Cortex-M33 is similar to a cross of Cortex-M4 and Cortex-M23, and
also has a 3-stage instruction pipeline.
CORTEX M35P:
The Cortex-M35P core was announced in May 2018. It is conceptually a Cortex-
M33 core with a new instruction cache, plus new tamper-resistant hardware concepts
borrowed from the ARM Secure Core family, and configurable parity and ECC features.
CORTEX M55:
The Cortex-M55 core was announced in February 2020 and is based on the Armv8.1-M
architecture that was previously announced in February 2019. It also has a 4-stage
instruction pipeline. Stack limit boundaries (available only with SAU option).
ARM – CORTEX M3 FUNCTIONAL DESCRIPTION :
The Wakeup Interrupt Controller (WIC) is a peripheral that can detect an interrupt
and wake the processor from deep sleep mode. The WIC is enabled only when the system is
in deep sleep mode.
The WIC is not programmable, and does not have any registers or user interface. It
operates entirely from hardware signals.
The term “nested” refers to the fact that in NVIC, a number of interrupts (up to
several hundred in some processors) can be defined, and each interrupt is assigned a
priority, with “0” being the highest priority.
BREAKPOINT UNIT:
A breakpoint enables you to interrupt your application when execution reaches a specific
address. When execution reaches the breakpoint, normal execution stops before any
instruction stored there is executed.
Types of breakpoints:
Software breakpoints stop your program when execution reaches a specific address.
Software breakpoints are implemented by the debugger replacing the instruction at the
breakpoint address with a special instruction. Software breakpoints can only be set in
RAM.
The MPU is an optional component for memory protection. The processor supports
the standard ARMv7 Protected Memory System Architecture model. The MPU provides full
support for:
protection regions
overlapping protection regions, with ascending region priority:
7 = highest priority
0 = lowest priority.
access permissions
exporting memory attributes to the system.
INTERFACES :
There are several bus interfaces on the Cortex-M3 processor. They allow the Cortex-
M3 to carry instruction fetches and data accesses at the same time. The main bus interfaces
are as follows: • Code memory buses • System bus • Private peripheral bus The code
memory region access is carried out on the code memory buses, which physically consist of
two buses, one called I-Code and other called D-Code. These are optimized for instruction
fetches for best instruction execution speed. The system bus is used to access memory and
peripherals. This provides access to the Static Random Access Memory (SRAM),
peripherals, external RAM, external devices, and part of the system level memory regions.
The private peripheral bus provides access to a part of the system-level memory
dedicated to private peripherals, such as debugging components.
MODES OF OPERATION :
The Cortex-M3 processor has two modes and two privilege levels. The operation
modes are given as,
1. Thread Mode
2. Handler Mode
In Thread mode,the processor works in normal mode. In Handler mode, the
processor runs in exception handler like an interrupt handler system.
There are two privilege levels which provide a mechanism for safeguarding
memory accesses to critical regions as well as providing a basic security model. They
are :
1. Privileged Level
2. User Level
When the processor is running a main program (thread mode), it can be either
in a privileged state or a user state, but exception handlers can only be in a
privileged state.
When the processor exits reset, it is in thread mode, with privileged access
rights. In the privileged state, a program has access to all memory ranges (except
when prohibited by MPU settings) and can use all supported instructions.
Software in the privileged access level can switch the program into the user
access level using the control register. When an exception takes place, the processor
will always switch back to the privileged state and return to the previous state when
exiting the exception handler.
A user program cannot change back to the privileged state by writing to the
control register. It has to go through an exception handler that programs the control
register to switch the processor back into the privileged access level when returning
to thread mode.
The support of privileged and user access levels provides a more secure and
robust architecture. For example, when a user program goes wrong, it will not be able to
corrupt control registers in the Nested Vectored Interrupt Controller (NVIC). In
addition, if the Memory Protection Unit (MPU) is present, it is possible to block user
programs from accessing memory regions used by privileged processes.
The user application stack and the kernel stack memory can be separated to
avoid the possibility of crashing a system caused by stack operation errors in user
programs. With this arrangement, the user program (running in thread mode) uses
the PSP, and the exception handlers use the MSP. The switching of SPs is automatic
upon entering or leaving the exception handlers
Privileged User
When running an exception handler Handler mode
When not running an exception handler Thread mode Thread mode
(e.g., main program)
The mode and access level of the processor are defined by the control register. When
the control register bit 0 is 0, the processor mode changes when an exception takes place.
When control register bit 0 is 1 (thread running user application), both processor
mode and access level change when an exception takes place.
Control register bit 0 is programmable only in the privileged level. For a user-
level program to switch to privileged state, it has to raise an interrupt (for example,
supervisor call [SVC]) and write to CONTROL within the handler.
The SRAM memory range is for connecting internal SRAM. Access to this region
is carried out via the system interface bus. a 32-MB range is defined as a bit-band alias.
Within the 32-bit-band alias memory range, each word address represents a single bit in
the 1-MB bit-band region. A data write access to this bit-band alias memory range will be
converted to an atomic READ- MODIFY-WRITE operation to the bit-band region so as
to allow a program to set or clear individual data bits in the memory. The bit-band
operation applies only to data accesses not instruction fetches. By putting Boolean
information (single bits) in the bit-band region, it is possible to pack multiple Boolean
data in a single word while still allowing them to be accessible individually via bit-band
alias, thus saving memory space without the need for handling READ-MODIFY-WRITE
in software.
Another 0.5-GB block of address range is allocated to on-chip peripherals. Similar
to the SRAM region, this region supports bit-band alias and is accessed via the system
bus interface. However, instruction execution in this region is not allowed. The bit-band
support in the peripheral region makes it easy to access or change control and status bits
of peripherals, making it easier to program peripheral control.
Two slots of 1-GB memory space are allocated for external RAM and external
devices. The difference between the two is that program execution in the external device
region is not allowed, and there are some differences with the caching behaviors.
The last 0.5-GB memory is for the system-level components, internal peripheral
buses, external peripheral bus, and vendor-specific system peripherals. There are two
segments of the private peripheral bus (PPB):
• Advanced High-Performance Bus (AHB) PPB, for Cortex-M3 internal AHB
peripherals only; this includes NVIC, FPB, DWT, and ITM
• Advance Peripheral Bus (APB) PPB, for Cortex-M3 internal APB devices as well
as external peripherals (external to the Cortex-M3 processor); the Cortex-M3
allows chip vendors to add additional on-chip APB peripherals on this private
peripheral bus via an APB interface
The NVIC is located in a memory region called the system control space (SCS). Besides
providing interrupt control features, this region also provides the control registers for
SYS- TICK, MPU, and code debugging control.
The remaining unused vendor-specific memory range can be accessed via the system bus
interface.
However, instruction execution in this region is not allowed.
The Cortex-M3 processor also comes with an optional MPU. Chip manufacturers can
decide whether to include the MPU in their products.
Similarly, bit-band support can simplify application code if we need to read a bit in a
memory location. For example, if we need to determine bit 2 of address 0x20000000,
THE BUILT-IN NESTED VECTORED INTERRUPT CONTROLLER:
The Cortex-M3 processor includes an interrupt controller called the Nested Vectored
Interrupt Controller (NVIC). It is closely coupled to the processor core and provides a
number of features as follows:
The NVIC provides nested interrupt support. All the external interrupts and most of the
system exceptions can be programmed to different priority levels. When an interrupt
occurs, the NVIC compares the priority of this interrupt to the current running priority
level. If the priority of the new interrupt is higher than the current level, the interrupt
handler of the new interrupt will override the current running task.
The Cortex-M3 processor has vectored interrupt support. When an interrupt is accepted,
the starting address of the interrupt service routine (ISR) is located from a vector table in
memory. There is no need to use software to determine and branch to the starting address
of the ISR. Thus, it takes less time to process the interrupt request.
Priority levels of interrupts can be changed by software during run time. Interrupts that
are being serviced are blocked from further activation until the ISR is completed, so their
priority can be changed without risk of accidental re entry.
The Cortex-M3 processor also includes a number of advanced features to lower the
interrupt latency. These include automatic saving and restoring some register contents,
reducing delay in switching from one ISR to another, and handling of late arrival
interrupts.
Interrupt Masking:
Interrupts and system exceptions can be masked based on their priority level or masked
completely using the interrupt masking registers BASEPRI, PRIMASK, and
FAULTMASK. They can be used to ensure that time-critical tasks can be finished on
time without being interrupted.
EXCEPTIONS :
In the Cortex-M3, besides normal software-controlled stack PUSH and POP, the
stack PUSH and POP operations are also carried out automatically when entering or
exiting an exception/interrupt handler.
Basic Operations of the Stack :
The SP is adjusted automatically in PUSH and POP so that multiple data PUSH
will not cause old stacked data to be erased.
The function of the stack is to store register contents in memory so that they can
be restored later, after a processing task is completed. For normal uses, for each store
(PUSH), there must be a corresponding read (POP), and the address of the POP operation
should match that of the PUSH operation. When PUSH/POP instructions are used, the SP
is incremented/decremented automatically.
When program control returns to the main program, the R0–R2 contents are the
same as before. Notice the order of PUSH and POP: The POP order must be the reverse
of PUSH.
For POP operations, the data is read from the memory location pointer by SP, and
then, the SP is incremented. The contents in the memory location are unchanged but will
be overwritten when the next PUSH operation takes place.
Because each PUSH/POP operation transfers 4 bytes of data (each register
contains 1 word, or 4 bytes), the SP decrements/increments by 4 at a time or a multiple of
4 if more than 1 register is pushed or popped.
The Two-Stack Model in the Cortex-M3 :
The Cortex-M3 has two SPs: 1. SP_main and 2. SP_Process. The SP register to
be used is controlled by the control register bit 1.
When CONTROL[1] is 0, the SP_main is used for both thread mode and handler
mode. In this arrangement, the main program and the exception handlers share the same
stack memory region. This is the default setting after power-up.
When the CONTROL[1] is 1, the SP_Process is used in thread mode. In this
arrangement, the main program and the exception handler can have separate stack
memory regions.
CONTROL[1]=1: Thread Level Uses Process Stack and Handler Uses Main Stack.
INSTRUCTION SET :
Some of the changes used to reduce the length of the instructions from 32 bits to 16 bits:
reduce the number of bits used to identify the register o less number of registers can
be used
reduce the number of bits used for the immediate value o smaller number range
remove options such as ‘S’ o make it default for some instructions
remove conditional fields (N, Z, V, C)
no conditional executions (except branch)
remove the optional shift (and no barrel shifter operation o introduce dedicated shift
instructions
remove some of the instructions o more restricted coding
REGISTERS:
ARM CORTEX-M3 has 13 General Purpose Registers which is divided into two
sections.(i) Low Registers (ii) High Registers. These registers are used for data handling
purposes. Low registers are from R0 to R7 and High registers are from R8 to R12.
R13 – This register is called Stack Pointer register. It is also called banked register
since, there are two registers but one register is visible to the user. The two stack registers are
SP_main and SP_Process.
The default stack is SP_main, which will be only used by Handler mode. Both
SP_process and SP_main can be handled by Thread mode based on the programming.
R14 – It is called Link Register. When Interrupt occurs, the return address will be
stored in Link register and the program counter will move to the ISR. Other than interruption,
this register acts as a normal General purpose registers.
R15 – It is called Program Counter. It is used to store the address of the next
instruction that has to be fetched.
Special Registers:
The Cortex-M3 processor also has a number of special registers.
Program Status registers (PSRs)
Interrupt Mask registers (PRIMASK, FAULTMASK, and BASEPRI)
Control register (CONTROL)
These registers have special functions and can be accessed only by special instructions. They
cannot be used for normal data processing.
Carry/borrow flag:
Carry/borrow flag: Carry/borrow flag:
1 = carry or borrow
[29] C 1C= carry or borrow 1 = carry or borrow
0 = no carry or borrow.
0 = no carry or borrow.
0 = no carry or borrow.
Overflow flag:
Overflow flag:
1 = overflow
[28] V V 1 = overflow
0 = no overflow.
0 = no overflow.
[26:0] -
Reserved.
INTERRUPT PSR:
The Interrupt PSR (IPSR) contains the Interrupt Service Routine (ISR)
number of the current exception activation.
Base level = 0
NMI = 2
SVCall = 11
INTISR[0] = 16
INTISR[1] = 17
INTISR[15] = 31
INTISR[239] = 255
EXECUTION PSR:
[31:27] - - Reserved.
Reserved
Interruptible-continuable
instruction bits. When an
interrupt occurs during an
LDM or STM operation, the
multiple operation stops
temporarily. The EPSR uses
bits [15:12] to store the
number of the next register
ICI
[26:25], [15:10] operand in the multiple
operation. After servicing the
interrupt, the processor
returns to the register pointed
to by [15:12] and resumes
the multiple operation. If the
ICI field points to a register
that is not in the register list
of the instruction, the
processor continues with the
next register in the list, if any.
If-Then bits. These are the
execution state bits of the If-
[26:25], [15:10] Then instruction. They
IT
contain the number of
instructions in the if-then
block and the conditions for
their execution.
The T-bit can be cleared using
an interworking instruction
where bit [0] of the written PC
is 0. It can also be cleared by
unstacking from an exception
[24] where the stacked T bit is 0.
T
[23:16] - Reserved.
[9:0] - Reserved.