Professional Documents
Culture Documents
2. Shibu K V, ―Introduction to
Embedded Systems‖, Tata McGraw Hill
Education Private Limited, 2009.
Module-1
ARM-32 bit Microcontroller:
Thumb-2 technology and applications of
ARM, Architecture of ARM Cortex M3,
Various Units in the architecture,
Debugging support, General Purpose
Registers, Special Registers, exceptions,
interrupts, stack operation, reset sequence
(Text 1: Ch 1, 2, 3)
How ARM cortex-M3 formed?
The engineers from ARM’s own tool chain
division joined forces with CPU designers to
form a team that would rationalize, simplify,
and improve the ARM7TDMI processor
design.
The result of this combination, the ARM
Cortex™-M3, represents an exciting
development to the original ARM
architecture.
What is the ARM CORTEX-M3 PROCESSOR?
Features include
• 512 kB of flash memory,
• 64 kB of data memory
The on-chip peripheral components of
LPC1768 include
• Ethernet MAC
• USB interface
• 8-channel general purpose DMA controller
• 4-UARTs
• 2-CAN channels, 2-SSP controllers
• 3-I2C interfaces
• SPI interface
• 8 channel 12-bit ADC, 10-bit DAC
• Motor control PWM
• Quadrature Encoder Interface
• 4-general purpose timers
• WatchDog Timer (WDT)
• 6-output general purpose PWM
• Ultra-low power RTC with separate battery
supply
• Up to 70 general purpose IO (GPIO) pins.
It supports the operating system like
• Windows
• LINUX
• Palm OS and etc.
Assembler Language Instructions Description:
Moving Data
One of the most basic functions in a processor is
transfer of data. In the Cortex-M3, data transfers can
be of one of the following types:
•Moving data between register and register
•Moving data between memory and register
•Moving data between special register and register
•Moving an immediate data value into a register
The command to move data between registers is
MOV (move). For example, moving data from register
R6 to register R9 looks like this:
MOV R9, R6
Another instruction can generate the negative value
(NOT) of the original data; it is called MVN (move
negative).
The basic instructions for accessing memory are Load
and Store.
•Load (LDR) transfers data from memory to registers.
•Store (STR) transfers data from registers to memory.
•The transfers can be in different data sizes (byte, half
word, word, and double word).
•Multiple Load and Store operations can be combined
into single instructions called LDM (Load Multiple)
and STM (Store Multiple).
ARM processors also support memory accesses with
preindexing and postindexing.
•For preindexing, the register holding the memory
address is adjusted.
•The memory transfer then takes place with the
updated address. e.g.,
LDR.W R0,[R1, #offset]! ; Read memory[R1+offset], ;
update R1 to R1+offset.
•The use of the “!” indicates the update of base
register R1. The “!” is optional; without it, the
instruction would be just a normal memory transfer
with offset from a base address.
•The preindexing memory access instructions include
load and store instructions of various transfer sizes.
Postindexing memory access instructions carry
out the memory transfer using the base address
specified by the register and then update the
address register afterward.
For example
LDR.W R0,[R1], #offset ; Read memory[R1], with
R1 ; updated to R1+offset
•When a postindexing instruction is used,
there is no need to use the “!” sign, because
all postindexing instructions update the base
address register.
•Whereas in preindexing you might choose
whether to update the base address register
or not.
Two other types of memory operation are stack
PUSH and stack POP.
The Cortex-M3 has a number of special
registers. To access these registers, we use the
instructions MRS and MSR. For example,
MRS R0, PSR ; Read Processor status word
into R0
MSR CONTROL, R1 ; Write value of R1 into
control register.
Moving immediate data into a register:
For small values (8 bits or less), we can use
MOVS (move)
MOVS R0, #0x12 ; Set R0 to 0x12
For a larger value (over 8 bits), you might need
to use a Thumb-2 move instruction.
For example
MOVW.W R0, #0x789A ; Set R0 to 0x789A
Or if the value is 32-bit, you can use two
instructions to set the upper and lower halves:
MOVW.W R0,#0x789A ; Set R0 lower half to
0x789A
MOVT.W R0,#0x3456 ; Set R0 upper half to
0x3456
Hence, R0=0x3456789A
•Alternatively, you can also use LDR (a pseudo-
instruction provided in ARM assembler).
e.g.,
LDR R0, =0x3456789A
This is not a real assembler command, but the
ARM assembler will convert it into a PC relative
load instruction to produce the required data.
To generate 32-bit immediate data, using LDR is
recommended rather than the MOVW.W and
MOVT.W combination because it gives better
readability and the assembler might be able to
reduce the memory being used if the same
immediate data are reused in several places of
the same program.
IF-THEN (IT) Examples
ITTE NE ; Next 3 instructions are conditional.
ANDNE R0, R0, R1
ADDSNE R2, R2, #1
MOVEQ R2, R3 ; Conditional move.
---------------------------------------------------
CMP R0, #9
ITE GT ; Next 2 instructions are conditional.
ADDGT R1, R0, #55
ADDLE R1, R0, #48
IT GT ; IT block with only one conditional
;instruction.
ADDGT R1, R1, #1 ; Increment R1 conditionally.
---------------------------------------------------------------
ITTEE EQ ; Next 4 instructions are conditional.
MOVEQ R0, R1 ; Conditional move.
ADDEQ R2, R2, #10 ; Conditional add.
ANDNE R3, R3, #1 ; Conditional AND.
BNE.W label ;
•To ensure a consistent memory view, it is
architecturally defined that software must
perform a Data Memory Barrier (DMB)
operation.
•DMB ensures ordering of memory accesses.
•The DMB instruction ensures that all explicit
data memory transfers before the DMB are
completed before any subsequent explicit data
memory transactions after the DMB starts. This
ensures correct ordering between two memory
accesses.
Saturation operations
Syntax
TST{cond} Rn, Operand2
TEQ{cond} Rn, Operand2