Compressed Thumb instructions of ARM MCU

Thumb instructions Thumb instructions shrink ARM instructions from 32 bit to 16-bit length. This allows saving up to 40% of program memory comparing to the ARM instruction set. Maybe this is the main reason for Thumb instructions being used. Thumb instructions lose many properties of ARM instructions and become similar to traditional RISC instructions. Thumb instructions cant be conditional. Data processing has a two-address format where the destination register is one of the source registers. ARM instruction: ADD R0, R0, R1 Thumb instruction: ADD R0, R1 As the Thumb instruction set takes less program space, it allows to upload bigger applications, but with lower speed than using ARM, instructions performance is up to 40% faster. But in noncritical applications or functions speed isn’t a significant factor. Also, Thumb instructions don’t have full access to all registers. Thumb instructions can only access “low registers”(R0-R7). And only a few instructions can access “high registers”(R8-R12).

Continue reading

ARM7 core instruction set explained

ARM7 architecture has a normal 32bit ARM7 instruction set and a compressed 16-bit instruction set, the so-called “Thumb.” ARM7 instructions have complex behavior. As ARM processor programming is usually written in C, there is no need to be an ARM expert, but understanding the basics may help develop 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 than 32-bit data types 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.

Continue reading

ARM7 exception modes

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 an exception occurs, execution is forced from a fixed memory address corresponding to the type of exception. When an exception occurs, R14 and SPSR registers act like this:

Continue reading

ARM7 MCU registers

ARM has 31 general purposes 32-bit registers where 16 of these are visible at any time. Other registers are used to speed up the processing of exceptions. There also are 6 32bit wide status registers. Let’s see how it looks like. Registers are arranged in partially overlapping banks with a different register ban of each MCU mode. As I mentioned, 15 general-purpose registers(R0 to R14) and one or two status registers and PC are visible at any time. Basically, R0-R12 registers are user register, that doesn’t have a 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 the program counter (PC):

Continue reading

How does ARM7 pipelining works

One of the key features of the fast performance of ARM microcontrollers is Pipelining. ARM7 Core has a three-stage pipeline that increases instruction flow through the processor up to three times. So each instruction is executed in three stages: Fetch – instruction is fetched from memory and placed in the pipeline; Decode – instruction is decoded and data-path signals prepared for the next cycle; Execute – instruction from prepared data-path reads from registry bank, shifts operand to ALU, and writes generated result to dominant register. Pipelining is implemented at the hardware level. The pipeline is linear, which means that in simple data processing processor executes one instruction in a single clock cycle while individual instruction takes three clock cycles. But when the program structure has branches, the pipeline faces difficulties because it cannot predict which command will be next. In this case, the pipeline flushes and has to be refilled what means execution speed drops to 1 instruction per 3 clock cycles. But it isn’t true, actually. ARM instructions have nice features that allow for the smooth performance of small branches in code that assure optimal performance. This is achieved at a hardware level where PC (Program Counter) is calculated…

Continue reading

Quick start using WinARM

WinARM is a collection of GNU tools for the ARM MCU family packed by Martin Thomas that works on MS Windows. WinARM is developed by inspiration on the WinAVR project, and it is effortless to start working with it if you had a chance to try WinAVR. WinARM doesn’t depend on Cygwin, or MinGW-environment like GNUARM tools do. WinARM toolset is compiled to work with most ARM microcontrollers, including the LPC2000 series, Atmel’s ARM microcontrollers, and Analog devices ARM microcontrollers. Basically, tools should work with any microcontroller with ARM architecture.

Continue reading

Using LPC2000 flash ISP utility to program LPC2148

As I earlier was writing about my homemade ARM7-Base development board for LPC2148 It is time to write few words on how to use LPC2000 flash ISP utility. LPC2000 flash utility is a software that is used to program LPC2000 series ARM microcontrollers: LPC2101, LPC2102, LPC2103, LPC2104, LPC2106, LPC2106, LPC2114, LPC2114, LPC2119, LPC2124, LPC2129, LPC2131, LPC2132, LPC2134, LPC2136, LPC2138, LPC2141, LPC2142, LPC2144, LPC2146, LPC2148, LPC2194.

Continue reading

RTC example on ARM7 LPC2148 using WinARM

Finally got my LPC2148 RTC working on my development board. arm7 base development board for lpc2148 I am quite new to ARM microcontrollers, so I managed to make a few tests using them by driving some peripherals and writing some test routines. The first code I tried was a simple LED blink program first lpc2148 arm7 microcontroller test led blink This one is running microcontrollers’ real-time clock (RTC) and generating interrupts every second. When Interrupt occurs, the microcontroller sends a particular message to UART that I could see via the Terminal program. The main program: And zipped project files:RTC clock example on ERM7 LPC2148 using WinARM

Continue reading

Increase microcontroller code efficiency

C compilers are getting more advanced, but there is always a trade-off between speed and code size. Compiled code can be faster or smaller, but not both. So you have to choose which part is more important speed or code size. The Increase in microcontroller code efficiency can be done in many ways. Don’t trust compiler optimization features, as they might not be as effective as you expect. It is better to grab some profiler and inspect what parts of your code take the most time and size. It is better to follow some techniques that may reduce code execution time and increase microcontroller code efficiency:

Continue reading