SlideShare a Scribd company logo
1 of 135
ARM Cortex M3 Instruction Sets
and Programming
Prof. Amogha B
Asst. Prof.
JIT, Davangere.
Why Assembler
5/22/2018 Dept. of ECE, JIT, DVG 2
• Most industrial microcontroller users program
in assembly language
• Many MC users will continue to program in
assembly they need the detailed control flow
• Many application require the efficiency of
assembly language
• Understanding the assembly helps in
evaluating high level language.
Outline
• Assembly basics, Instruction
• List and description,
• Useful instructions,
• Assembly and C language Programming
5/22/2018 3Dept. of ECE, JIT, DVG
Introduction
• It focus on the various instruction set of
CORTEX M3 and example for each
5/22/2018 4Dept. of ECE, JIT, DVG
Assembly Basics
• The basic syntax should be clearly understood before
writing the programs
• Common syntax is
– Label opcode operand1, operand2,…… ; comments
• Label is optional for every instruction
– Address of instruction are identified by label.
• Opcode – a high level English word for user and
machine level code for computers
• Normally first operand is destination and it depends on
instruction.
• Number of operands are dependant on instruction.
5/22/2018 5Dept. of ECE, JIT, DVG
Example moving a immediate data
• Mov r0, #0x12 ; after execution r0 = 0x12 (H)
• Mov r1,#’A’ ; after execution r1= ASCII value.
– While passing ASCII inside codes or 0xA is good
• The text after ; is considered as comments
which doesn’t effect the execution which
helps the user to understand the code in
better way.
5/22/2018 Dept. of ECE, JIT, DVG 6
EQU
• It is used to define the constants and they can
be used inside the program.
• Example : keil
5/22/2018 Dept. of ECE, JIT, DVG 7
DCB, DCD
• Constants are stored in the literal pool
– Literal pool means a portion of memory
embedded in the code to hold constant values
– Constant values are placed at the address near to
end
• DCB – define constant byte to store characters
• DCD- define constant data in binary format
• Example
5/22/2018 Dept. of ECE, JIT, DVG 8
Use of Suffixes
• In assembler for ARM processors, instructions can
be followed by suffixes.
• In Cortex M3 the conditional execution suffixes
are usually used for branch instructions.
• The suffixes are
– S – Update Application Program Status Register (APSR)
ex: ADDS R0, R1; updates APSR
– EQ, NE, LT , GT – conditional execution
• ex: BEQ <Label> ; Branch if equal.
5/22/2018 Dept. of ECE, JIT, DVG 9
Simple Addition Program
• 10+9+8+7+6+5+4+3+2+1+0
• 1+2+3+4+5+6+7+8+9+10
5/22/2018 Dept. of ECE, JIT, DVG 10
Unified Assembler Language (UAL)
• For easy porting between the thumb and ARM
code the UAL made a common syntax
– Traditional Thumb instruction : ADD R0, R1 ;
– UAL syntax : ADD R0, R1, R1; R0 = R0+R1
• Thumb syntax can be used, in assembly
directive to make differentiate between the
thumb and UAL syntax are mentioned.
– CODE 16 – traditional Thumb
– THUMB – UAL syntax
5/22/2018 Dept. of ECE, JIT, DVG 11
Conti.
• Developer should be careful while using
Traditional thumb as some updates APSR
• Where as in UAL syntax if S is used then only it
updates the APSR
– AND R0, R1 ; Traditional Thumb syntax
– ANDS R0, R0, R1 ; Equivalent UAL syntax (S suffix is
added)
5/22/2018 Dept. of ECE, JIT, DVG 12
Some instruction can done in THUMB
and THUMB-2
• The .W (wide) suffix specifies a 32-bit instruction.
If no suffix is given, the assembler tool can
choose either instruction but usually defaults to
16-bit Thumb code to get a smaller size
– ADDS R0, #1 ; Use 16-bit Thumb instruction by
default ; for smaller size
– ADDS.N R0, #1 ; Use 16-bit Thumb instruction
(N=Narrow)
– ADDS.W R0, #1 ; Use 32-bit Thumb-2 instruction
(W=wide)
5/22/2018 Dept. of ECE, JIT, DVG 13
Conti.
• In C compliers will use 16 bit instructions if data
size is less and switches to thumb2 if exceeds
• R0 – R7 can be accessed by thumb
• No limitations for register accessing for thumb 2
• Location for thumb 2 and thumb
– 0x1000 : LDR r0,[r1] ;a 16-bit instructions (occupy
0x1000-0x1001)
– 0x1002 : RBIT.W r0 ;a 32-bit Thumb-2 instruction
(occupy; 0x1002-0x1005) – 4 bytes
5/22/2018 Dept. of ECE, JIT, DVG 14
Instruction List
• 16 Bit Data Processing Instruction
• ADDITION
– ADC
– ADD
– ADR
• Compare
– CMP
– CMN- compare negative compare one data with two’s
complement of another data and update flags
5/22/2018 Dept. of ECE, JIT, DVG 15
Instructions
• AND
• BIC performs an AND operation on the bits
in Rn with the complements of the
corresponding bits in the value of Operand2.
• CPY – copy instruction same as mov i.e data
transfer between two register
• MVN – perform not operation
• NEG- 2’s compliment
5/22/2018 Dept. of ECE, JIT, DVG 16
16 Bit Data Processing Instruction
5/22/2018 Dept. of ECE, JIT, DVG 17
Branch Instruction
• B Branch
• B<cond> Conditional branch
• BL Branch with link; call a subroutine and store the
return address in LR (this is actually
• a 32-bit instruction, but it is also available in Thumb in
traditional ARM processors)
• BLX Branch with link and change state (BLX <reg> only)
• BX <reg> Branch with exchange state
• CBZ Compare and branch if zero (architecture v7)
• CBNZ Compare and branch if nonzero (architecture v7)
• IT IF-THEN (architecture v7) – in next slides will see this
5/22/2018 Dept. of ECE, JIT, DVG 18
CBZ AND CBNZ
• The branch destination must be within 4 to 130 bytes
after the instruction and in the same execution state.
• These instructions must not be used inside an IT block.
• Condition flags
– These instructions do not change the flags.
• Architectures
– These 16-bit Thumb instructions are available in ARMv6T2
and above.
– There are no ARM or 32-bit Thumb versions of these
instructions.
5/22/2018 Dept. of ECE, JIT, DVG 19
CBZ
• Same as
– CMP R0, #0
– BEQ LABEL
5/22/2018 Dept. of ECE, JIT, DVG 20
5/22/2018 Dept. of ECE, JIT, DVG 21
16 BIT LOAD AND STORE INSTRUCTION
• LDR Load word from memory to register
• LDRH Load half word from memory to register
• LDRB Load byte from memory to register
• LDRSH Load half word from memory, sign extend it, and put it in
register
• LDRSB Load byte from memory, sign extend it, and put it in register
• STR Store word from register to memory
• STRH Store half word from register to memory
• STRB Store byte from register to memory (Only LSB)
• LDM/LDMIA Load multiple/Load multiple increment after
• STM/STMIA Store multiple/Store multiple increment after
• PUSH Push multiple registers
• POP Pop multiple registers
5/22/2018 Dept. of ECE, JIT, DVG 22
Other 16 bit Instruction
• SVC Supervisor call
• SEV Send event
• WFE Sleep and wait for event
• WFI Sleep and wait for interrupt
• BKPT
– Breakpoint; if debug is enabled, it will enter debug mode(halted), or if debug
monitor exception is enabled, it will invoke the debug exception; otherwise, it
will invoke a fault exception
• NOP No operation
• CPSIE
– Enable PRIMASK (CPSIE i)/FAULTMASK (CPSIE f ) register (set the register to 0)
• CPSID
– Disable PRIMASK (CPSID i)/ FAULTMASK (CPSID f ) register (set the register to1)
5/22/2018 Dept. of ECE, JIT, DVG 23
32 bit Data processing
• PDF on Desktop
• UXTB – unsigned extend byte
– B- byte for 16 bit
• UXTH – unsigned extend half word
• UBFX - Signed and Unsigned Bit Field Extract.
– Copies adjacent bits from one register into the least significant bits of a
second register, and sign extends or zero extends to 32 bits.
• UBFX/SBFX{cond} Rd, Rn, #lsb, #width
• USAT – saturates to in range of unsigned number
• LDREX
– If the physical address has the Shared TLB attribute, LDREX tags the physical
address as exclusive access for the current processor, and clears any exclusive
access tag for this processor for any other physical address.
5/22/2018 Dept. of ECE, JIT, DVG 24
Unsupported Thumb Instructions
• Unsupported instructions are
– Coprocessor are not supported
– The two instructions that cortex M3 doesn’t
support are BLX, SETEND
– Unsupported Change Process State Instruction
• If these are invoked a usage fault exceptions
will generate.
5/22/2018 Dept. of ECE, JIT, DVG 25
Unsupported Thumb Instructions
• BLX label
– This is branch with link and exchange state. In a format
with immediate data, BLX always changes to ARM state.
Because the Cortex-M3 does not support the ARM state,
instructions like this one that attempt to switch to the
ARM state will result in a fault exception called usage fault.
• SETEND
– This Thumb instruction, introduced in architecture v6,
switches the endian configuration during run time. Since
the Cortex-M3 does not support dynamic endian, using the
SETEND instruction will result in a fault exception.
5/22/2018 Dept. of ECE, JIT, DVG 26
Unsupported Co-Processor
• MCR Move to coprocessor from ARM processor
• MCR2 Move to coprocessor from ARM processor
• MCRR Move to coprocessor from two ARM register
• MRC Move to ARM register from coprocessor
• MRC2 Move to ARM register from coprocessor
• MRRC Move to two ARM registers from coprocessor
• LDC Load coprocessor; load memory data from a
sequence of consecutive memory addresses to a
coprocessor
• STC Store coprocessor; stores data from a coprocessor
to a sequence of consecutive memory addresses
5/22/2018 Dept. of ECE, JIT, DVG 27
Unsupported Change Process State
Instructions
• CPS<IE|ID>.W A There is no A bit in the Cortex-
M3
• CPS.W #mode There is no mode bit in the Cortex-
M3 PSR
– A- abort
– I- interrupt
– T- Thumb state
C:UsersAmoghaDesktopProgram+Status+Registers
.jpg
5/22/2018 Dept. of ECE, JIT, DVG 28
Unsupported Hint Instructions
• Used in the place of below instruction
– NOP, WFE, WFI, YIELD, SEV-set event
• DBG A hint instruction to debug and trace system
• PLD Preload data; no cache on cortex M3
• PLI Preload instruction; no cache on cortex M3
• YIELD
– A hint instruction to allow multithreading software to
indicate to hardware that it is doing a task that can be
swapped out to improve overall system performance.
5/22/2018 Dept. of ECE, JIT, DVG 29
Instruction Descriptions
• Moving Data
– 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
5/22/2018 Dept. of ECE, JIT, DVG 30
Moving data between register
• The instruction used is MOV
– MOV R5,R3 ; R3 contents are moved to R5
• If need to generate negative value of original
data is MVN
5/22/2018 Dept. of ECE, JIT, DVG 31
Moving an Immediate data Value to
Register
• The instruction used is MOV
• MOV R0,#0x123
– Important thing is the immediate value should be
less than 16 bits
5/22/2018 Dept. of ECE, JIT, DVG 32
LOAD / STORE instruction
• Load from memory to register
• STORE- register to Memory
5/22/2018 Dept. of ECE, JIT, DVG 33
Pre and post Indexing of memory
5/22/2018 Dept. of ECE, JIT, DVG 34
Moving data between memory and
register
• The instruction used for performing this are
LOAD and STORE
– LOAD (LDR)
– STORE (STR)
• The transfer of data is of different data size
– Byte, half word, word etc
• Multiple data are combined and
stored/accessed from memory
5/22/2018 Dept. of ECE, JIT, DVG 35
Move of special register to register
• MSR
– MOV xPSR,R0
• MRS
– MOV R0,APSR
5/22/2018 Dept. of ECE, JIT, DVG 36
Processing DATA
• There are many data processing operations in
cortex M3, can have multiple instruction
formats
– Ex: ADD; instruction can operate between two
registers or between one register and an
immediate data value
– ADD R0, R0, R1 ; R0 = R0 + R1
– ADDS R0, R0, #0x12 ; R0 = R0 + 0x12
– ADD.W R0, R1, R2 ; R0 = R1 + R2
5/22/2018 Dept. of ECE, JIT, DVG 37
Traditional Thumb and Thumb2
• The only difference between them are
– Traditional thumb instruction updates flag without
specifying by user
– Thumb2 if user specified then only those
instructions can update flags.
5/22/2018 Dept. of ECE, JIT, DVG 38
Instruction Operation
ADD RD, RN,RM ; RD=RN+RM Perform addition
ADD Rd, #immed ; Rd = Rd + #immed
ADD Rd, Rn, # immed ; Rd = Rn + #immed
ADC Rd, Rn, Rm ; Rd = Rn + Rm + carry
ADC Rd, Rd, Rm ; Rd = Rd + Rm + carry
Addition with carry
ADDW Rd, Rn, #immed ; Rd = Rn +
#immed
ADD register with 12-bit immediate value
Same for subtraction immediate, subtract
with barrow SUB, SBC,
SUB Rd, Rn, Rm ; Rd= Rn -Rm Subtract
RSB.W Rd, Rn, Rm ; Rd = Rm – Rn Reverse Subtract
MUL Rd, Rn, Rm ; Rd = Rn*Rm Multiply
UDIV Rd, Rn, Rm Division for unsigned division SDIV -signed
5/22/2018 Dept. of ECE, JIT, DVG 39
Other instruction
• Multiplication – signed and unsigned
• Logic operation –
– AND, ORRR, EOR(EX-OR), BIC(Bit clear)
• Shift and rotate
– Logical Shift Left
– Logical Shift Right
– Rotate Right
– Arithmetic Shift Right (ASR)
5/22/2018 Dept. of ECE, JIT, DVG 40
Shift and Rotate
5/22/2018 Dept. of ECE, JIT, DVG 41
• ASR It copies the sign bit into vacated bit positions on
the left.
• LSL provides the value of a register multiplied by a
power of two.
• LSR provides the unsigned value of a register divided
by a variable power of two. Both instructions insert
zeros into the vacated bit positions.
• ROR provides the value of the contents of a register
rotated by a value. The bits that are rotated off the
right end are inserted into the vacated bit positions on
the left.
• RRX provides the value of the contents of a register
shifted right one bit. The old carry flag is shifted into
bit[31]. If the S suffix is present, the old bit[0] is placed
in the carry flag.
5/22/2018 Dept. of ECE, JIT, DVG 42
Logical Operations
• AND gate
– AND Rd, Rn ; Rd = Rd & Rn
– AND.W Rd, Rn, Rm ; Rd = Rn & Rd for 32 bit
• OR gate
– ORR Rd, Rn ; Rd = Rd | Rn
– ORR.W Rd, Rn, Rm ; Rd = Rn | Rd
• Bit clear and Exor gate
– BIC Rd, Rn ; Rd = Rd & (~Rn)
– EOR Rd, Rn ; Rd = Rd ^ Rn
• Bit wise OR and NOT
– ORN.W Rd, Rn,#immed ; Rd = Rn | (~#immed)
5/22/2018 Dept. of ECE, JIT, DVG 43
There is no ROTATE LEFT
• Only a rotate right is provided
• The rotate right can be operated as left if we
increase the rotation value.
5/22/2018 Dept. of ECE, JIT, DVG 44
Sign Extend Instruction
Instruction Operation
SXTB Rd, Rm ; Rd = signext(Rm[7:0]) Sign extend byte data into word
SXTH Rd, Rm ; Rd = signext(Rm[15:0]) Sign extend half word data into word
5/22/2018 Dept. of ECE, JIT, DVG 45
Reverse Operation
5/22/2018 Dept. of ECE, JIT, DVG 46
Call and Unconditional Branch
• Posses three statements
– Branch with label ex: B label
– Branch to specified address: BX REG
– Branch to link : BL
5/22/2018 Dept. of ECE, JIT, DVG 47
Decisions and Conditional Branches
• Flags
– N- Negative
– Z- zero
– C- carry This flag is for unsigned data processing for
example, in add (ADD) it is set when an overflow
occurs; in subtract (SUB) it is set when a borrow did
not occur (borrow is the invert of carry)
– V- Over flow
• BEQ label or BEQ.W label; branch to label address
when zero flag is set
5/22/2018 Dept. of ECE, JIT, DVG 48
Symbol Condition Flag
CS/HS Carry set/unsigned higher or same C –set
CC/LO Carry clear/unsigned lower C – clear
MI Minus/negative N- set
PL Plus/Positive or zero N-clear
VS Overflow V-set
VC No overflow V-clear
HI Unsigned higher C- set and Z clear
LS Unsigned Lower or same C-clear or Z set
GE Signed greater than or equal N set and V set, or N clear and V clear (N
== V)
LT Signed Les than N set and V clear, or N clear and V set (N
!= V)
GT Signed Greater than Z clear, and either N set and V set, or N
clear and
V clear (Z == 0, N == V)
LE Signed Less than or equal Z set, or N set and V clear, or N clear and
V set (Z == 1 or N != V)
AL/
EQ/NE
Always( Un-conditional), equal and not
equal5/22/2018 Dept. of ECE, JIT, DVG 49
TST
• TEST instruction is same as AND, it performs
AND, updates flags but doesn’t store results.
– TST R0, R1 ; Calculate R0 AND R1 and update
flag
– TST R0, #0x12 ; Calculate R0 AND 0x12 and update
flag
5/22/2018 Dept. of ECE, JIT, DVG 50
Syntax for IT (TRUE- THEN-ELSE)
• IT<x><y><z> <cond>; IT instruction (<x>, <y>, ; <z> can be T or E)
• instr1<cond> <operands> ; 1 instruction (<cond> ; must be same as
IT)
• instr2<cond or not cond> <operands> ; 2 instruction (can be ; <cond> oe
<!cond>
• instr3<cond or not cond> <operands> ; 3 instruction (can be ;<cond> or
<!cond>
• instr4<cond or not cond> <operands> ; 4instruction (can be ; <cond> or
<!cond>
5/22/2018 Dept. of ECE, JIT, DVG 51
Program on IT
• Less than 4 instructions are executed and
minimum is 1.
• The number of instructions should be maintained
• During exception
– Single IT – exception are stored in PSR and pop when
exception is served
– Multiple instructions ( multiple load and store) the
whole instructions are abandoned and restarted( 1st IT
instruction) after interrupt process is completed.
5/22/2018 Dept. of ECE, JIT, DVG 52
Memory Barrier
• Avoids occurring of race conditions during
memory errors.
• Whenever the memory misses in cache previous
controller will wait till the memory corrects but
now if the result of present line is not dependent
on next instruction then the ARM will proceed for
executing the next line
– Ex: LDR r0, [r1] if error occurs in load
– STR r2,[r5] here store isn't depending on load hence
arm executes the same.
5/22/2018 Dept. of ECE, JIT, DVG 53
Registers for Memory Barrier
• DMB Data memory barrier; ensures that all
memory accesses are completed before new
memory access is committed
• DSB Data synchronization barrier; ensures that all
memory accesses are completed before next
instruction is executed
• ISB Instruction synchronization barrier; flushes
the pipeline and ensures that all previous
instructions are completed before executing new
instructions
5/22/2018 Dept. of ECE, JIT, DVG 54
Saturation Operations
5/22/2018 Dept. of ECE, JIT, DVG 55
• SSAT.W <Rd>, #<immed>, <Rn>, {,<shift>}
Saturation for signed value
• USAT.W <Rd>, #<immed>, <Rn>, {,<shift>}
Saturation for a signed value into an unsigned value
– Rn: Input value
– Shift: Shift operation for input value before
saturation; optional, can be #LSL N or #ASR N
– Immed: Bit position where the saturation is carried
out
– Rd: Destination register
5/22/2018 Dept. of ECE, JIT, DVG 56
Unsigned Saturation Operation
5/22/2018 Dept. of ECE, JIT, DVG 57
Division
• SDIV
– SDIV{cond} {Rd}, Rn, Rm
• UDIV
– The result is Rd = Rn/Rm.
• Code
• LDR R0,=300 ; Decimal 300
• MOV R1,#5
• UDIV.W R2, R0, R1
5/22/2018 Dept. of ECE, JIT, DVG 58
Divide by zero
• You can set up the DIVBYZERO bit in the NVIC
Configuration Control Register so that when a
divide by zero occurs, a fault exception (usage
fault) takes place. Otherwise, <Rd> will
become 0 if a divide by zero takes place.
5/22/2018 Dept. of ECE, JIT, DVG 59
Table Branch Byte
• Table Branch Byte (TBB) and Table Branch
Halfword (TBH) are for implementing branch
tables. The
• TBB instruction uses a branch table of byte
size offset, and TBH uses a branch table of half
word offset.
– Syntax: TBB.W [Rn, Rm]
5/22/2018 Dept. of ECE, JIT, DVG 60
Example IF-THEN-ELSE
• CMP R0, R1 ; Compare R0 and R1
• ITTE GT ; If R0 > R1 Then ; if true, first 2
statements execute,
; if false, other 1 statement is executed
• MOVGT R2, R0 ; R2 = R0
• MOVGT R3, R1 ; R3 = R1
• MOVLE R2, R0 ; Else R2 = R1
5/22/2018 Dept. of ECE, JIT, DVG 61
Program
• IT PROGRAM
• IF CONDITION IS TRUE
– Perform Three operations
• If Condition is false
– Perform two operations
• Condition be like compare R1 and R2.
– Condition is if (R1 < R2)
5/22/2018 Dept. of ECE, JIT, DVG 62
Memory System Features
• Features
– Predefined memory map for bus interface these
are enabled when memory location is accessed
– This feature allow the porting between the
processor and it is made easy
– Bit band access – each bits can be addressed using
bit-band example 0x20000004
– Unaligned transfers of data
– Supports both little endian and big endian
memory configuration
5/22/2018 Dept. of ECE, JIT, DVG 63
Memory Maps
• CORTEX M3 has the fixed memory map which
makes software porting to another product
– System peripherals (NVIC, MPU) have same
location for all CORTEX M3 hence manufactures
can differentiate with others.
– Some memory locations are reserved to private
peripherals such as debugging components.
Private peripheral memory region holds this
5/22/2018 Dept. of ECE, JIT, DVG 64
5/22/2018 Dept. of ECE, JIT, DVG 65
Private peripheral components
• Fetch patch and break point unit (FPB)
• Data watch-point and trace unit (DWT)
• Instrumentation Trace Macrocell (ITM)
• Embedded Trace Macrocell (ETM)
• Trace Port Interface Unit (TPIU)
• ROM table –
– Shows the minimum size of ROM required to contain
the image (ext. data video, audio, image). This does
not include ZI data and debug information which is
not stored in the ROM.
5/22/2018 Dept. of ECE, JIT, DVG 66
ADDRESS SPACE
• 4GB of address space
• Program code can be placed in
– Code region
– Static Random Access Memory region
– External RAM region
• Preferably the codes are placed in code
regions as data fetching can happen
simultaneously on two separate bus.
5/22/2018 Dept. of ECE, JIT, DVG 67
SRAM Memory range
• SRAM memory range is for connecting
internal SRAM, system interface bus is used for interface.
• 32 MB is defined as a bit band alias.
– A 32-bit-band alias memory range, each word
address represents a single bit in the 1-MB bit-
band region
– For altering the bit band alias we can use atomic
READ-MODIFY-WRITE.
– Bit band alias memory access works only for data
not for instruction fetches.
5/22/2018 Dept. of ECE, JIT, DVG 68
On chip peripherals
• 0.5 GB block of address range is allocated to
on-chip peripherals.
• This is also supports bit band alias for
modifying
• Instruction execution is not allowed in this
region.
5/22/2018 Dept. of ECE, JIT, DVG 69
External RAM
• Two slots of 1-GB memory space are allocated
for external RAM and external devices.
• Normally program won’t execute in memory
reserved for external device.
• If required in external RAM is attached
5/22/2018 Dept. of ECE, JIT, DVG 70
AMBA bus
• 0.5 GB at last is reserved for system level
components , internal peripheral buses, external
peripheral bus, and vendor-specific system
peripherals.
• Private peripheral bus – two segments
– Advanced high Performance Bus (AHB)- for Cortex-
M3 internal AHB peripherals only like NCIV.
– Advance Peripheral BUS (APB)- for internal APB and
external peripherals.
• A provision is provided in CORTEX M3 additional on chip APB
which is provided in private peripheral bus via APB interface.
5/22/2018 Dept. of ECE, JIT, DVG 71
System level
• The NVIC is located in a memory region called
the system control space (SCS)
– Additional interrupt control features, this region
also provides the control registers for SYSTICK,
MPU, and code debugging control.
5/22/2018 Dept. of ECE, JIT, DVG 72
• Question paper discussion
5/22/2018 Dept. of ECE, JIT, DVG 73
Yesterday
• Every peripheral is reserved by address and it
is accessible
• Bit band operation – for read write operation
5/22/2018 Dept. of ECE, JIT, DVG 74
Memory Access Attributes
• The CORTEX M3 memory attributes (Method) are
– Bufferable:
• Write to memory can be carried out by a write buffer while the
processor continues on next instruction execution. Example : UART
– Cacheable:
• Data obtained from memory read can be copied to a memory
cache so that next time it is accessed the value can be obtained
from the cache to speed up the program execution
– Executable
• Processor can execute code from this memory region
– Sharable
• Data in this memory region could be shared by multiple bus
masters
5/22/2018 Dept. of ECE, JIT, DVG 75
Memory regions of attributes
• Code Memory region (0x00000000 to 0x1FFFFFFF)
– Region is executable
– Cache is write through i.e. can have data in this
memory region
– Data is transferred using the data bus interface
– Write transfers is bufferable
5/22/2018 Dept. of ECE, JIT, DVG 76
CONTI.
• SRAM memory region (0x20000000–0x3FFFFFFF)
– Meant for on-chip RAM
– Executing the code is feasible.
– Write transfer are bufferable.
• Peripheral Region (0x40000000–0x5FFFFFFF)
– Reserved to use only by peripherals
– Can’t execute program here
• External RAM (0x60000000–0x7FFFFFFF)
– Used for on or off chip memory
– Can execute the program in this region
– Write data are bufferable
5/22/2018 Dept. of ECE, JIT, DVG 77
Conti.
• External RAM (0x80000000–0x9FFFFFFF)
– Reserved only for external devices
– Memory is non-bufferable to access
– Can’t execute code in this region
• Same for 0xC0000000–0xDFFFFFFF
• System Region (0xE0000000–0xFFFFFFFF)
– Reserved for the usage of private peripherals and
vendor specific peripherals
– For private peripherals access are non-bufferable
– Vendor specific access are bufferable
5/22/2018 Dept. of ECE, JIT, DVG 78
Default Memory Access Permission
• Prevents the user programs to access some
locations which are controlled by MPU
5/22/2018 Dept. of ECE, JIT, DVG 79
Memory
Region
Address Access in User Program
Vendor Specific 0xE0100000–0xFFFFFFFF Full access
ROM table 0xE00FF000–0xE00FFFFF Blocked ; if user tries to access a bus
fault is generated
External Private
Peripheral Bus
0xE0042000–0xE00FEFFF Blocked; if user tries to access a bus
fault is generated
ETM
(Embedded
Trace
Macrocell)
0xE0041000–0xE0041FFF Blocked; if user tries to access a bus
fault is generated
TPIU Trace Port Interface
Unit
0xE0040000–0xE0040FFF Blocked; if user tries to
access a bus fault is
generated
Internal Peripheral Private
Bus
0xE000F000–0xE003FFFF Blocked; if user tries to
access a bus fault is
generated
NVIC 0xE000E000–0xE000EFFF Blocked; if user tries to
access a bus fault is
generated
FPB 0xE0002000–0xE0003FFF Blocked; if user tries to
access a bus fault is
generated
DWT 0xE0001000–0xE0001FFF Blocked
ITM 0xE0000000–0xE0000FFF Blocked
External device 0xA0000000–0xDFFFFFFF Full Access
External RAM 0x60000000–0x9FFFFFF Full Access
Peripheral 0x40000000–0x5FFFFFFF Full Access
SRAM 0x20000000–0x3FFFFFFF Full Access
Code 0x00000000–0x1FFFFFFF Full Access5/22/2018 Dept. of ECE, JIT, DVG 80
Un-Alignment Basics
5/22/2018 Dept. of ECE, JIT, DVG 81
Programmers see memory as just a row of memory array
Process see memory in union of even numbers 4,8,16,32
Aligned access
5/22/2018 Dept. of ECE, JIT, DVG 82
Consider reading a 4 Byte
of data
Data should be aligned to
4,8,16,32 formats , if not
we are not going to get
accurate fetching
Unaligned Data access
5/22/2018 Dept. of ECE, JIT, DVG 83
UNALIGNED TRANSFERS
• Supports both unaligned and aligned access
• Traditional ARM were supporting only aligned
memory access
• 1 bytes = ?
• 8 bit
• If 32 bits – 4 bytes of memory
• 16- 2 bytes
• 8- 1 bytes
5/22/2018 Dept. of ECE, JIT, DVG 84
Example for unaligned data
5/22/2018 Dept. of ECE, JIT, DVG 85
For full word (32)
For half word (16)
Exclusive Accesses
• In CORTEX M3 we don’t have swap option
instead of it we posses exclusive access.
• Swapping was normally used in semaphores
– Semaphores are used to allocate shared resources
to applications.
– Shared source serve only one application at a time
i.e. called as Mutual Exclusion (MUTEX).
– If the resource is being locked by one process
(task), it can’t serve another process until the lock
is released
5/22/2018 Dept. of ECE, JIT, DVG 86
Conti.
• MUTEX semaphore in memory is used to
indicate whether the resource is locked or
free.
5/22/2018 Dept. of ECE, JIT, DVG 87
Working
5/22/2018 Dept. of ECE, JIT, DVG 88
Programming it
• Cortex-M3 include LDREX (word), LDREXB
(byte), LDREXH (half word), STREX (word),
STREXB (byte), and STREXH (half word
• Rxf – base register address with shifted offset
value
• LDREX <Rxf>, [Rn, #offset]
• STREX <Rd>, <Rxf>,[Rn, #offset]
5/22/2018 Dept. of ECE, JIT, DVG 89
Endian mode
• Cortex M3 supports both little endian and big
endian mode
• Little endian mode
– LSB Data = MSB of memory
– Data 0x12345678
– Address 0x40000010 – 78 56 34 12
5/22/2018 Dept. of ECE, JIT, DVG 90
Figure
5/22/2018 Dept. of ECE, JIT, DVG 91
Big Endian
– Data 0x12345678
– Address 0x40000010 – 12 34 56 78
5/22/2018 Dept. of ECE, JIT, DVG 92
Big Indian Memory Example
5/22/2018 Dept. of ECE, JIT, DVG 93
Conti.
• The endian mode is set when the processor
exits reset later it can’t be changed.
• No dynamic changing of memory mode
• If processor is in little endian, some
peripherals works on big endian means
change the format using REV, REV16
5/22/2018 Dept. of ECE, JIT, DVG 94
BIT BAND Operation
• Bit-band operation support allows a single
load/store operation to access (read/write) to
a single data bit.
• Memory regions are bit band region(1MB) and
bit band alias (32MB)
• Use of bit band is each peripheral bits can be
accessed separately in LSB.
5/22/2018 Dept. of ECE, JIT, DVG 95
Working
• If without bitband
– Access the address
– Load the changing value to another register
– Perform OR to modify bit
– Store the result to address.
• With bit-band
– Load address to register
– Load the changing value
– Store the modified value to address
5/22/2018 Dept. of ECE, JIT, DVG 96
Differences
• Without bit band
• LDR R0,=0x20000000; set address
• LDR R1,[R0] ; Read
• ORR.W R1,#0x4; modify bit
• STR R1,[R0]
• With Bit Band
• LDR R0,=0x20000008
• MOV R1,#1
• STR R1,[R0]
5/22/2018 Dept. of ECE, JIT, DVG 97
Example
5/22/2018 Dept. of ECE, JIT, DVG 98
Perform it using and not using bit band
5/22/2018 Dept. of ECE, JIT, DVG 99
Advantages
• During branch decisions on peripherals the
below task happens if not bit band is
– Reading whole register
– Masking the unwanted bits
– Comparing and branch
• These are simplified as
– Reading the status bit via bit-band alias
– Comparing and branching
5/22/2018 Dept. of ECE, JIT, DVG 100
BIT-BAND and BIT-BANG
• Bit-band to indicate that the feature is a
special memory band (region) that provides
bit accesses
• Bit bang commonly refers to driving I/O pins
under software control to provide serial
communication functions.
5/22/2018 Dept. of ECE, JIT, DVG 101
Data last when exception occurs if bit
band is not used
5/22/2018 Dept. of ECE, JIT, DVG 102
Bit band providing locking facility
during exceptions
5/22/2018 Dept. of ECE, JIT, DVG 103
Programming bitband
• #define DEVICE_REG0 *((volatile unsigned long *) (0x40000000))
• #define DEVICE_REG0_BIT0 *((volatile unsigned long *)
(0x42000000))
• #define DEVICE_REG0_BIT1 *((volatile unsigned long *)
(0x42000004)) ...
• DEVICE_REG0 = 0xAB; // Accessing the hardware register by normal
// address..
• DEVICE_REG0 = DEVICE_REG0 | 0x2; // Setting bit 1 without using
// bitband feature...
• DEVICE_REG0_BIT1 = 0x1; // Setting bit 1 using bitband feature //
via the bit band alias address
5/22/2018 Dept. of ECE, JIT, DVG 104
Development Flow
5/22/2018 Dept. of ECE, JIT, DVG 105
Flow of program
• Whenever the applications are developed using
cortex M3 it is the process.
• The concepts of code generation flow in terms of
these tools are similar
• Basic ones are
– Assembler
– C complier
– Linker
– Binary file generation utilities.
• Real View development suite (RVDS) or Real view
complier tools shows a file generation flow.
5/22/2018 Dept. of ECE, JIT, DVG 106
Flow is explained by taking C program
• Create C program
• Create vectors
• Create vector table
• Compile the file
• Use linker to link the file
• Get executable file .elf
– In Mp steps (REMEMBER MASM, LINK, CV exe)
5/22/2018 Dept. of ECE, JIT, DVG 107
To compile
• arm cc –c –g –W sample_LED.c –o
sample_LED.o
• armcc –c -g –W vectors.c –o vectors.o
• o- object file (remember MP programs)
• After MASM object files were created.
5/22/2018 Dept. of ECE, JIT, DVG 108
Linker
• LINKER used to generate the program image.
• It generates filename.scat
• scat tells the linker to put the starting address
of program into vector table
5/22/2018 Dept. of ECE, JIT, DVG 109
Linker Commands
• Armlink –scatter sample_LED.scat "--
keep=vectors.o(exceptions_area)“
sample_LED.o vectors.o sample_LED.ELF
• Executable image sample_LED.ELF is
generated
5/22/2018 Dept. of ECE, JIT, DVG 110
Execute image
• /* create binary file */
• $> fromelf –-bin sample_LED.elf –output
sample_LED.bin
• /* Create disassembly output */
• $> fromelf –c sample_LED.elf > list.txt
5/22/2018 Dept. of ECE, JIT, DVG 111
Compile in same example in Keil using
DOS
• C:KeilARMBIN40armcc -c -O3 -W -g -Otime
--device DLM vectors.c
• C:KeilARMBIN40armcc -c -O3 -W -g -Otime
--device DLM blinky.c
• C:KeilARMBIN40armlink --device DLM "--
keep=Startup.o(RESET)"
"--first=Startup.o(RESET)" -scatter led.scat --
map vectors.o blinky.o -o blinky.elf
• C:KeilARMBIN40fromelf --bin blinky.elf -o
blinky.bin
5/22/2018 Dept. of ECE, JIT, DVG 112
Accessing Memory Mapped Regions in
C
• Accessing the Peripherals using
– Volatile Pointers
– From address
– Place pointers to elements
– Scatter Loading file.
5/22/2018 Dept. of ECE, JIT, DVG 113
Accessing Peripheral Registers as
Pointers.
5/22/2018 Dept. of ECE, JIT, DVG 114
#define SYSTICK_CTRL
(*((volatile unsigned
long *) (0xE000E010)))
Alternative Way of Accessing
Peripheral Registers as Pointers.
5/22/2018 Dept. of ECE, JIT, DVG 115
Define address directly
# define SYSSTICK_CTRL
= 0xE000E010
Accessing Peripheral Registers as
Pointers to Elements in Data Structure
5/22/2018 Dept. of ECE, JIT, DVG 116
Defining Peripheral-Based Address
Using Scatter Loading File.
5/22/2018 Dept. of ECE, JIT, DVG 117
Intrinsic Function
• A built in function that is implemented directly
by the complier without making use of any
library
5/22/2018 Dept. of ECE, JIT, DVG 118
Embedded Assembler and Inline
Assembler
• Feature is provided to write the assembly
inside the C code it is called as inline
assembler.
• Format
• Type of program, return type , access
5/22/2018 Dept. of ECE, JIT, DVG 119
Interface assembly and C
• Tasks can’t performed in C coding
– Functions such as direct manipulation of stack
data or special is not possible
– Timing-critical routines
– Tight memory requirements, causing part of the
program to be written in assembly to get the
smallest memory size
5/22/2018 Dept. of ECE, JIT, DVG 120
FORMAT
• Slight change
• armasm –cpu cortex –m3 –o test1.o test1.s
• Armlink –rw_base 0x2000000 –ro_base 0x0 –
map –o test1.elf tes1.o
– Here 0x0 is the read only memory
– 0x20000000 specifies a read/write memory.
• Fromelf –bin –output test1.bin test1.elf
• Fromelf –c –output test1.list test1.elf
5/22/2018 Dept. of ECE, JIT, DVG 121
Producing Output
5/22/2018 Dept. of ECE, JIT, DVG 122
Output to console other than UART
• Semi-hoisting: we can send the output using
printf statement using debug register
• Instrumentation trace: the output is sent to
outer world using trace port analyzer
• Instrumentation trace via serial wire viewer:
other than Trace port interface unit a low cost
serial wire viewer can be used to get data
5/22/2018 Dept. of ECE, JIT, DVG 123
UART program in Assembly
• In C
• Logic ?
• CHECK LSR content
• Need to use Transmitter CHECK THR (0x20)
• IF Receive (0x01)
• RBR
• Assembly
• Load UART_FLAGS to one register and compare
with 0x20
5/22/2018 Dept. of ECE, JIT, DVG 124
All algorithm
• Main program
– Make r0 to r4 as 0
– Branch to label UART0Initialize
– Load R0 with content of variable by name NUM1
– Branch to Puts
• Puts, Putswaitloop, Putsloop exit
• Putc, Putcloop
• Uart0Intitialize label
• NUM1 deceleration
5/22/2018 Dept. of ECE, JIT, DVG 125
CMSIS – Newly added to the syllabus
CORTEX MC Software Interface
Standard
5/22/2018 Dept. of ECE, JIT, DVG 128
CORTEX M3 in embedded application
market
• By 2008, it has 5 complier vendors, more than
15 embedded Operating Systems.
• Many companies were providing hands for
embedded software solutions
– Codecs ( decoders ex: KM player some new format
of video needs to download codecs)
– Data processing libraries
– Various software and debug solutions
5/22/2018 Dept. of ECE, JIT, DVG 129
Aims of CMSIS
• Improve software portability and reusability
• Develop a products and device libraries which
works on various silicon vendors
• Easy to use and have standard interface
• Run on multiple sources without the risk of
drivers installation.
5/22/2018 Dept. of ECE, JIT, DVG 130
Organization of CMSIS
5/22/2018 Dept. of ECE, JIT, DVG 131
Layers
• Core Peripheral Access Layer- to access core
registers and core peripherals
• Middleware Access Layer
– A common method for accessing peripherals ( yet to
launch)
– Communication includes Ethernet, UART, SPI
– Software support for communication interface
• Device Peripheral Access layer (Microcontroller
unit specific)
• Access functions for peripherals (Microcontroller
unit specific)
5/22/2018 Dept. of ECE, JIT, DVG 132
CMSIS includes
5/22/2018 Dept. of ECE, JIT, DVG 133
• Core_CM3.h contains peripheral register definitions
and access functions
– NVIC, System Control Block registers and SYSTICK registers.
– Includes CMSIS intrinsic functions
– Includes a function to output debug message via
Instrumentation Trace Module.
• Core_cm3.c includes CMSIS intrinsic functions which
aren’t defined in Core_CM3.h
• System_Device.h- contains Microcontroller specific
interrupt number, exception and handlers.
• System <device.c> specific function of
microcontroller which includes system initialization.
5/22/2018 Dept. of ECE, JIT, DVG 134
Example
• #include “vendor_device.h>
– <lpc17xx.h> // NXP
– <lm3S_CMSIS.h> //Micro devices
– Stm32f10x.h // for ST devices (house hold appli.)
• SystemInit (); used for system initialize code
• Void UART1_IRQHandler - for peripherals
• Void SysTick_Handler – system handlers
5/22/2018 Dept. of ECE, JIT, DVG 135
Benefits of CMSIS
5/22/2018 Dept. of ECE, JIT, DVG 136
Thank You
• Uart_base equ 0x4000000
• Uart_flag equ uart_base+0x20
• Uart_data equ uart_base+0x40
• Area
• Mov r0,#0
• R1,r2,r3,r4
• B uart0_initilization
• BL puts
5/22/2018 Dept. of ECE, JIT, DVG 137

More Related Content

What's hot

PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.parthi_arjun
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction setv Kalairajan
 
Architecture of 8085 microprocessor
Architecture of 8085 microprocessorArchitecture of 8085 microprocessor
Architecture of 8085 microprocessorAMAN SRIVASTAVA
 
I o ports and timers of 8051
I o ports and timers of 8051I o ports and timers of 8051
I o ports and timers of 8051SARITHA REDDY
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil KawareProf. Swapnil V. Kaware
 
Embedded system Design
Embedded system DesignEmbedded system Design
Embedded system DesignAJAL A J
 
Introduction to Embedded Architecture
Introduction to Embedded Architecture Introduction to Embedded Architecture
Introduction to Embedded Architecture amrutachintawar239
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.pptDr.YNM
 
Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processorRAMPRAKASHT1
 
Embedded System Tools ppt
Embedded System Tools  pptEmbedded System Tools  ppt
Embedded System Tools pptHalai Hansika
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architectureJamia Hamdard
 
Introduction to ARM LPC2148
Introduction to ARM LPC2148Introduction to ARM LPC2148
Introduction to ARM LPC2148Veera Kumar
 
Question paper with solution the 8051 microcontroller based embedded systems...
Question paper with solution  the 8051 microcontroller based embedded systems...Question paper with solution  the 8051 microcontroller based embedded systems...
Question paper with solution the 8051 microcontroller based embedded systems...manishpatel_79
 

What's hot (20)

PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentals
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction set
 
Architecture of 8085 microprocessor
Architecture of 8085 microprocessorArchitecture of 8085 microprocessor
Architecture of 8085 microprocessor
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
I o ports and timers of 8051
I o ports and timers of 8051I o ports and timers of 8051
I o ports and timers of 8051
 
Switches and LEDs interface to the 8051 microcontroller
Switches and LEDs interface to the 8051 microcontrollerSwitches and LEDs interface to the 8051 microcontroller
Switches and LEDs interface to the 8051 microcontroller
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
Embedded system Design
Embedded system DesignEmbedded system Design
Embedded system Design
 
8051 programming in c
8051 programming in c8051 programming in c
8051 programming in c
 
Introduction to Embedded Architecture
Introduction to Embedded Architecture Introduction to Embedded Architecture
Introduction to Embedded Architecture
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processor
 
Embedded System Tools ppt
Embedded System Tools  pptEmbedded System Tools  ppt
Embedded System Tools ppt
 
Xilinx 4000 series
Xilinx 4000 seriesXilinx 4000 series
Xilinx 4000 series
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
Introduction to ARM LPC2148
Introduction to ARM LPC2148Introduction to ARM LPC2148
Introduction to ARM LPC2148
 
Question paper with solution the 8051 microcontroller based embedded systems...
Question paper with solution  the 8051 microcontroller based embedded systems...Question paper with solution  the 8051 microcontroller based embedded systems...
Question paper with solution the 8051 microcontroller based embedded systems...
 

Similar to ARM Cortex M3 Instruction Sets and Programming

Module 1 - ARM 32 Bit Microcontroller
Module 1 - ARM 32 Bit Microcontroller Module 1 - ARM 32 Bit Microcontroller
Module 1 - ARM 32 Bit Microcontroller Amogha Bandrikalli
 
Comparison between RISC architectures: MIPS, ARM and SPARC
Comparison between RISC architectures: MIPS, ARM and SPARCComparison between RISC architectures: MIPS, ARM and SPARC
Comparison between RISC architectures: MIPS, ARM and SPARCApurv Nerlekar
 
An Overview of LPC2101/02/03
An Overview of LPC2101/02/03An Overview of LPC2101/02/03
An Overview of LPC2101/02/03Premier Farnell
 
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptxWINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptxSoniBhavya
 
DESIGN OF A 16-BIT HARVARD STRUCTURED RISC PROCESSOR IN CADENCE 45nmTECHNOLOGY
DESIGN OF A 16-BIT HARVARD STRUCTURED RISC PROCESSOR  IN CADENCE 45nmTECHNOLOGYDESIGN OF A 16-BIT HARVARD STRUCTURED RISC PROCESSOR  IN CADENCE 45nmTECHNOLOGY
DESIGN OF A 16-BIT HARVARD STRUCTURED RISC PROCESSOR IN CADENCE 45nmTECHNOLOGYshaikalthaf40
 
Lcu14 101- coresight overview
Lcu14 101- coresight overviewLcu14 101- coresight overview
Lcu14 101- coresight overviewLinaro
 
8085 instructions and addressing modes
8085 instructions and addressing modes8085 instructions and addressing modes
8085 instructions and addressing modesSuchismita Paul
 
L10 assembly-language-programming-of-atmega328 p
L10 assembly-language-programming-of-atmega328 pL10 assembly-language-programming-of-atmega328 p
L10 assembly-language-programming-of-atmega328 prsamurti
 
Gl embedded starterkit_ethernet
Gl embedded starterkit_ethernetGl embedded starterkit_ethernet
Gl embedded starterkit_ethernetRoman Brovko
 
GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64Yi-Hsiu Hsu
 
Lect 3 ARM PROCESSOR ARCHITECTURE
Lect 3  ARM PROCESSOR ARCHITECTURE Lect 3  ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE Dr.YNM
 
POWER processor and features presentation
POWER processor and features presentationPOWER processor and features presentation
POWER processor and features presentationGanesan Narayanasamy
 
Arm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_modelArm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_modelGanesh Naik
 
A REVIEW ON ANALYSIS OF 32-BIT AND 64-BIT RISC PROCESSORS
A REVIEW ON ANALYSIS OF 32-BIT AND 64-BIT RISC PROCESSORSA REVIEW ON ANALYSIS OF 32-BIT AND 64-BIT RISC PROCESSORS
A REVIEW ON ANALYSIS OF 32-BIT AND 64-BIT RISC PROCESSORSIRJET Journal
 
Unit II Arm7 Thumb Instruction
Unit II Arm7 Thumb InstructionUnit II Arm7 Thumb Instruction
Unit II Arm7 Thumb InstructionDr. Pankaj Zope
 

Similar to ARM Cortex M3 Instruction Sets and Programming (20)

Module 1 - ARM 32 Bit Microcontroller
Module 1 - ARM 32 Bit Microcontroller Module 1 - ARM 32 Bit Microcontroller
Module 1 - ARM 32 Bit Microcontroller
 
Comparison between RISC architectures: MIPS, ARM and SPARC
Comparison between RISC architectures: MIPS, ARM and SPARCComparison between RISC architectures: MIPS, ARM and SPARC
Comparison between RISC architectures: MIPS, ARM and SPARC
 
Lecture 03 basics of pic
Lecture 03 basics of picLecture 03 basics of pic
Lecture 03 basics of pic
 
An Overview of LPC2101/02/03
An Overview of LPC2101/02/03An Overview of LPC2101/02/03
An Overview of LPC2101/02/03
 
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptxWINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
WINSEM2022-23_BECE204L_TH_VL2022230500861_2023-02-10_Reference-Material-I.pptx
 
DESIGN OF A 16-BIT HARVARD STRUCTURED RISC PROCESSOR IN CADENCE 45nmTECHNOLOGY
DESIGN OF A 16-BIT HARVARD STRUCTURED RISC PROCESSOR  IN CADENCE 45nmTECHNOLOGYDESIGN OF A 16-BIT HARVARD STRUCTURED RISC PROCESSOR  IN CADENCE 45nmTECHNOLOGY
DESIGN OF A 16-BIT HARVARD STRUCTURED RISC PROCESSOR IN CADENCE 45nmTECHNOLOGY
 
Lcu14 101- coresight overview
Lcu14 101- coresight overviewLcu14 101- coresight overview
Lcu14 101- coresight overview
 
8085 instructions and addressing modes
8085 instructions and addressing modes8085 instructions and addressing modes
8085 instructions and addressing modes
 
L10 assembly-language-programming-of-atmega328 p
L10 assembly-language-programming-of-atmega328 pL10 assembly-language-programming-of-atmega328 p
L10 assembly-language-programming-of-atmega328 p
 
Gl embedded starterkit_ethernet
Gl embedded starterkit_ethernetGl embedded starterkit_ethernet
Gl embedded starterkit_ethernet
 
Assignment
AssignmentAssignment
Assignment
 
Arm architecture overview
Arm architecture overviewArm architecture overview
Arm architecture overview
 
GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64
 
Highridge ISA
Highridge ISAHighridge ISA
Highridge ISA
 
Lect 3 ARM PROCESSOR ARCHITECTURE
Lect 3  ARM PROCESSOR ARCHITECTURE Lect 3  ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE
 
POWER processor and features presentation
POWER processor and features presentationPOWER processor and features presentation
POWER processor and features presentation
 
Arm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_modelArm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_model
 
A REVIEW ON ANALYSIS OF 32-BIT AND 64-BIT RISC PROCESSORS
A REVIEW ON ANALYSIS OF 32-BIT AND 64-BIT RISC PROCESSORSA REVIEW ON ANALYSIS OF 32-BIT AND 64-BIT RISC PROCESSORS
A REVIEW ON ANALYSIS OF 32-BIT AND 64-BIT RISC PROCESSORS
 
Unit II Arm7 Thumb Instruction
Unit II Arm7 Thumb InstructionUnit II Arm7 Thumb Instruction
Unit II Arm7 Thumb Instruction
 
Unit ii arm7 thumb
Unit ii arm7 thumbUnit ii arm7 thumb
Unit ii arm7 thumb
 

Recently uploaded

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 

Recently uploaded (20)

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 

ARM Cortex M3 Instruction Sets and Programming

  • 1. ARM Cortex M3 Instruction Sets and Programming Prof. Amogha B Asst. Prof. JIT, Davangere.
  • 2. Why Assembler 5/22/2018 Dept. of ECE, JIT, DVG 2 • Most industrial microcontroller users program in assembly language • Many MC users will continue to program in assembly they need the detailed control flow • Many application require the efficiency of assembly language • Understanding the assembly helps in evaluating high level language.
  • 3. Outline • Assembly basics, Instruction • List and description, • Useful instructions, • Assembly and C language Programming 5/22/2018 3Dept. of ECE, JIT, DVG
  • 4. Introduction • It focus on the various instruction set of CORTEX M3 and example for each 5/22/2018 4Dept. of ECE, JIT, DVG
  • 5. Assembly Basics • The basic syntax should be clearly understood before writing the programs • Common syntax is – Label opcode operand1, operand2,…… ; comments • Label is optional for every instruction – Address of instruction are identified by label. • Opcode – a high level English word for user and machine level code for computers • Normally first operand is destination and it depends on instruction. • Number of operands are dependant on instruction. 5/22/2018 5Dept. of ECE, JIT, DVG
  • 6. Example moving a immediate data • Mov r0, #0x12 ; after execution r0 = 0x12 (H) • Mov r1,#’A’ ; after execution r1= ASCII value. – While passing ASCII inside codes or 0xA is good • The text after ; is considered as comments which doesn’t effect the execution which helps the user to understand the code in better way. 5/22/2018 Dept. of ECE, JIT, DVG 6
  • 7. EQU • It is used to define the constants and they can be used inside the program. • Example : keil 5/22/2018 Dept. of ECE, JIT, DVG 7
  • 8. DCB, DCD • Constants are stored in the literal pool – Literal pool means a portion of memory embedded in the code to hold constant values – Constant values are placed at the address near to end • DCB – define constant byte to store characters • DCD- define constant data in binary format • Example 5/22/2018 Dept. of ECE, JIT, DVG 8
  • 9. Use of Suffixes • In assembler for ARM processors, instructions can be followed by suffixes. • In Cortex M3 the conditional execution suffixes are usually used for branch instructions. • The suffixes are – S – Update Application Program Status Register (APSR) ex: ADDS R0, R1; updates APSR – EQ, NE, LT , GT – conditional execution • ex: BEQ <Label> ; Branch if equal. 5/22/2018 Dept. of ECE, JIT, DVG 9
  • 10. Simple Addition Program • 10+9+8+7+6+5+4+3+2+1+0 • 1+2+3+4+5+6+7+8+9+10 5/22/2018 Dept. of ECE, JIT, DVG 10
  • 11. Unified Assembler Language (UAL) • For easy porting between the thumb and ARM code the UAL made a common syntax – Traditional Thumb instruction : ADD R0, R1 ; – UAL syntax : ADD R0, R1, R1; R0 = R0+R1 • Thumb syntax can be used, in assembly directive to make differentiate between the thumb and UAL syntax are mentioned. – CODE 16 – traditional Thumb – THUMB – UAL syntax 5/22/2018 Dept. of ECE, JIT, DVG 11
  • 12. Conti. • Developer should be careful while using Traditional thumb as some updates APSR • Where as in UAL syntax if S is used then only it updates the APSR – AND R0, R1 ; Traditional Thumb syntax – ANDS R0, R0, R1 ; Equivalent UAL syntax (S suffix is added) 5/22/2018 Dept. of ECE, JIT, DVG 12
  • 13. Some instruction can done in THUMB and THUMB-2 • The .W (wide) suffix specifies a 32-bit instruction. If no suffix is given, the assembler tool can choose either instruction but usually defaults to 16-bit Thumb code to get a smaller size – ADDS R0, #1 ; Use 16-bit Thumb instruction by default ; for smaller size – ADDS.N R0, #1 ; Use 16-bit Thumb instruction (N=Narrow) – ADDS.W R0, #1 ; Use 32-bit Thumb-2 instruction (W=wide) 5/22/2018 Dept. of ECE, JIT, DVG 13
  • 14. Conti. • In C compliers will use 16 bit instructions if data size is less and switches to thumb2 if exceeds • R0 – R7 can be accessed by thumb • No limitations for register accessing for thumb 2 • Location for thumb 2 and thumb – 0x1000 : LDR r0,[r1] ;a 16-bit instructions (occupy 0x1000-0x1001) – 0x1002 : RBIT.W r0 ;a 32-bit Thumb-2 instruction (occupy; 0x1002-0x1005) – 4 bytes 5/22/2018 Dept. of ECE, JIT, DVG 14
  • 15. Instruction List • 16 Bit Data Processing Instruction • ADDITION – ADC – ADD – ADR • Compare – CMP – CMN- compare negative compare one data with two’s complement of another data and update flags 5/22/2018 Dept. of ECE, JIT, DVG 15
  • 16. Instructions • AND • BIC performs an AND operation on the bits in Rn with the complements of the corresponding bits in the value of Operand2. • CPY – copy instruction same as mov i.e data transfer between two register • MVN – perform not operation • NEG- 2’s compliment 5/22/2018 Dept. of ECE, JIT, DVG 16
  • 17. 16 Bit Data Processing Instruction 5/22/2018 Dept. of ECE, JIT, DVG 17
  • 18. Branch Instruction • B Branch • B<cond> Conditional branch • BL Branch with link; call a subroutine and store the return address in LR (this is actually • a 32-bit instruction, but it is also available in Thumb in traditional ARM processors) • BLX Branch with link and change state (BLX <reg> only) • BX <reg> Branch with exchange state • CBZ Compare and branch if zero (architecture v7) • CBNZ Compare and branch if nonzero (architecture v7) • IT IF-THEN (architecture v7) – in next slides will see this 5/22/2018 Dept. of ECE, JIT, DVG 18
  • 19. CBZ AND CBNZ • The branch destination must be within 4 to 130 bytes after the instruction and in the same execution state. • These instructions must not be used inside an IT block. • Condition flags – These instructions do not change the flags. • Architectures – These 16-bit Thumb instructions are available in ARMv6T2 and above. – There are no ARM or 32-bit Thumb versions of these instructions. 5/22/2018 Dept. of ECE, JIT, DVG 19
  • 20. CBZ • Same as – CMP R0, #0 – BEQ LABEL 5/22/2018 Dept. of ECE, JIT, DVG 20
  • 21. 5/22/2018 Dept. of ECE, JIT, DVG 21
  • 22. 16 BIT LOAD AND STORE INSTRUCTION • LDR Load word from memory to register • LDRH Load half word from memory to register • LDRB Load byte from memory to register • LDRSH Load half word from memory, sign extend it, and put it in register • LDRSB Load byte from memory, sign extend it, and put it in register • STR Store word from register to memory • STRH Store half word from register to memory • STRB Store byte from register to memory (Only LSB) • LDM/LDMIA Load multiple/Load multiple increment after • STM/STMIA Store multiple/Store multiple increment after • PUSH Push multiple registers • POP Pop multiple registers 5/22/2018 Dept. of ECE, JIT, DVG 22
  • 23. Other 16 bit Instruction • SVC Supervisor call • SEV Send event • WFE Sleep and wait for event • WFI Sleep and wait for interrupt • BKPT – Breakpoint; if debug is enabled, it will enter debug mode(halted), or if debug monitor exception is enabled, it will invoke the debug exception; otherwise, it will invoke a fault exception • NOP No operation • CPSIE – Enable PRIMASK (CPSIE i)/FAULTMASK (CPSIE f ) register (set the register to 0) • CPSID – Disable PRIMASK (CPSID i)/ FAULTMASK (CPSID f ) register (set the register to1) 5/22/2018 Dept. of ECE, JIT, DVG 23
  • 24. 32 bit Data processing • PDF on Desktop • UXTB – unsigned extend byte – B- byte for 16 bit • UXTH – unsigned extend half word • UBFX - Signed and Unsigned Bit Field Extract. – Copies adjacent bits from one register into the least significant bits of a second register, and sign extends or zero extends to 32 bits. • UBFX/SBFX{cond} Rd, Rn, #lsb, #width • USAT – saturates to in range of unsigned number • LDREX – If the physical address has the Shared TLB attribute, LDREX tags the physical address as exclusive access for the current processor, and clears any exclusive access tag for this processor for any other physical address. 5/22/2018 Dept. of ECE, JIT, DVG 24
  • 25. Unsupported Thumb Instructions • Unsupported instructions are – Coprocessor are not supported – The two instructions that cortex M3 doesn’t support are BLX, SETEND – Unsupported Change Process State Instruction • If these are invoked a usage fault exceptions will generate. 5/22/2018 Dept. of ECE, JIT, DVG 25
  • 26. Unsupported Thumb Instructions • BLX label – This is branch with link and exchange state. In a format with immediate data, BLX always changes to ARM state. Because the Cortex-M3 does not support the ARM state, instructions like this one that attempt to switch to the ARM state will result in a fault exception called usage fault. • SETEND – This Thumb instruction, introduced in architecture v6, switches the endian configuration during run time. Since the Cortex-M3 does not support dynamic endian, using the SETEND instruction will result in a fault exception. 5/22/2018 Dept. of ECE, JIT, DVG 26
  • 27. Unsupported Co-Processor • MCR Move to coprocessor from ARM processor • MCR2 Move to coprocessor from ARM processor • MCRR Move to coprocessor from two ARM register • MRC Move to ARM register from coprocessor • MRC2 Move to ARM register from coprocessor • MRRC Move to two ARM registers from coprocessor • LDC Load coprocessor; load memory data from a sequence of consecutive memory addresses to a coprocessor • STC Store coprocessor; stores data from a coprocessor to a sequence of consecutive memory addresses 5/22/2018 Dept. of ECE, JIT, DVG 27
  • 28. Unsupported Change Process State Instructions • CPS<IE|ID>.W A There is no A bit in the Cortex- M3 • CPS.W #mode There is no mode bit in the Cortex- M3 PSR – A- abort – I- interrupt – T- Thumb state C:UsersAmoghaDesktopProgram+Status+Registers .jpg 5/22/2018 Dept. of ECE, JIT, DVG 28
  • 29. Unsupported Hint Instructions • Used in the place of below instruction – NOP, WFE, WFI, YIELD, SEV-set event • DBG A hint instruction to debug and trace system • PLD Preload data; no cache on cortex M3 • PLI Preload instruction; no cache on cortex M3 • YIELD – A hint instruction to allow multithreading software to indicate to hardware that it is doing a task that can be swapped out to improve overall system performance. 5/22/2018 Dept. of ECE, JIT, DVG 29
  • 30. Instruction Descriptions • Moving Data – 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 5/22/2018 Dept. of ECE, JIT, DVG 30
  • 31. Moving data between register • The instruction used is MOV – MOV R5,R3 ; R3 contents are moved to R5 • If need to generate negative value of original data is MVN 5/22/2018 Dept. of ECE, JIT, DVG 31
  • 32. Moving an Immediate data Value to Register • The instruction used is MOV • MOV R0,#0x123 – Important thing is the immediate value should be less than 16 bits 5/22/2018 Dept. of ECE, JIT, DVG 32
  • 33. LOAD / STORE instruction • Load from memory to register • STORE- register to Memory 5/22/2018 Dept. of ECE, JIT, DVG 33
  • 34. Pre and post Indexing of memory 5/22/2018 Dept. of ECE, JIT, DVG 34
  • 35. Moving data between memory and register • The instruction used for performing this are LOAD and STORE – LOAD (LDR) – STORE (STR) • The transfer of data is of different data size – Byte, half word, word etc • Multiple data are combined and stored/accessed from memory 5/22/2018 Dept. of ECE, JIT, DVG 35
  • 36. Move of special register to register • MSR – MOV xPSR,R0 • MRS – MOV R0,APSR 5/22/2018 Dept. of ECE, JIT, DVG 36
  • 37. Processing DATA • There are many data processing operations in cortex M3, can have multiple instruction formats – Ex: ADD; instruction can operate between two registers or between one register and an immediate data value – ADD R0, R0, R1 ; R0 = R0 + R1 – ADDS R0, R0, #0x12 ; R0 = R0 + 0x12 – ADD.W R0, R1, R2 ; R0 = R1 + R2 5/22/2018 Dept. of ECE, JIT, DVG 37
  • 38. Traditional Thumb and Thumb2 • The only difference between them are – Traditional thumb instruction updates flag without specifying by user – Thumb2 if user specified then only those instructions can update flags. 5/22/2018 Dept. of ECE, JIT, DVG 38
  • 39. Instruction Operation ADD RD, RN,RM ; RD=RN+RM Perform addition ADD Rd, #immed ; Rd = Rd + #immed ADD Rd, Rn, # immed ; Rd = Rn + #immed ADC Rd, Rn, Rm ; Rd = Rn + Rm + carry ADC Rd, Rd, Rm ; Rd = Rd + Rm + carry Addition with carry ADDW Rd, Rn, #immed ; Rd = Rn + #immed ADD register with 12-bit immediate value Same for subtraction immediate, subtract with barrow SUB, SBC, SUB Rd, Rn, Rm ; Rd= Rn -Rm Subtract RSB.W Rd, Rn, Rm ; Rd = Rm – Rn Reverse Subtract MUL Rd, Rn, Rm ; Rd = Rn*Rm Multiply UDIV Rd, Rn, Rm Division for unsigned division SDIV -signed 5/22/2018 Dept. of ECE, JIT, DVG 39
  • 40. Other instruction • Multiplication – signed and unsigned • Logic operation – – AND, ORRR, EOR(EX-OR), BIC(Bit clear) • Shift and rotate – Logical Shift Left – Logical Shift Right – Rotate Right – Arithmetic Shift Right (ASR) 5/22/2018 Dept. of ECE, JIT, DVG 40
  • 41. Shift and Rotate 5/22/2018 Dept. of ECE, JIT, DVG 41
  • 42. • ASR It copies the sign bit into vacated bit positions on the left. • LSL provides the value of a register multiplied by a power of two. • LSR provides the unsigned value of a register divided by a variable power of two. Both instructions insert zeros into the vacated bit positions. • ROR provides the value of the contents of a register rotated by a value. The bits that are rotated off the right end are inserted into the vacated bit positions on the left. • RRX provides the value of the contents of a register shifted right one bit. The old carry flag is shifted into bit[31]. If the S suffix is present, the old bit[0] is placed in the carry flag. 5/22/2018 Dept. of ECE, JIT, DVG 42
  • 43. Logical Operations • AND gate – AND Rd, Rn ; Rd = Rd & Rn – AND.W Rd, Rn, Rm ; Rd = Rn & Rd for 32 bit • OR gate – ORR Rd, Rn ; Rd = Rd | Rn – ORR.W Rd, Rn, Rm ; Rd = Rn | Rd • Bit clear and Exor gate – BIC Rd, Rn ; Rd = Rd & (~Rn) – EOR Rd, Rn ; Rd = Rd ^ Rn • Bit wise OR and NOT – ORN.W Rd, Rn,#immed ; Rd = Rn | (~#immed) 5/22/2018 Dept. of ECE, JIT, DVG 43
  • 44. There is no ROTATE LEFT • Only a rotate right is provided • The rotate right can be operated as left if we increase the rotation value. 5/22/2018 Dept. of ECE, JIT, DVG 44
  • 45. Sign Extend Instruction Instruction Operation SXTB Rd, Rm ; Rd = signext(Rm[7:0]) Sign extend byte data into word SXTH Rd, Rm ; Rd = signext(Rm[15:0]) Sign extend half word data into word 5/22/2018 Dept. of ECE, JIT, DVG 45
  • 46. Reverse Operation 5/22/2018 Dept. of ECE, JIT, DVG 46
  • 47. Call and Unconditional Branch • Posses three statements – Branch with label ex: B label – Branch to specified address: BX REG – Branch to link : BL 5/22/2018 Dept. of ECE, JIT, DVG 47
  • 48. Decisions and Conditional Branches • Flags – N- Negative – Z- zero – C- carry This flag is for unsigned data processing for example, in add (ADD) it is set when an overflow occurs; in subtract (SUB) it is set when a borrow did not occur (borrow is the invert of carry) – V- Over flow • BEQ label or BEQ.W label; branch to label address when zero flag is set 5/22/2018 Dept. of ECE, JIT, DVG 48
  • 49. Symbol Condition Flag CS/HS Carry set/unsigned higher or same C –set CC/LO Carry clear/unsigned lower C – clear MI Minus/negative N- set PL Plus/Positive or zero N-clear VS Overflow V-set VC No overflow V-clear HI Unsigned higher C- set and Z clear LS Unsigned Lower or same C-clear or Z set GE Signed greater than or equal N set and V set, or N clear and V clear (N == V) LT Signed Les than N set and V clear, or N clear and V set (N != V) GT Signed Greater than Z clear, and either N set and V set, or N clear and V clear (Z == 0, N == V) LE Signed Less than or equal Z set, or N set and V clear, or N clear and V set (Z == 1 or N != V) AL/ EQ/NE Always( Un-conditional), equal and not equal5/22/2018 Dept. of ECE, JIT, DVG 49
  • 50. TST • TEST instruction is same as AND, it performs AND, updates flags but doesn’t store results. – TST R0, R1 ; Calculate R0 AND R1 and update flag – TST R0, #0x12 ; Calculate R0 AND 0x12 and update flag 5/22/2018 Dept. of ECE, JIT, DVG 50
  • 51. Syntax for IT (TRUE- THEN-ELSE) • IT<x><y><z> <cond>; IT instruction (<x>, <y>, ; <z> can be T or E) • instr1<cond> <operands> ; 1 instruction (<cond> ; must be same as IT) • instr2<cond or not cond> <operands> ; 2 instruction (can be ; <cond> oe <!cond> • instr3<cond or not cond> <operands> ; 3 instruction (can be ;<cond> or <!cond> • instr4<cond or not cond> <operands> ; 4instruction (can be ; <cond> or <!cond> 5/22/2018 Dept. of ECE, JIT, DVG 51
  • 52. Program on IT • Less than 4 instructions are executed and minimum is 1. • The number of instructions should be maintained • During exception – Single IT – exception are stored in PSR and pop when exception is served – Multiple instructions ( multiple load and store) the whole instructions are abandoned and restarted( 1st IT instruction) after interrupt process is completed. 5/22/2018 Dept. of ECE, JIT, DVG 52
  • 53. Memory Barrier • Avoids occurring of race conditions during memory errors. • Whenever the memory misses in cache previous controller will wait till the memory corrects but now if the result of present line is not dependent on next instruction then the ARM will proceed for executing the next line – Ex: LDR r0, [r1] if error occurs in load – STR r2,[r5] here store isn't depending on load hence arm executes the same. 5/22/2018 Dept. of ECE, JIT, DVG 53
  • 54. Registers for Memory Barrier • DMB Data memory barrier; ensures that all memory accesses are completed before new memory access is committed • DSB Data synchronization barrier; ensures that all memory accesses are completed before next instruction is executed • ISB Instruction synchronization barrier; flushes the pipeline and ensures that all previous instructions are completed before executing new instructions 5/22/2018 Dept. of ECE, JIT, DVG 54
  • 56. • SSAT.W <Rd>, #<immed>, <Rn>, {,<shift>} Saturation for signed value • USAT.W <Rd>, #<immed>, <Rn>, {,<shift>} Saturation for a signed value into an unsigned value – Rn: Input value – Shift: Shift operation for input value before saturation; optional, can be #LSL N or #ASR N – Immed: Bit position where the saturation is carried out – Rd: Destination register 5/22/2018 Dept. of ECE, JIT, DVG 56
  • 57. Unsigned Saturation Operation 5/22/2018 Dept. of ECE, JIT, DVG 57
  • 58. Division • SDIV – SDIV{cond} {Rd}, Rn, Rm • UDIV – The result is Rd = Rn/Rm. • Code • LDR R0,=300 ; Decimal 300 • MOV R1,#5 • UDIV.W R2, R0, R1 5/22/2018 Dept. of ECE, JIT, DVG 58
  • 59. Divide by zero • You can set up the DIVBYZERO bit in the NVIC Configuration Control Register so that when a divide by zero occurs, a fault exception (usage fault) takes place. Otherwise, <Rd> will become 0 if a divide by zero takes place. 5/22/2018 Dept. of ECE, JIT, DVG 59
  • 60. Table Branch Byte • Table Branch Byte (TBB) and Table Branch Halfword (TBH) are for implementing branch tables. The • TBB instruction uses a branch table of byte size offset, and TBH uses a branch table of half word offset. – Syntax: TBB.W [Rn, Rm] 5/22/2018 Dept. of ECE, JIT, DVG 60
  • 61. Example IF-THEN-ELSE • CMP R0, R1 ; Compare R0 and R1 • ITTE GT ; If R0 > R1 Then ; if true, first 2 statements execute, ; if false, other 1 statement is executed • MOVGT R2, R0 ; R2 = R0 • MOVGT R3, R1 ; R3 = R1 • MOVLE R2, R0 ; Else R2 = R1 5/22/2018 Dept. of ECE, JIT, DVG 61
  • 62. Program • IT PROGRAM • IF CONDITION IS TRUE – Perform Three operations • If Condition is false – Perform two operations • Condition be like compare R1 and R2. – Condition is if (R1 < R2) 5/22/2018 Dept. of ECE, JIT, DVG 62
  • 63. Memory System Features • Features – Predefined memory map for bus interface these are enabled when memory location is accessed – This feature allow the porting between the processor and it is made easy – Bit band access – each bits can be addressed using bit-band example 0x20000004 – Unaligned transfers of data – Supports both little endian and big endian memory configuration 5/22/2018 Dept. of ECE, JIT, DVG 63
  • 64. Memory Maps • CORTEX M3 has the fixed memory map which makes software porting to another product – System peripherals (NVIC, MPU) have same location for all CORTEX M3 hence manufactures can differentiate with others. – Some memory locations are reserved to private peripherals such as debugging components. Private peripheral memory region holds this 5/22/2018 Dept. of ECE, JIT, DVG 64
  • 65. 5/22/2018 Dept. of ECE, JIT, DVG 65
  • 66. Private peripheral components • Fetch patch and break point unit (FPB) • Data watch-point and trace unit (DWT) • Instrumentation Trace Macrocell (ITM) • Embedded Trace Macrocell (ETM) • Trace Port Interface Unit (TPIU) • ROM table – – Shows the minimum size of ROM required to contain the image (ext. data video, audio, image). This does not include ZI data and debug information which is not stored in the ROM. 5/22/2018 Dept. of ECE, JIT, DVG 66
  • 67. ADDRESS SPACE • 4GB of address space • Program code can be placed in – Code region – Static Random Access Memory region – External RAM region • Preferably the codes are placed in code regions as data fetching can happen simultaneously on two separate bus. 5/22/2018 Dept. of ECE, JIT, DVG 67
  • 68. SRAM Memory range • SRAM memory range is for connecting internal SRAM, system interface bus is used for interface. • 32 MB is defined as a bit band alias. – A 32-bit-band alias memory range, each word address represents a single bit in the 1-MB bit- band region – For altering the bit band alias we can use atomic READ-MODIFY-WRITE. – Bit band alias memory access works only for data not for instruction fetches. 5/22/2018 Dept. of ECE, JIT, DVG 68
  • 69. On chip peripherals • 0.5 GB block of address range is allocated to on-chip peripherals. • This is also supports bit band alias for modifying • Instruction execution is not allowed in this region. 5/22/2018 Dept. of ECE, JIT, DVG 69
  • 70. External RAM • Two slots of 1-GB memory space are allocated for external RAM and external devices. • Normally program won’t execute in memory reserved for external device. • If required in external RAM is attached 5/22/2018 Dept. of ECE, JIT, DVG 70
  • 71. AMBA bus • 0.5 GB at last is reserved for system level components , internal peripheral buses, external peripheral bus, and vendor-specific system peripherals. • Private peripheral bus – two segments – Advanced high Performance Bus (AHB)- for Cortex- M3 internal AHB peripherals only like NCIV. – Advance Peripheral BUS (APB)- for internal APB and external peripherals. • A provision is provided in CORTEX M3 additional on chip APB which is provided in private peripheral bus via APB interface. 5/22/2018 Dept. of ECE, JIT, DVG 71
  • 72. System level • The NVIC is located in a memory region called the system control space (SCS) – Additional interrupt control features, this region also provides the control registers for SYSTICK, MPU, and code debugging control. 5/22/2018 Dept. of ECE, JIT, DVG 72
  • 73. • Question paper discussion 5/22/2018 Dept. of ECE, JIT, DVG 73
  • 74. Yesterday • Every peripheral is reserved by address and it is accessible • Bit band operation – for read write operation 5/22/2018 Dept. of ECE, JIT, DVG 74
  • 75. Memory Access Attributes • The CORTEX M3 memory attributes (Method) are – Bufferable: • Write to memory can be carried out by a write buffer while the processor continues on next instruction execution. Example : UART – Cacheable: • Data obtained from memory read can be copied to a memory cache so that next time it is accessed the value can be obtained from the cache to speed up the program execution – Executable • Processor can execute code from this memory region – Sharable • Data in this memory region could be shared by multiple bus masters 5/22/2018 Dept. of ECE, JIT, DVG 75
  • 76. Memory regions of attributes • Code Memory region (0x00000000 to 0x1FFFFFFF) – Region is executable – Cache is write through i.e. can have data in this memory region – Data is transferred using the data bus interface – Write transfers is bufferable 5/22/2018 Dept. of ECE, JIT, DVG 76
  • 77. CONTI. • SRAM memory region (0x20000000–0x3FFFFFFF) – Meant for on-chip RAM – Executing the code is feasible. – Write transfer are bufferable. • Peripheral Region (0x40000000–0x5FFFFFFF) – Reserved to use only by peripherals – Can’t execute program here • External RAM (0x60000000–0x7FFFFFFF) – Used for on or off chip memory – Can execute the program in this region – Write data are bufferable 5/22/2018 Dept. of ECE, JIT, DVG 77
  • 78. Conti. • External RAM (0x80000000–0x9FFFFFFF) – Reserved only for external devices – Memory is non-bufferable to access – Can’t execute code in this region • Same for 0xC0000000–0xDFFFFFFF • System Region (0xE0000000–0xFFFFFFFF) – Reserved for the usage of private peripherals and vendor specific peripherals – For private peripherals access are non-bufferable – Vendor specific access are bufferable 5/22/2018 Dept. of ECE, JIT, DVG 78
  • 79. Default Memory Access Permission • Prevents the user programs to access some locations which are controlled by MPU 5/22/2018 Dept. of ECE, JIT, DVG 79 Memory Region Address Access in User Program Vendor Specific 0xE0100000–0xFFFFFFFF Full access ROM table 0xE00FF000–0xE00FFFFF Blocked ; if user tries to access a bus fault is generated External Private Peripheral Bus 0xE0042000–0xE00FEFFF Blocked; if user tries to access a bus fault is generated ETM (Embedded Trace Macrocell) 0xE0041000–0xE0041FFF Blocked; if user tries to access a bus fault is generated
  • 80. TPIU Trace Port Interface Unit 0xE0040000–0xE0040FFF Blocked; if user tries to access a bus fault is generated Internal Peripheral Private Bus 0xE000F000–0xE003FFFF Blocked; if user tries to access a bus fault is generated NVIC 0xE000E000–0xE000EFFF Blocked; if user tries to access a bus fault is generated FPB 0xE0002000–0xE0003FFF Blocked; if user tries to access a bus fault is generated DWT 0xE0001000–0xE0001FFF Blocked ITM 0xE0000000–0xE0000FFF Blocked External device 0xA0000000–0xDFFFFFFF Full Access External RAM 0x60000000–0x9FFFFFF Full Access Peripheral 0x40000000–0x5FFFFFFF Full Access SRAM 0x20000000–0x3FFFFFFF Full Access Code 0x00000000–0x1FFFFFFF Full Access5/22/2018 Dept. of ECE, JIT, DVG 80
  • 81. Un-Alignment Basics 5/22/2018 Dept. of ECE, JIT, DVG 81 Programmers see memory as just a row of memory array Process see memory in union of even numbers 4,8,16,32
  • 82. Aligned access 5/22/2018 Dept. of ECE, JIT, DVG 82 Consider reading a 4 Byte of data Data should be aligned to 4,8,16,32 formats , if not we are not going to get accurate fetching
  • 83. Unaligned Data access 5/22/2018 Dept. of ECE, JIT, DVG 83
  • 84. UNALIGNED TRANSFERS • Supports both unaligned and aligned access • Traditional ARM were supporting only aligned memory access • 1 bytes = ? • 8 bit • If 32 bits – 4 bytes of memory • 16- 2 bytes • 8- 1 bytes 5/22/2018 Dept. of ECE, JIT, DVG 84
  • 85. Example for unaligned data 5/22/2018 Dept. of ECE, JIT, DVG 85 For full word (32) For half word (16)
  • 86. Exclusive Accesses • In CORTEX M3 we don’t have swap option instead of it we posses exclusive access. • Swapping was normally used in semaphores – Semaphores are used to allocate shared resources to applications. – Shared source serve only one application at a time i.e. called as Mutual Exclusion (MUTEX). – If the resource is being locked by one process (task), it can’t serve another process until the lock is released 5/22/2018 Dept. of ECE, JIT, DVG 86
  • 87. Conti. • MUTEX semaphore in memory is used to indicate whether the resource is locked or free. 5/22/2018 Dept. of ECE, JIT, DVG 87
  • 88. Working 5/22/2018 Dept. of ECE, JIT, DVG 88
  • 89. Programming it • Cortex-M3 include LDREX (word), LDREXB (byte), LDREXH (half word), STREX (word), STREXB (byte), and STREXH (half word • Rxf – base register address with shifted offset value • LDREX <Rxf>, [Rn, #offset] • STREX <Rd>, <Rxf>,[Rn, #offset] 5/22/2018 Dept. of ECE, JIT, DVG 89
  • 90. Endian mode • Cortex M3 supports both little endian and big endian mode • Little endian mode – LSB Data = MSB of memory – Data 0x12345678 – Address 0x40000010 – 78 56 34 12 5/22/2018 Dept. of ECE, JIT, DVG 90
  • 91. Figure 5/22/2018 Dept. of ECE, JIT, DVG 91
  • 92. Big Endian – Data 0x12345678 – Address 0x40000010 – 12 34 56 78 5/22/2018 Dept. of ECE, JIT, DVG 92
  • 93. Big Indian Memory Example 5/22/2018 Dept. of ECE, JIT, DVG 93
  • 94. Conti. • The endian mode is set when the processor exits reset later it can’t be changed. • No dynamic changing of memory mode • If processor is in little endian, some peripherals works on big endian means change the format using REV, REV16 5/22/2018 Dept. of ECE, JIT, DVG 94
  • 95. BIT BAND Operation • Bit-band operation support allows a single load/store operation to access (read/write) to a single data bit. • Memory regions are bit band region(1MB) and bit band alias (32MB) • Use of bit band is each peripheral bits can be accessed separately in LSB. 5/22/2018 Dept. of ECE, JIT, DVG 95
  • 96. Working • If without bitband – Access the address – Load the changing value to another register – Perform OR to modify bit – Store the result to address. • With bit-band – Load address to register – Load the changing value – Store the modified value to address 5/22/2018 Dept. of ECE, JIT, DVG 96
  • 97. Differences • Without bit band • LDR R0,=0x20000000; set address • LDR R1,[R0] ; Read • ORR.W R1,#0x4; modify bit • STR R1,[R0] • With Bit Band • LDR R0,=0x20000008 • MOV R1,#1 • STR R1,[R0] 5/22/2018 Dept. of ECE, JIT, DVG 97
  • 98. Example 5/22/2018 Dept. of ECE, JIT, DVG 98
  • 99. Perform it using and not using bit band 5/22/2018 Dept. of ECE, JIT, DVG 99
  • 100. Advantages • During branch decisions on peripherals the below task happens if not bit band is – Reading whole register – Masking the unwanted bits – Comparing and branch • These are simplified as – Reading the status bit via bit-band alias – Comparing and branching 5/22/2018 Dept. of ECE, JIT, DVG 100
  • 101. BIT-BAND and BIT-BANG • Bit-band to indicate that the feature is a special memory band (region) that provides bit accesses • Bit bang commonly refers to driving I/O pins under software control to provide serial communication functions. 5/22/2018 Dept. of ECE, JIT, DVG 101
  • 102. Data last when exception occurs if bit band is not used 5/22/2018 Dept. of ECE, JIT, DVG 102
  • 103. Bit band providing locking facility during exceptions 5/22/2018 Dept. of ECE, JIT, DVG 103
  • 104. Programming bitband • #define DEVICE_REG0 *((volatile unsigned long *) (0x40000000)) • #define DEVICE_REG0_BIT0 *((volatile unsigned long *) (0x42000000)) • #define DEVICE_REG0_BIT1 *((volatile unsigned long *) (0x42000004)) ... • DEVICE_REG0 = 0xAB; // Accessing the hardware register by normal // address.. • DEVICE_REG0 = DEVICE_REG0 | 0x2; // Setting bit 1 without using // bitband feature... • DEVICE_REG0_BIT1 = 0x1; // Setting bit 1 using bitband feature // via the bit band alias address 5/22/2018 Dept. of ECE, JIT, DVG 104
  • 105. Development Flow 5/22/2018 Dept. of ECE, JIT, DVG 105
  • 106. Flow of program • Whenever the applications are developed using cortex M3 it is the process. • The concepts of code generation flow in terms of these tools are similar • Basic ones are – Assembler – C complier – Linker – Binary file generation utilities. • Real View development suite (RVDS) or Real view complier tools shows a file generation flow. 5/22/2018 Dept. of ECE, JIT, DVG 106
  • 107. Flow is explained by taking C program • Create C program • Create vectors • Create vector table • Compile the file • Use linker to link the file • Get executable file .elf – In Mp steps (REMEMBER MASM, LINK, CV exe) 5/22/2018 Dept. of ECE, JIT, DVG 107
  • 108. To compile • arm cc –c –g –W sample_LED.c –o sample_LED.o • armcc –c -g –W vectors.c –o vectors.o • o- object file (remember MP programs) • After MASM object files were created. 5/22/2018 Dept. of ECE, JIT, DVG 108
  • 109. Linker • LINKER used to generate the program image. • It generates filename.scat • scat tells the linker to put the starting address of program into vector table 5/22/2018 Dept. of ECE, JIT, DVG 109
  • 110. Linker Commands • Armlink –scatter sample_LED.scat "-- keep=vectors.o(exceptions_area)“ sample_LED.o vectors.o sample_LED.ELF • Executable image sample_LED.ELF is generated 5/22/2018 Dept. of ECE, JIT, DVG 110
  • 111. Execute image • /* create binary file */ • $> fromelf –-bin sample_LED.elf –output sample_LED.bin • /* Create disassembly output */ • $> fromelf –c sample_LED.elf > list.txt 5/22/2018 Dept. of ECE, JIT, DVG 111
  • 112. Compile in same example in Keil using DOS • C:KeilARMBIN40armcc -c -O3 -W -g -Otime --device DLM vectors.c • C:KeilARMBIN40armcc -c -O3 -W -g -Otime --device DLM blinky.c • C:KeilARMBIN40armlink --device DLM "-- keep=Startup.o(RESET)" "--first=Startup.o(RESET)" -scatter led.scat -- map vectors.o blinky.o -o blinky.elf • C:KeilARMBIN40fromelf --bin blinky.elf -o blinky.bin 5/22/2018 Dept. of ECE, JIT, DVG 112
  • 113. Accessing Memory Mapped Regions in C • Accessing the Peripherals using – Volatile Pointers – From address – Place pointers to elements – Scatter Loading file. 5/22/2018 Dept. of ECE, JIT, DVG 113
  • 114. Accessing Peripheral Registers as Pointers. 5/22/2018 Dept. of ECE, JIT, DVG 114 #define SYSTICK_CTRL (*((volatile unsigned long *) (0xE000E010)))
  • 115. Alternative Way of Accessing Peripheral Registers as Pointers. 5/22/2018 Dept. of ECE, JIT, DVG 115 Define address directly # define SYSSTICK_CTRL = 0xE000E010
  • 116. Accessing Peripheral Registers as Pointers to Elements in Data Structure 5/22/2018 Dept. of ECE, JIT, DVG 116
  • 117. Defining Peripheral-Based Address Using Scatter Loading File. 5/22/2018 Dept. of ECE, JIT, DVG 117
  • 118. Intrinsic Function • A built in function that is implemented directly by the complier without making use of any library 5/22/2018 Dept. of ECE, JIT, DVG 118
  • 119. Embedded Assembler and Inline Assembler • Feature is provided to write the assembly inside the C code it is called as inline assembler. • Format • Type of program, return type , access 5/22/2018 Dept. of ECE, JIT, DVG 119
  • 120. Interface assembly and C • Tasks can’t performed in C coding – Functions such as direct manipulation of stack data or special is not possible – Timing-critical routines – Tight memory requirements, causing part of the program to be written in assembly to get the smallest memory size 5/22/2018 Dept. of ECE, JIT, DVG 120
  • 121. FORMAT • Slight change • armasm –cpu cortex –m3 –o test1.o test1.s • Armlink –rw_base 0x2000000 –ro_base 0x0 – map –o test1.elf tes1.o – Here 0x0 is the read only memory – 0x20000000 specifies a read/write memory. • Fromelf –bin –output test1.bin test1.elf • Fromelf –c –output test1.list test1.elf 5/22/2018 Dept. of ECE, JIT, DVG 121
  • 122. Producing Output 5/22/2018 Dept. of ECE, JIT, DVG 122
  • 123. Output to console other than UART • Semi-hoisting: we can send the output using printf statement using debug register • Instrumentation trace: the output is sent to outer world using trace port analyzer • Instrumentation trace via serial wire viewer: other than Trace port interface unit a low cost serial wire viewer can be used to get data 5/22/2018 Dept. of ECE, JIT, DVG 123
  • 124. UART program in Assembly • In C • Logic ? • CHECK LSR content • Need to use Transmitter CHECK THR (0x20) • IF Receive (0x01) • RBR • Assembly • Load UART_FLAGS to one register and compare with 0x20 5/22/2018 Dept. of ECE, JIT, DVG 124
  • 125. All algorithm • Main program – Make r0 to r4 as 0 – Branch to label UART0Initialize – Load R0 with content of variable by name NUM1 – Branch to Puts • Puts, Putswaitloop, Putsloop exit • Putc, Putcloop • Uart0Intitialize label • NUM1 deceleration 5/22/2018 Dept. of ECE, JIT, DVG 125
  • 126. CMSIS – Newly added to the syllabus CORTEX MC Software Interface Standard 5/22/2018 Dept. of ECE, JIT, DVG 128
  • 127. CORTEX M3 in embedded application market • By 2008, it has 5 complier vendors, more than 15 embedded Operating Systems. • Many companies were providing hands for embedded software solutions – Codecs ( decoders ex: KM player some new format of video needs to download codecs) – Data processing libraries – Various software and debug solutions 5/22/2018 Dept. of ECE, JIT, DVG 129
  • 128. Aims of CMSIS • Improve software portability and reusability • Develop a products and device libraries which works on various silicon vendors • Easy to use and have standard interface • Run on multiple sources without the risk of drivers installation. 5/22/2018 Dept. of ECE, JIT, DVG 130
  • 129. Organization of CMSIS 5/22/2018 Dept. of ECE, JIT, DVG 131
  • 130. Layers • Core Peripheral Access Layer- to access core registers and core peripherals • Middleware Access Layer – A common method for accessing peripherals ( yet to launch) – Communication includes Ethernet, UART, SPI – Software support for communication interface • Device Peripheral Access layer (Microcontroller unit specific) • Access functions for peripherals (Microcontroller unit specific) 5/22/2018 Dept. of ECE, JIT, DVG 132
  • 131. CMSIS includes 5/22/2018 Dept. of ECE, JIT, DVG 133
  • 132. • Core_CM3.h contains peripheral register definitions and access functions – NVIC, System Control Block registers and SYSTICK registers. – Includes CMSIS intrinsic functions – Includes a function to output debug message via Instrumentation Trace Module. • Core_cm3.c includes CMSIS intrinsic functions which aren’t defined in Core_CM3.h • System_Device.h- contains Microcontroller specific interrupt number, exception and handlers. • System <device.c> specific function of microcontroller which includes system initialization. 5/22/2018 Dept. of ECE, JIT, DVG 134
  • 133. Example • #include “vendor_device.h> – <lpc17xx.h> // NXP – <lm3S_CMSIS.h> //Micro devices – Stm32f10x.h // for ST devices (house hold appli.) • SystemInit (); used for system initialize code • Void UART1_IRQHandler - for peripherals • Void SysTick_Handler – system handlers 5/22/2018 Dept. of ECE, JIT, DVG 135
  • 134. Benefits of CMSIS 5/22/2018 Dept. of ECE, JIT, DVG 136
  • 135. Thank You • Uart_base equ 0x4000000 • Uart_flag equ uart_base+0x20 • Uart_data equ uart_base+0x40 • Area • Mov r0,#0 • R1,r2,r3,r4 • B uart0_initilization • BL puts 5/22/2018 Dept. of ECE, JIT, DVG 137

Editor's Notes

  1. Sign extension without altering the sign and value extend it to 32 bits
  2. Search in KEIL
  3. Branch instructions
  4. Saturation doesn’t prevent distortion but saves the amount of distortion greatly
  5. LSL – logical shift ASR- Arithmetic shift
  6. Bit band access means in traditional arm need to perform or and later mask while selecting any peripherals
  7. If data is present at 1000 and next data 1005 it access 0x1004 first shift address by 1 and access the 1005 extra work this arrangement is available in microprocessor this complex is brought to microcontroller
  8. Typedef struct { Unsigned int long SYSTIC_CTRL ; Unsigned int long SYSTIC_RELOAD ; Unsigned int long SYSTIC_VALUE ; Unsigned int long SYSTIC_CALIB ; } ; #define SysTick((SYStick_TYPE)0xE000E010 ;
  9. Typeof struct { // variable and its datatypes } LOAD_FLASH 0x0000000 { SYSTICK(0xE000E010) } }