Microcontroller power consumption profiling (EFM32 series, SiLabs)


Two years ago, Silicon Labs absorbed another smaller company - this time a Norwegian manufacturer of low-power ARM-controllers EnergyMicro. Since then, SiLabs has been actively developing and promoting microcontrollers of the EFM32 series with a funny lizard on the case.

To business

If you had to read reviews on modern microcontrollers, then you will agree - among other things, it will definitely tell you about record-high performance and record-breaking low power consumption. It seems that this is simply the rule of good form in the club of MK manufacturers, but it happens that the template phrases of marketers make sense.

According to the documentation, the energy consumption of EFM32 is really low, you can verify this in practice using the utility for profiling the energy consumption of microcontrollers from Silicon Labs.

Under the cat, a review of the utility and practical tips on its use.

Hardware : EFM32WG-STK3800 debug board.
EFM32 microcontrollers are based on ARM Cortex-M0 +, Cortex-M3 and Cortex-M4 cores and differ in the set of peripherals and the amount of internal memory. There is a separate debug board for each series of microcontrollers, but all the boards are very similar and are sold at a price of 42 USD. I have a kit for EFM32 Wonder Gecko controllers.

Software part : platform for development and debugging of the Simplicity Studio project.
this is something like an aggregator of development tools for Silicon Labs microcontrollers (by the way, not only EFM32, but also the good old C8051Fxxx, Zigbee modules, etc.). Here is the IDE (gnu ARM eclipse), documentation, and about a dozen different auxiliary utilities, including the Energy Profiler. The full-fledged distribution of Simplicity Studio (Windows, MAC, Ubuntu) can be downloaded for free from silabs.com.

The main menu of Simplicity Studio immediately after installation:

Before connecting the debug board, relatively few tools are available, but you can already look around a bit: parametric search on microcontrollers is available on the left side (only SiLabs, of course), in the upper right corner there are three icons responsible for setting components included with Simplicity Studio. In general, the program itself monitors the release of new utilities and updates of its components, but you can configure it manually.

To start working with the board, just connect it to the computer via USB and select debug USB as the power source (the battery and USB from the target microcontroller are also available).

After the connection, the board is determined by the computer and all the components intended for the corresponding series of controllers (EFM32WGxxx) become available.

Acquaintance is easiest to start with a demo, since there are a lot of them in Simplicity Studio.

I select one of the examples for the EFM32WG-STK3800 - a simple program for working with the LCD display - and run it with the default settings.

Simultaneously with the launch of the program on the microcontroller, the energy measurement of the crystal begins. In real time, a graph of energy versus time is plotted, this is perhaps the most obvious part of the profiler.

Firstly, the graph shows the dynamics of changes in consumption during the execution of the program. Secondly, for the selected point on the graph and for the selected time interval, the exact and average values ​​of the measured indicators are available.

* The screenshot shows the moment when all available profiler functions are enabled. At the first start, the picture does not look so colorful. Plotting

can be stopped and resumed, the graph has a function of scaling along the time scale, and both the linear and the logarithmic scale can be set along the vertical axis. The logarithmic scale is a convenient tool for low currents, but the ability to simply scale the graph vertically is still sometimes not enough.

Several other useful functions are also available: displays on the graph of inputs to interrupt handlers (multi-colored vertical arrows) and the voltage level, export of measurement results to excel, etc.

But the most delicious is the correlation of the chart with the executable code. If the processor core supports tracing (Cortex-M3 and M4 are suitable), then a line of code will match any point on the Energy Profiler chart — clicking on the chart will highlight the line in the listing on the right. To determine too “gluttonous” functions and procedures, statistics of the operation of individual program functions are also used - under the graph you can see the distribution of energy consumed between them. Each function can be assigned a specific color, then on the graph it will be clear where it starts and ends.

All this beauty, in short, is implemented as follows :
A measuring module is built into the power circuit of the microcontroller on the debug board. Through it, the current and voltage values ​​are sent to the computer, as well as the value from the timer built into the measuring module. Together with the value of the instruction counter (SWO line), the data is processed and interpreted by the profiler.

The current, voltage and time from the beginning of measurements allow you to build a graph of energy consumption versus time, and the value of the command counter allows you to correlate each point with the line number and the name of the source code file.

Energy Profiler uses the .axf object file with debug data in the DWARF (Debug With Arbitrary Record Format) format, which is created when the project is compiled in debug mode and the libelf and libdwarf libraries determine the required line in the code.

About profiling your own project

The demo built into Simplicity Studio was reviewed above. When using Energy Profiler, there are also few pitfalls.

So, to profile your own project you need to be in the Simplicity IDE window to do the following:
  1. Add the SWOTraceSetup () trace configuration function to the project and call it when the controller is initialized.
  2. After compilation, create a new profiler configuration:
    • Run-> ProfilingConfigurations ... menu
    • click on Simplicity Energy Profiler for ARM -> New
    • specify the * .afx file in the Executable field
    • check the Enable Code Correlation checkbox on the Profiler tab
SWOTraceSetup ()
the function can be found in any example from the manufacturer, in help and many more where, but here I will add it too
void BSP_TraceSwoSetup(void)
  /* Enable GPIO Clock. */
  /* Enable Serial wire output pin */
#if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY) || defined(_EFM32_LEOPARD_FAMILY)
  /* Set location 0 */
  /* Enable output on pin - GPIO Port F, Pin 2 */
  /* Set location 1 */
  /* Enable output on pin */
  /* Enable debug clock AUXHFRCO */
  /* Enable trace in core debug */
  CoreDebug->DHCSR |= 1;
  CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
  /* Enable PC and IRQ sampling output */
  DWT->CTRL = 0x400113FF;
  /* Set TPIU prescaler to 16. */
  TPI->ACPR = 0xf;
  /* Set protocol to NRZ */
  TPI->SPPR = 2;
  /* Disable continuous formatting */
  TPI->FFCR = 0x100;
  /* Unlock ITM and output data */
  ITM->LAR = 0xC5ACCE55;
  ITM->TCR = 0x10009;

After that, you can start profiling (with preliminary assembly and compilation of the project and firmware of the microcontroller) with one click.

Since the utility uses absolute paths to source code files, it is better to compile the project before each profiling, away from harm.

Speaking about setting up the trace, you need to remember that the auxiliary AUXHFRCO RC generator is used for it. In theory, it is configured and started when the trace tuning function is executed, however, if it is assumed that the microcontroller often uses the "deep sleep" modes, in which this auxiliary generator is turned off, there may be different glitches. If EM2 and lower operating modes are used, it makes sense to manually adjust the AUXHFRCO power supply:


The auxiliary generator, providing the transmission of the value of the command counter via the SWO line, increases the power consumption by ~ 400 μA and slightly noises the measuring channel. If the optimization of the program is completed and you want to get accurate measurement results, you should disable the correlation of measurements with the executable code (read kernel tracing), i.e. remove the call to the SWOTraceSetup () function .

Profiling can also be carried out for the original target board, in this case the SiLabs brand board will serve as a measuring module between the target board and the computer. To do this, you will need:
  • Power the target board from the VMCU line on the Starter Kit and connect the SWO pins of the target microcontroller and the branded board.
  • Change the board operation mode - from the debug mode of the microcontroller located on the board to work in the external debugger mode. Setup is carried out in another utility that is part of Simplicity Studio - Kit Manager.

    Kit manager

Also popular now: