I wrote about what microcontrollers are in a previous article. In this article I will write about how you might go about picking the right microcontroller based on your needs and the processor architecture.
Introduction
The goal of an embedded developer is to leverage a microcontroller in order to push out a product to the market. However, when that product hits the market, the questions that the consumers ask are usually related to the cost of the product or the features and capabilities that it provides.
For example, when a user is about to purchase a device for measuring their blood glucose levels, they want to know how frequently they will need to replace the battery, and how easy it is to get supplies for the device. They don’t ask how fast the device is, or how much storage it has got.
On the other hand, the embedded developer needs to make a choice based on a number of things such as which device the program is going to fit on, and what mathematical computations the device would need to be capable of supporting.
Consider how you might purchase a laptop using either of the two approaches below:
Purchase the laptop using only price as a factor and picking whatever fits into your budget.
Purchase the laptop by specifying what peripherals must be available, and then purchasing the cheapest one that meets your requirements. For example, you would like a dedicated GPU but are fine with a 128GB SSD.
Picking a Microcontroller
When it comes to picking a microcontroller, the process is a bit more involved. You might want to take the following into consideration:
Form factor
Power
Onboard storage
Processor frequency
Processor architecture
Let’s start with the processor architecture by looking at “the Amazon of computer electronics”, a site called digikey.com.
A quick look at all MCUs on digikey shows a manufacturer column. At this point you might want to ask what the difference is between Arduino, Arm, and Atmel. Is it the same as the difference between Intel and AMD?
The answer lies in the instruction set architecture (ISA). This is also called computer architecture. On desktops (or Personal Computers) powered by Intel and AMD processors, both processor manufacturers design them on top of the x86 ISA. The x86 ISA implements what is called Complex Instruction Set Computing (CISC).
Most MCUs utilize a processor that is based on Reduced Instruction Set Computing (RISC). However, unlike in the desktop world, the ISA can vary. There is a Wikipedia entry for a comparison of various ISA here.
We want an MCU that is based on a processor that utilizes an Arm ISA. By scrolling further down the page on digikey you will find a listing similar to the following.
There are two entries highlighted in the image above. By looking at the last column, which is labeled Core Processor, you will find that both MCUs utilize an ARM Cortex-M0+. You will also see on the screen that the other devices utilize an AVR Core Processor. AVR is an 8-bit ISA that was developed by Atmel, a company that was acquired by Microchip.
The Cortex M processors are designed to be easy to use and are found in a large number of embedded systems!
Going back to the Supplier column, you can see that the two highlighted MCUs are supplied by two different companies, SparkFun Electronics and Arduino. These are not the only companies that supply Arm-based MCUs.
By going back to the filter section and looking down the core processor section, we see a number of entries with the Arm name. We can see an ARM Cortex M3 and an ARM Cortex A15. If you are wondering what the ARM Cortex is, then we are almost there. The next point of call is the Arm website.
There are three entries with a Cortex name on the website. I will summarize them below as follows:
Cortex A: for compute intensive tasks such as phones and single-board computers (SBCs) such as the Raspberry Pi 4.
Cortex R: for real-time applications such as in automotive uses
Cortex M: for use in resource-constrained applications.
For embedded systems, what you want is a Cortex M processor. But, why do we have numbers such as M3 and M7?
Cortex M and M-Profile Architectures
According to the Arm website, the M in Cortex M stands for Microcontroller! That’s just brilliant.
Again, from the Arm website, it states that Arm produces a family of processors that share common instruction sets and have a certain degree of backwards compatibility. The M-Profile provides low-latency operation for embedded systems.
There are three ISAs on the Arm website:
A64: introduced in version 8 of the Arm architecture generation for 64-bit computing
A32: introduced in version 6 of the Arm architecture generation for 32-bit computing
T32: a 16-bit and 32-bit mixed-length instruction set.
The M-Profile architectures utilize the T32 instruction set along with some optional architecture extensions. They do not implement a Memory Management Unit (MMU).
The following Cortex M processors are listed on the Arm website as of November 2021:
Cortex-M0: smallest processor, ideal for smart sensors and SoC
Cortex-M0+: most energy-efficient processor, ideal for wearables (healthcare, fitness, etc)
Cortex-M1: optimized for Field Programmable Gate Arrays (FPGA)
Cortex-M3: energy-efficient use in smart home devices
Cortex-M4: ideal for industrial applications
Cortex-M7: highest performance with in-built floating-point processing
Cortex-M23: smallest processor with TrustZone security, ideal for energy-harvesting IoT nodes and small sensors
Cortex-M55: most AI-capable, with optimized software libraries
Cortex-M33: has a blend of real-time determinism, efficiency, and security
Cortex-M35P: a processor with tamper resistance built in
A quick search for “ARMv6-M Architecture Reference Manual” will lead you to a 436-page manual with probably all of the information you will need in order to understand all of the Cortex-M architecture. The following bits of information might prove useful:
The processors support the following data types in memory:
Byte: 8 bits
Halfword: 16 bits
Word: 32 bits
Doubleword: 64 bits
Registers size: 32 bits
Register data types:
32-bit pointers
32-bit integers (signed and unsigned)
8-bit and 16-bit integers (signed and unsigned)
64-bit integers (signed and unsigned) held in two registers
Registers:
General Purpose: 13 (R0 to R12)
Special Purpose:
Stack Pointer (SP)
Link Register (LP)
Program Counter (PC)
Special-Purpose Program Status Registers
Memory Address Space: flat, 2^32 8-bit bytes
The following image is taken from the Arm Cortex-M0 Processor Datasheet.
Board Selection
Once you have settled on the processor you would like, you can then proceed to find an “implementation” that meets your requirements. In the following example, I pick on the Cortex-M0+ processor and filter down on digikey.com
The first item there is a Pro Micro RP2040 from SparkFun. The RP2040 has some documentation on the SparkFun website.
The RP2040 is available as the Raspberry Pi Pico, “a new flexible $4 microcontroller board from Raspberry Pi”.
At this point you can read through the technical specifications of your chosen MCU board to see if it will meet your requirements. One advice I find useful is to pick the largest board you can afford and prototype on it. You can then pick a smaller one on your next iteration if you find that you have excess capacity. If you pick a board that is too small you will find yourself trying to rewrite your code to fit your constraints.
You should get used to reading the specifications of any board you are interested in. More importantly, I hope that this article has taught you to check for the core processor that your MCU is running. Here is an example specification of the Raspberry Pi Pico below.
If you look back at the various Cortex M processor classes, you will find that the Cortex-M4 is meant for industrial applications. I would like to mention the SparkFun Edge development board that I used as the header image for this article. It features a 32-bit Arm Cortex-M4F processor with Direct Memory Access running at 48MHz with 1MB Flash and 384KB SRAM. It comes with a number of sensors onboard which I will be utilising for some articles in the future. You can get the board here.
Summary: Why Arm Cortex-M?
The Cortex-M family of processors are versatile and are manufactured by a large number of vendors. They implement a 32-bit RISC architecture with a number of the processors being backwards compatible. Development is easy and Arm provides free tools to help you get started. We will get into programming these MCUs in another article.
Comments