Getting started with the STM32L-Discovery board and ChibiOS/RT

This article will explain how to get started with the recently released STM32L-Discovery board using ChibiOS/RT. This board is really cheap (around 12$) and is an excellent evaluation platform for the STMicroelectronics STM32L family.

Board features

stm32l-discovery_board.jpg

  • STM32L152RBT6 EnergyLite 32bits MCU, 32MHz Cortex-M3 CPU, 128KB flash, 16KB RAM, 4KB EEPROM.
  • 7 DMA channels, 3 USARTs, 2 SPIs, 2 I2C, ADC, DAC, RTC, lots of timers, CRC unit, two independent watchdogs.
  • Integrated ST-Link/V2 USB debugger/programmer unit. The debugger unit is also usable separately.
  • 8MHz HSE crystal shared between the ST-Link and the target MCU.
  • 32768Hz LSE crystal.
  • USB power LED (red).
  • USB communication LED (red/green).
  • Two user LEDs (green, blue).
  • Reset button.
  • User button.
  • 24 segments LCD with 4 commons.
  • Linear touch sensor
  • All the STM32 I/O pins are conveniently available on the board pin strips.

Required Software

  • ChibiOS/RT 2.3.3 or newer.
  • A GNU GCC toolchain, for example YAGARTO or CodeSourcery. The demo can also be compiled using the free IAR and Keil ARM compilers (projects included).
  • ST Toolset 4.2.1p2 or newer for flash programming.

Required Hardware

serial_cat.jpgpotentiometer.jpgjumper_wires.jpg

  • An STM32L-Discovery board.
  • A 10KΩ resistive trimmer or linear potentiometer.
  • Some jumper wires to connect the various parts.
  • An RS232 levels translator. It is required only if you want to capture the test report from the USART1 port using a terminal emulator, for example the (in)famous HyperTerminal. I bought the one in the picture here.
  • An SPI Analyzer or a Logic Analyzer or an Oscilloscope. It is only required if you want to see the SPI output.

ChibiOS/RT Components

ChibiOS/RT Logo

ChibiOS/RT offers an excellent support for the STM32L platform. The application demonstrates the use of the following components:

  • Cortex-M3 startup support.
  • Linker scripts for STM32L.
  • STM32L-Discovery specific board files.
  • RTOS kernel for multi-threading and synchronization.
  • HAL driver for the STM32L platform initialization (clock tree).
  • PAL driver (I/O ports abstraction).
  • DMA driver (shared DMA-abstractor helper driver).
  • ADC driver.
  • SPI driver.
  • PWM driver.
  • Serial driver.
  • Test Suite for self test and reporting.

All drivers are “native” in order to minimize the memory footprint, the bulky ST library has not been used (but is supported).

Relevant documents

The Demo Application

The demo application samples two analog channels (AN10 and Temperature Sensor) using the ADC driver and modulates two PWM channels using the average of four samples per channel. The sampled data is also transmitted over the SPI bus (SPI1, CPOL=0, CPHA=0, 16bits frames, MSb first).
The PWM is programmed with a cycle of exactly one second, the ADC samples modulate the two output channels with a duty cycle between 0 and 100 percent. The PWM outputs are connected to the board green and blue LEDs so you don't need any instrument to see the output.
By pressing the user button the test suite is activated and the output is transmitted over the serial port 1 (38400-8-N-1).

The application demonstrates the following tasks:

  • STM32L platform startup and initialization.
  • Clock tree initialization using the HAL driver.
  • RTOS initialization and operations.
  • I/O pins programming and redirection.
  • DMA-assisted ADC sampling and callbacks.
  • DMA-assisted SPI transactions and callbacks.
  • PWM operations and callbacks.
  • Interrupt driven buffered serial driver.
  • Multithreading.

The demo code can be previewed here.

Board Setup

Now let's connect the various parts:

  1. Carefully remove the display from its socket, the display uses all the available pins and the demo requires several of them for I/O.
  2. Connect the STM32F4-Discovery PA9 (TX) pin to the RS232 board transmitter input.
  3. Connect the STM32F4-Discovery PA10 (RX) pin to the RS232 board receiver output.
  4. Connect the STM32L-Discovery EXT_3V pin to the RS232 board VCC pin.
  5. Connect the STM32L-Discovery VDD pin to the potentiometer pin 1.
  6. Connect the STM32L-Discovery GND pin to the RS232 board GND pin.
  7. Connect the STM32L-Discovery GND pin to the potentiometer pin 3.
  8. Connect the STM32L-Discovery PC0 pin to the potentiometer pin 2 (center).
  9. Connect your analyzer to the SPI port pins (NSS=PB12, SCK=PB13, MOSI=PB15).
  10. Connect the RS232 board to a PC, run a terminal emulator setting the parameters 38400-8-N-1.
  11. Connect the STM32L-Discovery board to a PC using an USB cable.

Building the Demo

The demo is located under ./demos/ARMCM3-STM32L152-DISCOVERY and can be compiled by simply giving the “make” command. You may consider to import the whole project under an Eclipse Toolchain, the guide ”Using an Eclipse-based IDE” explains how the demo can be imported.

Uploading the Demo

stvp_model_l.jpg stvp_open.jpg stvp_program.jpg

In order to upload the demo to your board you can use the ST Visual Programmer tool. Its use is very simple:

  1. Launch the tool.
  2. Select the device STM32L152xB.
  3. Load the demo image file ”ch.hex”.
  4. Program the STM32 flash memory with the demo application binary image.

If you are using the IAR Workbench or Keil uVision you can flash and debug the STM32L-Discovery directly from you IDE (select ST-Link as probe and configure it in SWD mode).

Running the Demo

The demo should run immediately after loading, if not then try disconnecting and reconnecting the board USB cable in order to reset it (older versions of ST visual programmer do not run the program automatically).

You will see both user LEDs flashing with an one second period, the green LED duty cycle can be adjusted using the potentiometer, the blue LED duty cycle is determined by the temperature and is driven by the STM32 internal sensor.

The various components assembled and working

Using a Logic Analyzer you can monitor the SPI output, the demo periodically transmits eight 16 bits words, each one representing a sample taken by the ADC.

SPI output on the Logic Analyzer

By pressing the user button the OS will execute the test suite, you can capture the USART1 output using a terminal emulator in order to examine the test report and the benchmark results.

Test Report on HyperTerminal

And now?

Now you have a complete working RTOS supporting the STM32L, strip the test suite code from the Makefile (you won't need it) and start experimenting modifying the file main.c.

 
chibios/articles/stm32l_discovery.txt · Last modified: 2012/01/06 21:43 by giovanni
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.3