How is ARM Programming Different?

How is ARM Programming Different?

 

Programming ARM MCUs – What is Different?

There are very, very few engineers or electronics enthusiasts who started programming with ARM microcontrollers right away. Most come to ARM looking for higher processing capabilities, with a background in simple 8-bit MCUs.

In the previous article on How to Setup and Install the Development Environment for ARM , it was shown how to set up the Keil ARM tools to be able to compile programs and generate output files. However, before you proceed to writing programs for an ARM microcontroller, it is important to know some differences between ARM and the AVR, 8051 or PIC that you might have programmed in the past.

There are some very basic, fundamental differences in how they treat data and transfer data internally. Knowing these differences simplifies the understanding of ARM hardware for those who have programmed 8-bit microcontrollers in the past.

Register Sizes

The first major difference you will notice is in the size of registers. On AVR or other 8-bit microcontrollers, the user accessible register size is almost always 8-bit. The registers that must contain 16-bit data are usually accessed as a “high byte” and a “low byte”. It requires two read accesses to read 16-bit data.

This is different in ARM. The ARM core is 32-bit capable and is most efficient when used in 32-bit mode. Therefore, almost all register addresses are 4 bytes in width (32-bit). For example, to enable all pins of AVR port D as output, you would write

DDRD = 0xFF;                     // Set all 8 pins as output

But on ARM, to make all pins of port 0 as output, you would write

IO0DIR = 0xFFFFFFFF;     // Set all 32 pins as output

That being said, note that the port pin numbers may range from Pn.0 to Pn.31, as the I/O ports are also 32-bit wide. Of course, not all pins may be available externally – just like with 8-bit microcontrollers.

You may also be wondering – what if you want to switch one pin to high without affecting the rest? The typical process on an AVR would be:

  • Take the contents of the output register
  • Logical OR with binary pin data you want to SET (set to ‘1’)
  • Logical AND with compliment of binary pin data you want to RESET (clear, or set to ‘0’)
  • Write the result back to the output register.

This, in short is called the read-modify-write sequence and is time consuming because of so many steps. ARM addresses this problem by making it available in hardware. Instead of just a PORTn register to write the bit values of all pins, ARM microcontrollers offer mask registers such as IOnSET and IOnCLR. Writing a ‘1’ to any bit of the register clears or sets the bit and leaves other bits unaffected. This enables very fast I/O toggling and control (over 15MHz!).

System Structure

This section considers the LPC214x (NXP Semiconductors) to illustrate how sections are organized within the ARM7 microcontroller.

LPC214x block diagram

LPC214x Block Diagram

The central backbone network that can immediately be noticed is the VPB (VLSI Peripheral Bus). If you trace the bus upwards in the block diagram, you will notice that it originates from the AHB (Advanced High-performance Bus). The AHB runs at the same clock speed as the main ARM7TDMI-S core. The VPB obtains its clock from the AHB and the clock speed can be stepped down using a divider. The VPB connects all peripherals to the core. Therefore, the peripherals run at a speed lower or equal to the speed of the ARM core.

The interrupt controller and USB DMA (direct memory access) however run at the same speed as the core. This enables fast handling of interrupts and USB data transfers.

Share this post