ARM7 MCU Bus structure
ARM MCU has multiple bus structure. There are two types of Busses in ARM7 microcontroller – Advanced High performance BUS (AHB) and VPB bus. AHB is fast bus which is clocked directly by PLL and works at same speed as ARM core. So to AHB bus ARM core and Interrupt controller are directly connected while other peripherals are connected through VPB divider. VPB divider is capable to divide speed of AHB by 1; 2 and 4. so this means if VPB bus divider will be set to 4 and CPI core speed will be 60MHz, then MCU timer will run at speed 60/4=15MHz.
//C code snippet of VPB speed setting define divider:
#define PBSD 4
//define VPBDIV_VALUE needed to write to VPBDIV register
#define VPBDIV_VALUE (PBSD & 0x03)
//Write VPBDIV_VALUE to VPBDIV register to divide VHB frequency by PBSD:
VPBDIV = VPBDIV_VALUE;
When talking of buses wee need to mention, that there is one more bus connected to AHB via MAM (Memory Accelerator Module). MAM is used to accelerate Flash memory as it is capable to run at maximum speed of 20MHz while CPU core can run at like 80MHz. MAM is using some sort of cashing technique to achieve flach memory speed equal to cores peed.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Compressed Thumb instructions of ARM MCU
Submitted by admin on Thu, 01/04/2007 - 19:04
Thumb instructions
Thumb instructions shrinks ARM instructions from 32 bit to 16 bit length. This allows saving up to 40% of program memory comparing to ARM instruction set. Maybe this is main reason of Thumb instructions being used. Thumb instructions loose many properties of ARM instructions and become similar to traditional RISC instructions. Thumb instructions cant be conditional, data processing have a two-address format where destination register is one of source registers.
ARM instruction: ADD R0, R0, R1
Thumb instruction: ADD R0, R1
As Thumb instruction set takes less of program space it allows to upload bigger applications but with lower speed as using ARM instructions performance is up to 40% faster. But in non critical applications or functions speed isn't significant factor.
Also Thumb instructions doesn't have full access to all registers. Thumb instructions can only access “low registers”(R0-R7). And only few instructions can access “high registers”(R8-R12).
Thumb decoding
Thumb instructions has to be decoded-decompressed to equivalent ARM instructions while executed. This is handled in instruction pipeline. Pipeline has additional de-compressor logic in series to instruction decoder, which firstly decompress Thumb instruction and then decode. This usually results in decode latency.
Changing to Thumb mode
Changing to Thumb mode is done by setting T-flag in CPSR register. This is usually done by executing BX(Branche exchange) instruction to address where the Thumb code begins. So same memory space may contain ARM-code and Thumb-code.
Some interesting facts about using Thumb:
- The Thumb code requires 70% of the space of the ARM code.
- The Thumb code uses 40% more instructions than the ARM code.
- With 32-bit memory, the ARM code is 40% faster than the Thumb code.
- With 16-bit memory, the Thumb code is 45% faster than the ARM code.
- Thumb code uses 30% less external memory power than ARM code.
This means that where performance is needed a system should use ARM instruction set, where cost and power consumption is important use Thumb instructions. Sometimes is better to use combination of both instruction sets. Where high end ARM system uses Thumb code in non critical routines to save power and memory space.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ARM7 core instruction set explained
Submitted by admin on Thu, 01/04/2007 - 17:32
ARM7 architecture has normal 32bit ARM7 instruction set and compressed 16 bit instruction set so called “Thumb”. ARM7 instructions has a complex behaviour. As ARM processor programming is usually written in C there is no need to be ARM expert, but understanding of basics may help in developing efficient programs.
ARM7 datatypes
ARM7 processor can support following datatypes:
- 8 bit signed and unsigned bytes;
- 16 bit signed and unsigned half-words;
- 32 bit signed and unsigned words
But shorter then 32 bit datatypes are supported only by data transfer functions but when internally processed they are extended to 32 bit size. ARM7 core doesn't support floating point datatypes – they can only be interpreted by software.
ARM memory organisation
ARM7 is capable to store words in two ways depending on weather significant byte is stored. If word MSB is stored at highest byte then operation is called “little-endian” if MSB is stored at lowest position, then it is called “big-endian”.
Usually it is easier to work with little-endian for people as they expect to be LSB at lowest position. Endian is selected in compiler settings.
ARM conditional instructions
Comparing to other RISC microcontrollers almost all ARM7 core instructions are conditionally executed. As conditional branches are standard instructions ARM instructions were extended by adding 4 bit in the top of 32 bit instruction field:
As condition field has 4 bits, there can be 16 condition values. According to condition – instruction can be executed or skipped. As we know conditions depends on N, Z, C and V flags in CPSR register. Available conditions:
Don't use 'NV' as it will act as 'nop' operation. But it is reserved and may change in other ARM platforms. Behaviour of this is not guaranteed.
Conditional instructions are is one factor that keeps smooth program flow through pipeline. As we know when usual branch occur the pipeline is flushed and start refiling from beginning.
Practically speaking
if(x<100)
{
x++;
}
would compile in most efficient ASM code using one conditional command.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ARM7 instruction groups
ARM7 instructions split in six main categories:
- Branching;
- Data processing;
- Data transfer;
- Block transfer;
- Multiply;
- Software interrupt.
Branching allows jumping forwards and backwards up to 32MB.
There are two main types of branching:
- Branch jump with/without link exchange (link exchange means that current PC value is stored ir R14 link register);
- Branching with/without link exchange and with instruction set exchange between ARM<->Thumb(The only recommended instruction to swap between ARM and Thumb).
Data processing includes all Logical, adding/subtracting, testing instructions (conditional/unconditional) like AND, EOR, SUB, RSB, ADD, ADC, SBC, RSC, TST, TEQ, CMP, CMN, ORR, MOV< BIC, MVN.
For instance compiler C code: if(z==1) R1=R2+(R3x4) should compile optimally to like
EQADDS R1, R2, R3, LSL #2
Data transfer instructions are used to move signed/unsigned Word, half-Word and Byte data to and from selected register. LDR and STR mnemonics.
Block transfer instructions are used to copy multiple registers with single instruction. Using LDM and STM instructions it is possible Load and Store whole register bank or subset.
Multiply instructions used for multiply operations. There are two subsets of operands MUL, MLA for 32bit results and MULL, MLAL for 64 bit results.
Software interrupt instruction SWI transfers execution to address in memory location 0x00000008 and changes mode to svc. SWI instruction can also be conditional. SWI instruction has 24 unused bits that can be used for storing data or or custom code which can be decoded in svc mode. This feature is handy in embedded OS when making operating system calls.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ARM7 exception modes
Submitted by admin on Thu, 12/07/2006 - 13:02
This is an important part of understanding ARM operation modes and handling them. ARM7 supports seven types (0x00000014 address is reserved) of exceptions:
As you can see in the table each exception has its own name and fixed address so called exception vectors. When exception occurs, execution is forced from fixed memory address corresponding to the type of exception. When exception occurs R14 and SPSR registers acts like this:
SPSR_<mode>=CPSR;
CPSR[4:0]=exception mode number;
//execute in ARM state
CPSR[5]=0;
//disable fast interrupts
if (<mode>==reset or FIQ) CPSR[6]=1;
//disable normal interrupts
CPSR[7]=1
PC=mode vector address
Each exception has priorities. Table bellow shows how priorities are assigned to exceptions:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ARM7 MCU registers
Submitted by admin on Thu, 12/07/2006 - 11:46
ARM has 31 general purpose 32 bit register where 16 of these are visible at any time. Other registers are used to speed up processing of exceptions. There also is 6 32bit wide status registers. Lets see how it looks like. Registers are arranged in partially overlapping banks with a different register ban of each MCU mode. As I mentioned at any time 15 general purpose registers(R0 to R14) and one or two status registers and PC are visible.
Basically R0-R12 registers are user register, that doesn't have special purpose. Registers R13 – R15 has special functions. R13 is used as stack pointer (SP), R14 is used as link register (LR) and R15 is as program counter (PC):
Additionally there is a Program status register CPSR which contains a number of flags of program status and control information. All modes have saved program status register SPSR of CPSR register except User/system mode.
- The N bit is the "negative flag" and indicates that a value is negative.
- The Z bit is the "zero flag" and is set when an appropriate instruction produces a zero result.
- The C bit is the "carry flag" but it can also be used to indicate "borrows" (from subtraction operations) and "extends" (from shift instructions (LINK)).
- The V bit is the "overflow flag" which is set if an instruction produces a result that overflows and hence may go beyond the range of numbers that can be represented in 2's complement signed format.
- The I and F bits which determine whether interrupts (such as requests for input/output) are enabled or disabled.
- The T bit which indicates whether the processor is in "Thumb" mode, where the processor can execute a subset of the assembly language as 16-bit compact instructions. As Thumb code packs more instructions into the same amount of memory, it is an effective solution to applications where physical memory is at a premium.
- The M4 to M0 bits are the mode bits. Application programs normally run in user mode (where the mode bits are 10000). Whenever an interrupt or similar event occurs, the processor switches into one of the alternative modes allowing the software handler greater privileges with regard to memory manipulation.
ARM7 MCU has six operation modes and each mode has its own register configuration. For instance FIQ interrupt mode has duplicated R7 – R12 registers, program doesn't have to preserve registers in to stack. And of course R13 – R15 registers are duplicated in each following mode. Other registers (R0 to R7) are un-banked what means they are physically same and accessible in all modes.
ARM7 is a load-and-store architecture, where before processing any instruction the data has to be moved from memory to set of registers after execution data is stored back into memory.
Hi,
ReplyDeletei have a JOB for you on LPC2468 based board, if interested please email me for more details:
ouaret.nabil@digiuslinkalgeria.com
thx