Application Development

This post introduces basic tools to develop microcontroller applications for beginners. If you are interested in how to develop real applications on the market, you can also take a look our application notes here.

1. C and assembly

In order to harness the power of MCUs one must both familiarize oneself with the available hardware as well as the development environment made available by the MCU vendor or third parties. The desired functionality is usually available through high level language, such as C, and by setting the appropriate values in the control registers of the peripherals.

Example 1. C code snippet, comments are surrounded with /* and */

/* Wait until counter value of the
peripheral TIMER0 is over 1000 */
while(TIMER0->CNT < 1000){
/*Do nothing, just wait */

If a high level language is not an option or a more fine grained control of the program is desired, an assembly language can be used. Assembly languages are dependent on the architecture of the processor used as well as the compiler. Assembly is also more difficult to write and maintain than high level languages such as C. It is becoming increasingly rare to be used for application development.

Example 2. Assembly (Thumb-2) version of the code snippet from Example 1.
LDR.N R0,        TIMER_CNT
MOV.W             R1, #1000
LDR                  R2, [R0]
CMP                 R1, R2
BCC.N              loop_start

2. Registers

The functionality of a peripheral is controlled by setting bits in the appropriate registers,see Figure 2.1. The word length of an architecture is the working unit, i.e. the number of bits of a number, or a pointer the architecture can naturally work with. Common word lengths for MCUs are 8-, 16- or 32-bit. The registers of the peripherals have the same size as the word length, although not all of the bits may be in use. A single attribute might be controlled by setting a single bit to 1 or 0, or by setting a bitfield consisting of two or more bits to the appropriate binary value.

Figure 2.1.  An example of a 32-bit register with a byte and bitfields marked

Figure 2.2.  The figure shows how the registers are placed in the modules.

3. Interrupts

There are several ways of triggering actions based on events. The first is to write a piece of code that constantly check some conditions, i.e. the value of a given bitfield in a register, and trigger actions based on that value. This is called polling, and is not ideal since the CPU is constantly doing work even though there might be nothing happening. A better approach is to use interrupts. Interrupts can be set in hardware to trigger a piece of code, called an interrupt handler, given some event. This means that a small piece of hardware can be awake checking if the conditions are met, while the CPU and other peripherals are asleep, i.e. turned off to save power. When the event occurs the interrupt is generated,
which wakes up the CPU and execute the interrupt handler. An even better way is to use Direct Memory Access (DMA) to do work without having to wake up the CPU.

4. Kits

To help development of MCU based products and to facilitate learning, the MCU vendors often produce development kits. They consist of the MCU attached to a printboard together with common I/O devices such as buttons and a display. It is also easy to attach custom hardware, and to connect the kit to a PC in order to download software as well as to debug software running on the MCU. There are many available kits for the EFM32, but in Energy Micro University, we will only consider the EFM32 Giant Gecko Starter Kit and EFM32 Tiny Gecko Starter kit.

5. PCB

MCUs are usually mounted on a Printed Circuit Board (PCB) together with other components. The MCU connects external peripherals through its pins. Some features might need more than one pin – the related pins are referred to as a port. Some pins may have a fixed functionality, e.g. ground, power supply or controlling a Light-Emitting Diode (LED) or a Liquid Crystal Display (LCD). Others are more generic, these are called General Purpose Input/Output (GPIO).

Energy Micro University is a program developed by Energy Micro to encourage learning and to help institutions develop their own programs for teaching microcontroller development. To download learning materials in pdf, please click here: Energy Micro University Program

For technical questions about this project, please use our support forum