mpmc unit-5 final
mpmc unit-5 final
The Cortex-M3 processor has registers R0 through R15 ,R13 (the stack pointer) is banked, with
only one copy of the R13 visible at a time
R0–R12: General-Purpose Registers R0–R12 are 32-bit general-purpose registers for data
operations. Some 16-bit Thumb® instructions can only access a subset of these registers (low
registers, R0–R7)
R13: Stack Pointers The Cortex-M3 contains two stack pointers (R13). They are banked so that
only one is visible at a time. The two stack pointers are as follows:
Main Stack Pointer (MSP): The default stack pointer, used by the operating system (OS) kernel
and exception handlers
Process Stack Pointer (PSP): Used by user application code The lowest 2 bits of the stack
pointers are always 0, which means they are always word aligned
R14: The Link Register When a subroutine is called, the return address is stored in the link
register.
R15: The Program Counter The program counter is the current program address. This register
can be written to control the program flow.
Special Registers The Cortex-M3 processor also has a number of special registers (see Figure
2.3). They are as follows:
• 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.
Cortex m3 Operation Modes:
The Cortex-M3 processor has two modes and two privilege levels. The operation modes (thread
mode and handler mode) determine whether the processor is running a normal program or
running an exception handler like an interrupt handler or system exception handler .
The privilege levels (privileged level and user level) provide a mechanism for safeguarding
memory accesses to critical regions as well as providing a basic security model. 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 separation of
privilege and user levels improves system reliability by preventing system configuration registers
from being accessed or changed by some untrusted programs. If an MPU is available, it can be
used in conjunction with privilege levels to protect critical memory locations, such as programs
and data for OSs.
The ARM Cortex-M3 processor provides various functions that enable developers to write
software for microcontrollers based on this core. These functions contribute to efficient
program execution, memory management, interrupt handling, and system control. Here are
some key functions of the ARM Cortex-M3:
1. Core Functions:
Arithmetic and Logic Unit (ALU): The Cortex-M3 processor includes an ALU that
performs arithmetic operations (addition, subtraction, multiplication, and division)
and logical operations (AND, OR, XOR, etc.) on data.
Barrel Shifter: The processor's barrel shifter allows efficient shifting and rotation
operations on data, facilitating bit manipulation and data handling.
Pipeline Architecture: The Cortex-M3 utilizes a three-stage pipeline architecture that
improves instruction throughput and efficiency by overlapping instruction fetch,
decode, and execution stages.
Thumb-2 Instruction Set: The Cortex-M3 uses the Thumb-2 instruction set
architecture, which combines 16-bit Thumb instructions for code density and 32-bit
ARM instructions for performance.
2. Memory Management:
Memory Protection Unit (MPU): The Cortex-M3 supports an optional MPU that
enables memory protection and access control by defining regions with different
attributes (read, write, execute permissions).
Stack Management: The processor provides stack operations and stack pointer
management for handling function calls, interrupts, and exception handling.
3. Interrupt Handling:
Nested Vectored Interrupt Controller (NVIC): The Cortex-M3 includes an NVIC that
manages interrupts and exceptions. It supports configurable interrupt priorities and
allows nested interrupts.
Interrupt Vector Table (IVT): The processor has an IVT that stores the addresses of
interrupt service routines (ISRs) and exception handlers.
4. System Control:
Power Management: The Cortex-M3 provides power management features, such as
clock gating and sleep modes, to optimize power consumption.
System Timer: The processor may include a system timer that generates periodic
interrupts, enabling precise timing and timekeeping functionality.
5. Debug and Trace:
Debug and Trace Unit (DWT): The Cortex-M3 processor incorporates a DWT that
provides advanced debugging and profiling capabilities, such as instruction and data
tracing, cycle counting, and event monitoring.
6. Floating-Point Unit (FPU) (optional):
Some Cortex-M3 implementations include an optional FPU for executing floating-
point operations in hardware, enhancing numerical computation performance.
Interfaces of arm cortex m3:
The ARM Cortex-M3 processor provides various interfaces to connect and communicate
with external devices and peripherals. These interfaces enable data transfer, control signals,
and communication protocols. Here are some of the commonly used interfaces supported by
the ARM Cortex-M3:
Programmers models:
the programmer's model in the ARM Cortex-M3 processor architecture defines the set of
registers and memory-mapped control registers that are used to program and control the
behavior of the processor.
To use the PIO functionality in the Cortex-M3 processor, you need to configure the GPIO
pins using the appropriate registers. The configuration process involves setting the pin
direction (input or output), the pin mode (push-pull or open-drain), and the pin speed (low,
medium, or high). Once configured, the PIO pins can be accessed and manipulated using the
GPIO register set.
In addition to PIO, the Cortex-M3 processor also supports other input/output operations, such
as serial communication (USART, SPI, I2C), analog-to-digital conversion (ADC), and
digital-to-analog conversion (DAC). These operations can be used to communicate with
external devices, read sensors, and generate analog signals.
Overall, the Cortex-M3 processor provides a flexible and powerful platform for developing
embedded systems with a wide range of input/output capabilities.
Arm cortex m3 processor programmers models
The ARM Cortex-M3 processor is a 32-bit microcontroller core designed for low-power and
high-performance applications. It is widely used in embedded systems, especially in
microcontrollers and other similar devices. There are various models of ARM Cortex-M3
processors available in the market, with different features and specifications. Some popular
models include:
Programmers working with ARM Cortex-M3 processors can use various software tools to
develop and debug their code. Some popular software tools include:
1. Keil µVision IDE: This is a popular Integrated Development Environment (IDE) for ARM
Cortex-M processors. It includes a code editor, compiler, linker, debugger, and other useful
tools.
2. GNU Toolchain for ARM: This is a collection of open-source software tools for developing
and debugging software for ARM processors. It includes a C/C++ compiler, assembler,
linker, debugger, and other utilities.
3. IAR Embedded Workbench: This is a commercial IDE for ARM Cortex-M processors. It
includes a code editor, compiler, linker, debugger, and other tools for developing and
debugging embedded software.
4. Atmel Studio: This is an IDE for developing software for Atmel microcontrollers, including
those based on ARM Cortex-M processors. It includes a code editor, compiler, linker,
debugger, and other useful tools.
The stack pointer is typically initialized at system startup to point to the top of the available
memory region reserved for the stack. As data is pushed onto the stack, the stack pointer is
decremented, and as data is popped off the stack, the stack pointer is incremented.
Here's an example of how to use the stack and stack pointer in ARM Cortex-M3 assembly
language programming:
a value onto
the stack PUSH {r0} ; Push multiple values onto the stack PUSH {r1-r3} ; Pop a value off
the stack POP {r0} ; Pop multiple values off the stack POP {r1-r3}
In this example, the MOV instruction initializes the stack pointer to the address 0x20001000.
The PUSH instruction pushes a value or multiple values onto the stack, and the POP
instruction pops a value or multiple values off the stack. The {} notation is used to specify the
registers to push or pop. When pushing or popping multiple registers, the registers are listed
in order of decreasing register number.
It's important to note that the stack grows downward in memory, so as data is pushed onto the
stack, the stack pointer is decremented. It's also important to ensure that there is enough
memory allocated for the stack to avoid stack overflow issues.
program
In this example, the my_subroutine subroutine is defined using a label. The subroutine code
is executed when it's called using the BL (branch-and-link) instruction. The BL instruction
saves the return address on the stack and branches to the address of the subroutine. The BX
instruction is used to return to the calling function. The lr (link register) is a register that
holds the return address when a subroutine is called.
The main function calls the my_subroutine subroutine using the BL instruction. After the
subroutine returns, the program continues to execute the code after the BL instruction.
It's important to note that subroutines should always save the registers they modify on the
stack and restore them before returning to the calling function. This ensures that the calling
function's state is preserved and avoids unexpected behavior.
In this example, the my_subroutine subroutine takes two parameters, which are passed in
registers r0 and r1. The ADD instruction adds the two parameters and stores the result in
register r2. The BX instruction is used to return to the calling function.
The main function sets the values of the two parameters using the MOV instruction, and then
calls the my_subroutine subroutine using the BL instruction. After the subroutine returns,
the program continues to execute the code after the BL instruction.
It's important to note that the registers used for parameter passing should be saved by the
subroutine if they are modified, to ensure that the calling function's state is preserved and to
avoid unexpected behavior. Additionally, if the number of parameters passed in registers
exceeds the number of available registers, parameters can also be passed on the stack.