Difference between revisions of "Workshop"

From MAGEEC
Jump to: navigation, search
(Software setup)
(Software setup)
Line 81: Line 81:
 
     $ make
 
     $ make
 
     $ sudo make DETECT_TOOLCHAIN=1 install
 
     $ sudo make DETECT_TOOLCHAIN=1 install
 +
    $ cd ..
  
  
Line 107: Line 108:
 
      
 
      
  
     $ arm-none-eabi-gdb src/firmware/energy_monitor
+
Now, we need to run this program and leave it running in - it will talk to GDB and the STM32F4 in the background.
     >
+
 
 +
    $ ./st-util
 +
 
 +
 
 +
In a new terminal, we can now flash the firmware to the board:
 +
 
 +
     $ arm-none-eabi-gdb
 +
 
 +
Choose the firmware file
 +
 
 +
    > file stm32f4-energy-monitor/src/firmware/energy_monitor
 +
 
 +
Tell GDB to talk to the GDB server (st-util) on port 4242
 +
 
 +
    > target extended :4242
 +
 
 +
Load the firmware onto the board
 +
 
 +
     > load
  
 
==Using the software==
 
==Using the software==

Revision as of 15:27, 12 January 2014

The MAGEEC project has designed a board for high frequency measurement of energy usage. This workshop will guide you through setting up and using the MAGEEC energy measurement boards.

At its simplest, the power measurement shield works by sampling the voltage drop across a resistor wire inline with a power supply. It is implemented as a shield for a ST Microelectronics STM32F4 Discovery board. The STM32F4 is used to process the raw data and pass it out over USB. The shield can measure up to three external targets simultaneously, as well as measuring its own energy usage.

The hardware is a fully open design by Dr Simon Hollis of Bristol University. It may be downloaded from GitHub: https://github.com/mageec/powersense-shield.

Image of the Energy Monitor


Software Requirements

Skip this section if you are running from the MAGEEC live CD.

This section sets up the packages required to compile the firmware for the energy monitor board, run the python scripts to communicate with the board and toolchain to compile for an arduino target board.

Install packages required to build the firmware for the energy monitor board

   add-apt-repository ppa:terry.guo/gcc-arm-embedded


If on Ubuntu 13.10, the following is required

   sed -i 's/saucy/raring/' /etc/apt/sources.list.d/terry_guo-gcc-arm-embedded-saucy.list


Install an ARM toolchain

   sudo apt-get install gcc-arm-none-eabi


If the target board is a shrimping kit / arduino / AVR

   sudo apt-get install gcc-avr  gdb-avr avr-libc avrdude arduino  


Install other libraries needed

   sudo apt-get install git python-numpy python-scipy build-essential python-pip autoconf automake autotools-dev libtool libusb-1.0-0-dev libusb-0.1-4
   sudo pip install pyusb


The following udev rules will need to be install, to use the board without being root

   https://github.com/jpallister/stm32f4-energy-monitor/blob/pyusb/53-energy-monitor.rules
   https://github.com/jpallister/stlink/blob/master/49-stlinkv2.rules

Connecting the hardware

First mount the shield as shown in the following image. There will probably be a jumper supplied with the STM32F4, which will need removing, with the pins slotting into a socket on the underside of the shield.

Energymonitor2.jpg

For each measurement point there are two headers. One 4x1 offering pins labelled GND, OUT and IN (more on the 4th one later) and one 5x2 for selecting an inline resistor (see below).

Photo of the pinheaders to select resistor and accept voltages

The target power supply should be intercepted, and wired to the IN pin, with the OUT pin then connected to the power supply on the target board. GND should be connected to ground on the target board. Power supplies up to 5V are supported. Although the voltage drop is sufficient to give the current measurement, a GND connection (not shown in the above picture) is needed to get an absolute voltage measurement.

The 4th pin next to IN is a jumper to bypass an inductor. Sometimes the only way to intercept the power supply on a target board is to cut out the inductor. In this case, remove the jumper to use the inductor on the shield instead. The target device can be powered from the shield if desired. In this case IN should be connected to the 3.3V or 5V supply on the shield (the above shows this, with the brown wire picking up the 3.3V supply). A maximum of 100mA draw is available in total.

The configuration of the resistors

The choice of resistor depends on the target maximum power consumption. Values of 0.05Ω, 0.5Ω, 1Ω and 5Ω are provided (the 5th slot is unused and can be used to supply your own resistor). The objective is a maximum 50mV drop.

Software setup

The first thing to do is to flash the STM32F4DISCOVERY board with the firmware required to take energy measurements. This firmware sets up the ADCs, USB and other peripherals, so that the board can talk to the host machine via USB. It performs the accumulation and conversion of the analog energy values coming from the power measurement shield.

In the following steps, skip any git clone commands if you are using the MAGEEC tools environment - all of the files are already provided on the desktop.

The energy monitor firmware uses a library called libopencm3 to interface to the hardware peripherals provided by the board. This needs to be downloaded and compiled into the toolchain:

   $ git clone https://github.com/libopencm3/libopencm3
   $ cd libopencm3
   $ make
   $ sudo make DETECT_TOOLCHAIN=1 install
   $ cd ..


Next, we need to obtain the energy monitor sources.

   $ git clone https://github.com/jpallister/stm32f4-energy-monitor
   $ cd stm32f4-energy-monitor
   $ git checkout pyusb


Then configure and compile specifying that we want to compile ARM firmware:

   $ ./configure --host=arm-none-eabi
   $ make

This will produce a file energy_monitor in src/firmware/. The next step is to flash this to the STM32F4 board. The board has two USB interfaces, one for programming and the other for the firmware's use. The programming USB interface is at the top of the board, connected with a USB mini cable. Make sure this is plugged in, and follow the steps below to flash the board.

To communicate with the board, we need a gdb server to enable communication between the debugger, GDB, and the target board. This is provided by the opensource st-link utility.

   $ cd ..
   $ git clone https://github.com/jpallister/stlink
   $ cd stlink
   $ ./autogen.sh
   $ ./configure
   $ make
   

Now, we need to run this program and leave it running in - it will talk to GDB and the STM32F4 in the background.

   $ ./st-util


In a new terminal, we can now flash the firmware to the board:

   $ arm-none-eabi-gdb

Choose the firmware file

   > file stm32f4-energy-monitor/src/firmware/energy_monitor

Tell GDB to talk to the GDB server (st-util) on port 4242

   > target extended :4242

Load the firmware onto the board

   > load

Using the software

TODO command line utility to read power data

TODO python scripting

Challenges

This section gives some examples for you to try out with the energy measurement kit.

Persistence of Vision

This uses one of the shrimping.it persistence of vision kits.

TODO energy required for different messages TODO compiler options exploration TODO interrupt driven version

Sorting

Try different sorting algorithms. Which is most energy efficient?

BEEBS

We use the a benchmark suite called BEEBS for our research. Try running some of these benchmarks on different hardware targets, with different clock speeds. Which takes the least energy?