Every microcontroller out there contains a processor which is responsible for performing all the actions on that microcontroller. Each processor is designed, based on a certain instruction set Architecture architecture. That architecture can be based on any type, for instance, ARM. Being our topic of discussion today let’s explore ARM Cortex-M4 microcontrollers architecture in detail.
Table of Contents
ARM Microcontroller Introduction
The abbreviation of ARM was later recognized as Acorn RISC Machines but with the time it has been upgraded to Advanced RISC Machines. The important point to discuss here is that ARM doesn’t develop microcontrollers silicon chip but it only provides IP core for a microprocessor and other building blocks of a microcontroller. ARM then provide it to the various manufacturer through licensing. The designs ARM provides are known as Intellectual Property (IP), and the business through which it sells the design is known as IP licensing.
ARM Cortex-M Microcontrollers Architecture
After enough discussion about ARM let’s move to the architecture designed by ARM name Cortex-M architecture. ARM Cortex-M architecture highly efficient, low cost and energy-efficient processor and it has been used in millions of customer devices. The reason for such diverse use of ARM Cortex-M profile is that its capabilities vary in a wide range from a vendor to vendor. It can be stated as “one microcontroller from one vendor using ARM Cortex-M will vary from other microcontrollers from a different vendor in hundreds of capabilities”. This flexibility is the main reason why these cores are widely used by hundreds of vendors to support additional features in a single microcontroller board.
As every manufactured device, ARM also have various versions and these versions keep on upgrading with time. Cortex-M belongs to the version of ARM names, ARMv7. Before this these were ARM versions named as ARMv4, ARMv5, ARMv6, and them comes ARMv7. Along with Cortex-M there are 2 other cores present in this architecture of ARM.
Cortex-M: Processors in these profiles are used for the development of microcontrollers based embedded systems. The Cortex-M family consists of Cortex-M0, Cortex-M0+, Cortex-M1, Cortex-M3, Cortex-M4 and Cortex-M7.
Cortex-A: Processors in this profile are used in high performance application devices like mobile/cellular phones.
Cortex-R: Main market of processors of this profile are in the real time application, where less response time is the main target.
ARM Cortex-M4 Introduction
ARM Cortex-M processors are used in microcontrollers family of ARM microcontrollers. It consists of 32-bit processor cores. The size of processor in terms of bits defines the maximum addressable range or the maximum address range it can handle. For example, ARM Cortex-M4 microcontrollers can handle 2^32 = 4GB of memory address space.
For further information on Cortex-M4 memory address and memory mapped peripherals, read the following article:
The 32-bit also means the size of internal registers of the processor. All internal registers such as general purpose and special function, are of 32-bit. Moreover, datapaths, functional units ( ALU) which perform arithmetic (addition, subtraction, multiplication, etc) and logical operations ( AND, OR, less than, greater than, etc) on data are also of 32-bit size. Bus interfaces such as memory/data buses are also 32-bit. Hence, size of functional unit, datapath, internal registers, interfacing buses, memory address range are the main factors that define the 32-bit size of ARM Cortex-M4 processor.
You may refer this article for further details:
Before discussing Cortex-M architecture, let’s first define what is architecture of a processor. Architecture of any processor is the instruction set or set of rules that defines the functionality of the microprocessor such as:
- Instruction loading
- Instruction decoding
- how it loads and stores data/instructions
- How processor access memory
There are two commonly used computer architectures i.e. Von-Numan and Harvard. Cortex-M microcontrollers are based on Harvard architecture that means they have separate instructions and data buses to access memory. That means the ARM Cortex-M processor can access both data and instructions at the same time.
Cortex-M4 Register Bank
The Cortex-M microcontrollers are based on the ARMv7 processor and this processor has a set of internal registers known as a register bank. This register bank consists of 16 registers ranging from R0-R16. First 13 registers from R0-12 are general purpose registers and last three from R12-R15 are special function registers.
General Purpose Registers (GPR)
General purpose registers are divided into two groups .i.e. lower registers (R0-R7) and higher registers(R8-R12). GPR are used to store addresses and data which is currently under process.
Special Function Registers
In special function registers, R13 (SP) is a stack pointer and it holds the address of the top element of the stack. R14 is a link register LR and it is used to store the return address of the functions. R15 (PC) is a program counter and it holds the address of the next instruction to be executed. Program counter value automatically increases by 4 after every instruction execution so that it points to the next instruction address.
Other than register bank, the processor also has special registers that contain the program status such as operational status, system interrupts. These status registers are:
- PSR ( Program status register)
Load Store Architecture
ARM Cortex-M4 is based on load store architecture. In a load store architecture, whenever a processor wants to perform operation on data which is stored inside memory, the processor first loads this data from memory to one of the internal registers of the processor. After processing, data will be written back to memory only if it is required.
ARM Cortex-M4 instruction Set Architecture
ARM Cortex-M4 microcontrollers are based on ARMv7 architecture. Hence, Cortex-M4 MCUs support thumb-2 instruction set architecture. Thumb-2 instructions support a mixture of 16-bit and 32-bit instructions.
The original architecture of ARM is an ARM instruction set architecture. ARM ISA is 32-bit long and provides efficient performance. But its major drawback is the low code density. Therefore, in order to improve code density, ARM provided a thumbs instruction set such as thumb-1 and thumb-2. Thumb-2 ISA contains a mixture of both 16-bit and 32-bit instructions to get the performance of original ARM 32 ISA and better code density with 16-bit instructions.
Cortex-M4 Main Components
ARM Cortex-M4 based consists of the following main building blocks as mentioned below:
- Processor core
- NVIC (Nested Vector Interrupt Controller)
- Debug system
- Bus system and bus matrix
A nested vectored interrupt controller is integrated inside the microcontroller chip. The main responsibility of NVIC is to handle interrupts, prioritize interrupts, and minimize interrupt latency. ARM Cortex-M4 microcontroller supports 240 system and peripheral interrupts and NVIC performs interrupts management with the help of an interrupt vector table. You can read this article on NVIC:
The processors developed on the Cortex-M profile are typically based on a 32-bit Reduced Instruction Set Computer (RISC) architecture.
Difference Between Cortex-M0, Cortex-M0, Cortex-M1, Cortex-M3 and Cortex-M4
Cortex-M is also divided into further categories Cortex-M0, Cortex-M1, Cortex-M3, and Cortex-M4. Where the first 2 falls under the ARMv6 family and Cortex-M3 and Cortex-M4 lies under the ARMv7 family. The relationship between Cortex-M3 and Cortex-M4 is the addition of DSP (Digital Signal Processing) in Cortex-M4. There’s another profile named Cortex-M4F which differs from Cortex-M4 by only a single unit name as FPU (Floating Point Unit).
The architecture of Cortex-M3, Cortex-M4 and Cortex-M4F are all the same and the only difference is as discussed above. On the other extreme we can say that Cortex-M4 is basically a cortex-M3 profile with the integration of a DSP unit in it. The instruction set architecture used in cortex-M4 is Thumb-2 which is a mixture of 32 bit ARM instruction set architecture and 16 bit Thumb instruction set architecture. However, cortex-M4 adds a range of SIMD (single instruction multiple data) instructions to optimize the use and functioning of digital signal processing.
ARM Cortex-M Microcontrollers Applications
Application of cortex-M4 mainly lies in the areas where we need intense digital signal processing or we want to do math related operating in floating point format. Cortex-M4 and Cortex-M4F can do these operations more efficiently and fast compared to Cortex-M3. However, if you are using Cortex-M4 for applications which do not need DSP or FPU than using cortex-M4 instead of Cortex-M3 will give you no better results as the architecture of both of them are same. Below is the list of applications Cortex-M4 supports, to name a few.
- Gaming equipment.
- Motion control.
- Medical instruments.
If you want to start learning ARM Cortex-M microcontrollers programming, you can read these getting started guides:
- Bare Metal Embedded Systems Build Process
- Microcontroller Booting Process
- What is Microcontrollers startup file
- Microcontroller Memory Organization and Types
- Bare Metal Embedded Systems Linker Script File
- How to use GPIO pins of TM4C123G Tiva launchPad
- Use Push Button to Control LED with TM4C123
- UART Communication TM4C123 Tiva C
- Bare-metal and RTOS Based Embedded Systems