Child pages
  • Using the IDD Current Measurement Feature on the STM32L053 Discovery Board
Skip to end of metadata
Go to start of metadata


The STM32L053 Discovery board from STMicroelectronics features an STM32L053C8 MCU, taken from their STM32L0 ultra-low-power series of microcontrollers. Among other features, this board includes a current measurement module that may be read by the MCU, allowing it to monitor its own current consumption. Unfortunately, the lack of documentation on this feature makes it rather difficult to utilize for evaluation purposes. Thanks to ST's example code, though, a basic procedure for communicating with the module was established and used to develop a more streamlined example application. Combined with the information from the Low-Power Modes on the STM32L0 Series  page, this application allows the user to observe how each low-power mode on the STM32L053C8 affects the MCU's current consumption.


ST offers three types of development boards: the Nucleo boards, Discovery boards, and Evaluation boards. The Nucleo boards are the simplest and cheapest. Besides including a built in ST-LINK/V2 debugger/programmer like the rest of the development boards, they do little more than break out the I/O lines of the featured MCU and provide a few pushbuttons and LEDs. The Evaluation boards, on the other hand, are far more expensive because they come with all the hardware required to evaluate every feature of the MCU the board is based on. The Discovery boards are a compromise. They come with only the necessary components for demonstrating specific device characteristics. Consider the key features of the STM32L053 Discovery board (Figure 1):

  • STM32L053C8T6 microcontroller featuring 64 KB of Flash memory, 8 KB RAM in an LQFP48 package.
  • On-board ST-LINK/V2-1 with selection mode switch to use the kit as a standalone ST-LINK/V2-2 (with SWD connector for programming and debugging)
  • mbedTM-enabled (
  • USB ST-LINK with re-enumeration capability and three different interfaces:
    • virtual com port
    • mass storage
    • debug port
  • Board power supply: through USB bus or from an external 5 V supply voltage
  • External application power supply: 3 V and 5 V
  • One linear touch sensor or four touchkeys
  • IDD current measurement
  • 2.04" E-paper display, 172X72 pixels
  • Four LEDs:
    • LD1 (red/green) for USB communication
    • LD2 (red) for 3.3 V power-on
    • Two user LEDs: SD3 (green), LD4 (red)
  • Two pushbuttons (user and reset)
  • Extension header for LQFP48 I/Os for a quick connection to the prototyping board and easy probing
  • Comprehensive free software including a variety of examples, part of STM32CubeL0 package

The main differences between this board and a similar Nucleo board are the linear touch sensor, IDD current measurement, and E-paper display. This makes sense considering that the featured MCU, i.e. the STM32L053C8, is an ultra-low-power microcontroller with touch sensing capabilities. In the following sections, the IDD measurement module is further explored so it may effectively be used to evaluate the low-power features of the STM32L0 series of MCUs.


Figure 1: The STM32L053 Discovery board

The following documents are very helpful when developing applications on the STM32L053 Discovery board:

Measuring Current Consumption

Section 6.1.8 of the STM32L053 datasheet shows that the preferred method of measuring the current consumed by the MCU is a high-side sensing scheme (Figure 2). That is, the current sensing device is placed between the voltage supply and the load (the MCU). The STM32L053 Discovery board uses this approach to implement its current  measurement feature. In short, this feature allows the user to measure the current consumed by the STM32L053C8 either by using their own current measurement instrument or by using the onboard current measurement module.


Figure 2: Current consumption measurement scheme suggested by the STM32L053 datasheet


Jumper JP4 on the Discovery board will enable or disable the IDD measurement feature. Figure 3 is a high level representation of how JP4 directs the flow of current. If the jumper is placed over pins 1 and 2 (the OFF position), then VCC is connected directly to the MCU and current cannot be measured. If the jumper is placed over pins 2 and 3 (the ON position), then current will flow from VCC, through the IDD measurement module, and then to the MCU. In this configuration, the MCU can communicate with the module and request the instantaneous current consumption.

In order to measure the current using an external device, like an ammeter, the jumper should be removed entirely. Then, the leads of the instrument should be placed on pins 1 and 2 in order to complete the circuit and still conform to the high-side sensing scheme.  


Figure 3: High-level representation of the connections made by JP4


IDD Measurement Module

Once JP4 is in the ON position, the user needs to know how to read the current measurements. The Discovery board's datasheet provides no information on this topic (other than mentioning that the measurement range is 50 mA to 100 nA). A simple operating procedure was deduced by studying the board's schematic and demonstration code. The module can plainly be divided into 2 parts: the current sense resistor network and the Multi-Function eXpander (MFX). The resistors create a voltage signal proportional to the rate of current flow, which is amplified before being read by the MFX. Not only does the MFX translate this voltage into a current measurement and report it to the MCU, but it also acts as a controller for the resistor network, configuring the total shunt resistance to the optimal value for the amount of current being consumed by the MCU.

Current Sense Resistors

Figure 4 shows the circuit that measures the current being consumed by the MCU. There are four current sense resistors in this circuit (1Ω, 24Ω, 620Ω, and 10kΩ) that have been highlighted by purple boxes. Three of these resistors are placed in series with MOSFETS whose gates are connected to GPIO pins on the MFX. In this way, the MFX can change the total shunt resistance by turning on various combinations of these MOSFETs. This is necessary to ensure that the amplified voltage across the shunt resistance does not exceed 3.3 V while small changes in current still produce a significant change in voltage. Note that there is a fourth MOSFET connected to the MFX that is used for calibration purposes.

There are four op-amps shown in Figure 4 that are used to amplify the voltage drop across the shunt resistance. The two labeled U7B and U7D are simply used as voltage followers in order to isolate the current sense resistors from the differential amplifier. U7C is used to implement said amplifier along with resistors chosen to provided a gain of 49.9. Finally, U7A is another voltage follower used to provide a bias voltage of 0.14814 V to the differential amplifier. This alters the output voltage equation as follows:

The offset is likely meant to correct for the voltage drop across the MOSFETS.


Figure 4: Circuit diagram of current measurement circuitry (from page 37 of the Discovery board user manual)


Multi-Function eXpander

The MFX is simply an STM32L152 chip loaded with firmware allowing it to act as a touch screen driver, I/O expander, and IDD controller. Only the last of these functions is taken advantage of on the STM32L053 Discovery board in order to abstract the above-mentioned current measurement circuitry from the master MCU (the STM32L053C8). Using an I2C bus, the MCU can control the MFX (at address 0x84) by configuring the registers defined in the mfxstm32l152.h file. This file is part of the STM32CubeL0 package and can be found by navigating to en.stm32cubel0/STM32Cube_FW_L0_V1.6.0/Drivers/BSP/Components/mfxstm32l152. The Excel document provided at the end of this section entitled "MFXSTM32L152_registers.xlsx" is a register map of the MFX common registers and the IDD control registers.

Figure 5 shows the MFX schematic. Notice the net labels that are shared between Figures 5 and 4, which reveal how the MFX interfaces with the resistor network. More importantly, however, are the labels enclosed in hexagons with yellow fill. These are bidirectional ports that are used to interface with other chips on the discovery board. In particular, the MFX_I2C_SDA, MFX_I2C_SCL, MFX_IRQ_OUT, and MFX_WAKEUP ports implement communication between the MFX and the MCU. These ports are connected to pins PB9, PB8, PC13, and PA1 of the STM32L053C8, respectively.

Figure 5: MFX wiring diagram (taken from page 37 of Discovery board user manual)

Because no official documentation on the MFX is available, the demo application for the STM32L053 Discovery board had to be studied in order to determine the correct the initialization procedure. This demo application was also found in the STM32CubeL0 folder, and the specific files used for current measurement were found in the en.stm32cubel0/STM32Cube_FW_L0_V1.6.0/Projects/STM32L053C8-Discovery/Demonstrations/Modules/iddmeasurement directory. From these files, the example function in Listing 1 was written on order to demonstrate how the MFX should be initialized to properly control the shunt resistors and send an interrupt signal to the MCU. The basic procedure is outlined as follows:

  1. A software reset is performed on the MFX to place it into a known state. A delay of 100 ms is placed immediately after this action in order to give the MFX registers time to be cleared.
  2. The IRQ_OUT signal is configured to inform the MCU that an MFX event has occurred. First, the physical pin on the MFX chip is configured as push-pull, active high (meaning that when an event occurs, the MFX_IRQ_OUT pin state will change from low to high). Then, the events which trigger the IRQ_OUT signal are selected. In this example, the "IDD" and "ERROR" events are chosen, i.e. the IRQ_OUT pin will be set either when an IDD measurement is ready or when any error occurs within the MFX. Notice that at the beginning of the Idd_Init() function, pin PC13 on the MCU is configured to trigger an interrupt on a rising edge.
  3. The IDD measurement function is enabled on the MFX
  4. The current measurement parameters are assigned to the MFX. These include the values of the current sense resistors and the gain of the differential amplifier. Also assigned is the minimum voltage (VDD) that may be applied to the MFX before a reset will occur. Since the registers that contain these values are located sequentially in memory (addresses 0x82 to 0x8F), the example function fills an array with the values to be written and then writes all 14 values to the block of memory at once.

Listing 1: Example of initializing the MFX for IDD measurements
void Idd_Init( void )
    uint8_t params[14];
    /* Initialize GPIOs */
    // PC13: recieve MFX_IRQ_OUT signal
    RCC->IOPENR |= RCC_IOPENR_GPIOCEN; // enable clocks
    GPIOC->MODER &= ~( GPIO_MODER_MODE13 ); // Input mode
    // Configure external interrupt on MFX_IRQ_OUT (PC13)
    SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PC; // PC13 is source for EXTI
    EXTI->IMR |= EXTI_IMR_IM13; // interrupt request from line 13 masked
    EXTI->RTSR |= EXTI_RTSR_TR13; // rising trigger enabled for input line 13
    // NOTE: I2C pins are configured in I2C_init function
    /* Initialize MFX */
    // reset MFX ( SYS_CTRL = SWRST )
    params[0] = 0x80;
    I2C_Write_Reg( I2C1, 0x84, 0x40, params, 1 );
    delay_ms( 100 );  // Give the registers time to be reset
    // IRQ pin -> push-pull, active high
    params[0] = 0x03;
    I2C_Write_Reg( I2C1, 0x84, 0x41, params, 1 );
    delay_ms( 1 );
    // IRQ source -> error and IDD ( IRQ_SRC_EN = IRQ_ERROR | IRQ_IDD )
    params[0] = 0x06;
    I2C_Write_Reg( I2C1, 0x84, 0x42, params, 1 );
    // Enable IDD function ( SYS_CTRL = IDD_EN )
    params[0] = 0x04;
    I2C_Write_Reg( I2C1, 0x84, 0x40, params, 1 );
    // Assign shunt values, gain value, and min VDD value
    params[0] = 0x03; params[1] = 0xE8;        // SH0 = 1000 mohm
    params[2] = 0x00; params[3] = 0x18;        // SH1 = 24 ohm
    params[4] = 0x02; params[5] = 0x6C;     // SH2 = 620 ohm
    params[6] = 0x00; params[7] = 0x00;        // SH3 = not included
    params[8] = 0x27; params[9] = 0x10;     // SH4 = 10,000 ohm
    params[10] = 0x13; params[11] = 0x7E; // Gain = 49.9 (4990)
    params[12] = 0x0B; params[13] = 0xB8;    // VDD_MIN = 3000 mV
    I2C_Write_Reg( I2C1, 0x84, 0x82, params, 14 );
    /* enable interrupts for external interrupt lines 4 - 15 */
    EXTI->PR |= EXTI_PR_PR13; // clear pending interrupt (if it is pending)
    NVIC_EnableIRQ( EXTI4_15_IRQn );
    NVIC_SetPriority( EXTI4_15_IRQn, IDD_INT_PRIO );

Once the MFX is initialized, IDD measurements can be requested. Listing 2 is an example of how to do just that. The first step is to specify a pre-delay (if desired). This is the amount of time that will elapse before the measurement is taken. Setting the most significant bit in the IDD_PRE_DELAY register will cause the pre-delay value to be interpreted in units of 20 ms, whereas clearing it changes the units to 5 ms. Then, the measurement is requested by setting the IDD_CTRL_REQ bit and the IDD_CTRL_SHUNT_NB bits in the IDD_CTRL register (see the Excel document). Since there are four shunt resistors on the Discovery board, 0x04 is written to the IDD_CTRL_SHUNT_NB field.

Listing 2: Example of requesting an IDD measurement from the MFX
void Idd_req_meas( uint8_t predelay )
    uint8_t param;
    predelay |= 0x80; // IDD_PRE_DELAY |= IDD_PREDELAY_20_MS
    I2C_Write_Reg( I2C1, 0x84, 0x81, &predelay, 1 ); //add predelay before Idd measurement
    param = 0x09; // IDD_CTRL = ( ( 4 << 1 ) & IDD_CTRL_SHUNT_NB ) | IDD_CTRL_REQ
    I2C_Write_Reg( I2C1, 0x84, 0x80, &param, 1 ); // request Idd measurement

Once the measurement is ready, it can be read from the three IDD_VALUE registers, as shown in Listing 3. However, the IRQ_PENDING register should be first be read in order to see if the IRQ_ERROR bit is set. If it is, the MFX may not respond when attempting to read the IDD measurement value. If there is no error, the IDD value can be read from memory addresses 0x14 (IDD_VALUE_MSB) to 0x16 (IDD_VALUE_LSB). Then, an acknowledgment must be sent to the MFX by setting the IRQ_IDD bit in the IRQ_ACK register in order to let the MFX know that the interrupt was received and handled. Note that once all three bytes of the IDD value are combined, the result will be in units of 10nA. In order to convert the value to nA, simply multiply it by 10.

Listing 3: Example of reading an IDD measurement from the MFX
int Idd_get_meas( void )
    uint8_t temp[3];
    uint8_t ack;
    // check for errors
    I2C_Read_Reg( I2C1, 0x84, 0x08, temp, 1 );
    if ( temp[0] & 0x04 ) // if ( REG_IRQ_PENGDING & IRQ_ERROR )
        CURR_MEAS_POS();  // move cursor to current measurement position
        USART_puts( USART1, "MFX ERROR" );
        return -1;
    I2C_Read_Reg( I2C1, 0x84, 0x14, temp, 3 ); // read current measurement
    ack = 0x02;
    I2C_Write_Reg( I2C1, 0x84, 0x44, &ack, 1 ); // acknowledge Idd from MFX
    return (temp[0]<<16) + (temp[1]<<8) + temp[2];

Register Map

As mentioned above, an Excel spreadsheet documenting the registers relevant to this discussion is included below. The definitions in the mfxstm32l152.h file were complied in order to fill in the address and bit columns. Likewise, any useful comments were placed in the comments and permissions columns. The reset value column was determined by running a test that read every register immediately after a software reset. There are many blank cells because some registers were not commented very well (or at all) and some bit fields were not defined. Still, this spreadsheet is a useful reference for who would like to understand what the seemingly random hexadecimal numbers used in the example functions above actually represent.  

Example Application

The demonstration program that comes pre-loaded on the STM32L053 Discovery kit will allow the user to chose between four modes of operation via the touch sensor and the current consumed will be displayed on the E-paper display. These modes include, Run mode, Sleep mode, Low-power sleep mode, and Stop mode. In order to further emphasize the low-power capabilities of the STM32L053 device while avoiding the clutter of ST's Hardware Abstraction Libraries, a new application was written that uses fewer peripherals and board features. This new example application includes the two low-power modes that were excluded from the demo application (Low-power run mode and Standby mode) and takes continuous measurements at a rate of about one measurement per second.

A terminal emulator provides the user interface for the application. Figure 6 is a screen shot of the output. The current measurement is displayed in the top window and the modes of operation are listed in the bottom window. An arrow points to the current mode and instructions for choosing a different mode are shown at the very bottom. Any terminal emulator program (e.g. PuTTY, Tera Term, CoolTerm, etc.) should work as long as the baud rate is set to 4800 and there is an implicit carriage return (CR) in every line feed (LF). If the sticker on the back of the STM32L053 Discovery board is labeled "MB1143 B-01" or later, then solder bridges SB2 and SB3 will need to be closed so the USART can interface with the virtual COM port (Section 4.14 of the Discovery board user manual).


Figure 6: User interface for example current measurement application


At the heart of the application is a Finite State Machine (FSM), where each state corresponds to one of the six modes of operation. The entry action for each is these states are functions that will configure the system clocks, power control registers, and the M0+ core registers in order to place the device into the desired mode of operation. These function are each named enter_<Mode>(), where <Mode> is replaced by one of the following: Run, LPRun, Sleep, LPSleep, Stop, or Standby. More information on these functions and their corresponding low-power modes can be found on the Low-Power Modes on the STM32L0 Series page.

Aside from the FSM, there is a background thread that will handle the current measurement functionality. It executes every time the MFX sets the IRQ_OUT line to signal that the current measurement is ready (recall that PC13 on the MCU is used to trigger an external interrupt). This thread uses the procedures discussed in the previous section to get the current measurement, display it, and request a new measurement. In order to verify the correctness of the current measurements delivered by the IDD measurement module, a digital multimeter was used for comparison. Three measurements for each mode using both methods were taken and the averages were reported in Table 1. In order to use the multimeter to take stable measurements, the the MFX was not initialized. This prevented the background thread from running and causing the MCU to temporarily enter Run mode every second. As the results show, the IDD module is not the most accurate of methods for Run mode, Sleep mode, and Low-power sleep mode, but is still impressively close considering the simplicity of the circuitry.


Table 1: Comparison of the measurements of current consumed by the MCU in various operating modes

ModeIDD ModuleMultimeter


3.399 mA3.451 mA


44.052 µA44.063 µA
Sleep1.331 mA1.474 mA
LPSleep14.179 µA15.233 µA
Stop451 nA443 nA
Standby297 nA288 nA

Complete Example Code

Because this is a relatively simple application that does not utilize ST's Hardware Abstraction Libraries, all of the code was placed in the main.c file (provided below). Written using Keil's µVision5 IDE, it is heavily commented and (hopefully) organized in a very logical manner. For those new to Keil's development tools, the procedure for creating this application from scratch is outlined below.

  1. Open µVision5 and go to Project > Manage > Pack Installer...
  2. In the left window, choose the device (STMicroelectronics > STM32L0 Series > STM32L053 > STM32L053C8 > STM32L053C8Tx)
  3. In the right window, click the Install buttons next to "Keil::STM32L0xx_DFP" and "ARM::CMSIS"
  4. Close the Pack Installer window and go to Project > New µVision Project...
  5. Navigate to the folder that will contain the project, enter a name for the project (e.g. STM32L035-DISCO_current_meas), and click Save
  6. Select the device (in the bottom left box, navigate to STMicroelectronics > STM32L0 Series > STM32L053 > STM32L053C8 > STM32L053C8Tx) and click OK
  7. Expand the "CMSIS" software component and check the box across from "Core"
  8. Select "Standalone" from the drop-down menu across from the "Device" software component. Expand the "Device" software component and check the box across from "Startup". Click OK
  9. In the Project menu, expand "Target 1", right-click on "Source Group 1", and select Add Existing Files to Group 'Source Group 1'...
  10. Navigate to wherever main.c is stored, select it, click Add, and then click Close
  11. Go to Project > Options for Target 'Target 1'... (Note: you may have to open and close Options for Group 'Source Group 1'... in order for this option to appear)
  12. Under the Debug tab, choose ST-Link Debugger from the top right drop-down menu
  13. Next to that drop-down menu, click Settings, go to the Flash Download tab, click the only option for Programming Algorithms (STM32L0 64KB Flash), and click OK
  14. Click OK again, and go to Project > Build Target
  15. Finally, go to Flash > Download (once the download is complete, the reset button may have to be pressed to use the application)

If all goes well, the board should be programmed and ready to use. Simply open a terminal emulator, set the baud rate to 4800, and open the correct COM port. Note that some terminal emulators will not print a carriage return automatically when a line feed is received, so that setting will have to be changed if necessary.


The STM32L053 Discovery board is an excellent tool for those wishing to evaluate the low-power capabilities of the STM32L053 family of microcontrollers. Its built in current measurement module employs a network of shunt resistors interfaced with a multi-function controller in order to abstract the current measurement process from the MCU. The most difficult part of using this module is performing the initialization process since no documentation is provided on the subject. Therefore, various pieces of example code were studied and a sufficient map of the controller's registers was created in order to be used as a reference when interfacing with the IDD measurement module. Likewise, a more compact example application demonstrating how the module can be used to measure and report the current consumed in each of the STM32L053C8's low-power modes was written using direct register access. This way, individual functions can be copied for use in other programs without the need to import any extra libraries.

Contact the Author

I realize that a lot of information has been presented in this article and because of that, some details may have been glossed over. If anyone feels lost at any point, has trouble implementing the example functions/application, or has any other related questions/feedback; feel free to send an email to or visit Digi-Key's TechForum.

  • No labels