Microcontrollers 101

In this article we are going to introduce microcontrollers and explain what they are and why those are so popular nowadays. We are going to look into the minimum set of tools that you would need to approach this topic.

What is a microcontroller

A Microcontroller unit or MCU is a single chip that integrates one or more CPUs, RAM and Flash memory and some low level I/O peripherals such as GPIO, UART, SPI, I2C, etc.

An MCU is relatively small and does not requires too many external components to work. An MCU typically embeds in the same package the CPU, memory and peripherals which is why it’s often referred to as an Embedded System.

Difference between CPU and MCU

A Central Processing Unit (CPU) is the main chip in a computer responsible for carrying out all tasks. Those tasks are provided in the form of instructions and those instructions are described in the software that runs on that CPU.

A CPU is designed to perform large complex operations such data elaboration or graphic processing. These devices operates at a clock speed of GHz and are coupled to fast RAMs operating at the same speed and having size in the order of GB. As the RAM cannot retain data when powered off, the system typically comes with Non-Volatile Memories (NVM) such an SDD with a size in the range of hundred of GBs.

A diagram of the VonNeumann architecture

A Micro Controller Unit (MCU) is more focused on power efficiency and real time operations. These devices are equipped with a CPU that operates at a clock speed of dozens of MHz, coupled with the RAMs large amount of MB and NVM with a size that can have hundreds of MBs. The peripherals of a MCU are also different from those of a traditional computer system: those are typically converters, signal generators or communication peripherals that are more suitable to target the hardware that typically an MCU has to interact with.

A block diagram of a Microcontroller

Why microcontrollers?

Microcontrollers are designed to interface hardware such motor controllers, sensors, small displays and radio frequency transceivers. They can operate with a small amount of power such that provided by a coin battery and are very easy to integrate into small devices. Because of that MCUs are nowadays largely use in applications where high computational power is not a requirement.

Microcontroller software development is also very accessible due to easy to find development kits and open source software. It is also very easy to find controllers, sensors and displays specifically designed to be interfaced with MCUs. Being able to put those building blocks together and enable them by writing embedded software allows users to build smart devices to which we are nowadays very used to. They can be found in your smartwatch, in your coffee machine and even in the trunk of your car.

The development process

The process of writing and running firmware on a microcontroller can be summarized as follows:

  1. Outline a series of instructions in a programming language
  2. Build the code and check syntax errors. The result of this operation will be a binary file which is also called Firmware or FW
  3. Flash the firmware in the MCU memory
  4. Run the firmware, detect and debug any unexpected behaviour
  1. Amend the code
  2. Build the code

The process ends when the firmware fulfills the original requirements.

MCU development flow

During the development phase it may be necessary to repeat this process multiple times to achieve the expected behaviour: every change to the code required to re-build, to re-flash the FW and to debug again.

Hence, developing firmware for a microcontroller sees two entities at play: a PC that runs some sort of Integrated Development Environment (IDE) and a Development board that hosts the MCU. During the development phase these two entities are interacting closely, when the development is over the MCU can be powered by an external source and run independently from the PC.

Dev kits and Toolchains

The MCU itself is a single chip that needs to be soldered onto a custom PCB. Therefore to speed up the evaluation and development phases, MCU producers offer Development kits. These kits are essentially a single PCB that hosts:

  • The MCU to evaluate or to develop with
  • A USB debugger/bootloader
  • A power section that powers the entire system typically sourced from the USB
  • Some LED, buttons, connector and peripherals that can be used by the User via software

Professional kits typically come with a debugger that serves also as a bootloader and this is very useful as a debugger provides some additional features that speed up the debugging process. To develop firmware we need a minimum set of tools that are often grouped in what is defined as the Toolchain:

  • Specific SW libraries designed for the MCU in use
  • A cross compiler able to build binaries suitable for the architecture of the MCU in use
  • A bootloader interface or optionally a SW debug interface that puts the MCU in communication with PC during the debugging phase
  • Some sort of IDE that facilitates the code development and offers a Graphical User Interface for debugging

Example: Analog Devices SDP-K1 + ChibiStudio

As an example let’s analyse the scenario in which we are developing using the SDP-K1 with Chibistudio and list the various component on the Dev Kit and Toolchain.

Chibistudio + SDP-K1

The SDP-K1 is a dev kit from Analog Devices that hosts an STM32F469 microcontroller:

  • The MCU is the STM32F469, an ARM Cortex M4 from STMicroelectronics
  • The USB debugger is a CMSIS Dap Link that also offers a Virtual COM Port and bootloading capability
  • The power section on board is supplied via the debugger USB
  • It offers 4 programmable LEDs, an Arduino Uno connector and the ADI 120 pin connector

ChibiStudio is a free and open source toolchain that includes all the tools needed to start to develop right away at no cost using ChibiOS

  • ChibiOS is a set of libraries that supports many Microcontrollers and many peripherals. It also offers a multithreading Real Time Operating System that can be very handy in some applications
  • The cross compiler is GCC for ARM
  • The debugger SW interface is a GDB server known as OpenOCD
  • A bootloader interface or optionally a SW debug interface that puts the MCU in communication with PC during the debugging phase
  • The IDE is Eclipse for C/C++

Be the first to reply at Microcontrollers 101

Leave a Reply