STM32L011 serial, analog and low power examples

Here are some further examples for the STM32L011 Nucleo board. The first is a simple interrupt driven serial communications demonstration. It makes use of the built in serial interface in the Nucleo board and so no additional hardware is required for your host PC to exchange data with the MCU.
The second example builds on the first. It reads ADC channel 0 and outputs the result to the host PC over the serial port.
The third example is a little more elaborate and is aimed at those wishing to develop a very long life battery application. It uses the built-in real-time-clock (RTC) to wake the MCU up about once every second. While awake, the MCU reads the ADC, outputs data to the host PC over the serial port and blinks the LED on the Nucleo board. Current consumption is minimized during sleep by turning off
peripherals, reducing AHB clock speed and putting the Cortex M0+ into a deep sleep. I found it difficult to measure the current flow during this time but it seems to be around 3 to 4 microamps. One thing I did notice is that the CPU will not go to sleep with interrupts disabled – a good way of preventing you from shooting yourself in the foot.

Links to code.

Serial communications over the nucleo serial interface to the host PC
Read the ADC and output the result over the serial port to the host PC
Minimize power consumption and wake using the internal RTC every second

Blinky on the STM32L011 Nucleo

The STM32L011 Nucleo board is an mbed enabled development kit featuring the STM32Lo11K4 MCU. This is a Cortex M0+ device with some interesting features such as hardware accelerated AES encryption (Correction: AES not present on the STM32L011) and a “Firewall” which seems to prevent firmware and other data being offloaded from the device. The board is meant to be programmed with a large IDE or using the mbed online development environment. I was curious to see could it be done from the command line with all code contained in a single directory. Normally I would tackle this with OpenOCD and GDB but this is such a new board that OpenOCD/GDB can’t interface with it properly (yet). All is not lost however! The mbed feature of this board means that it appears as a removable storage device to the operating system. Programming the board is simply a matter of dropping a correctly formatted executable (binary) file into this removable storage device. The utility objcopy can be used to prepare the executable file.
Assuming you have compiled your code to an “elf” file called main.elf, you can generate a binary file as follows:
objcopy -O binary main.elf main.bin
The “bin” file can be dropped on the Nucleo and should run fine.
Code for blinky is available here