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

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

Board features

The STM32 on the board is packed with peripherals, especially communication ports and timers, there is a lot that can be done with this “low end” part.


  • STM32F100RB Value Line Medium Density MCU, 24MHz Cortex-M3 CPU, 128KB flash, 8KB RAM.
  • 7 DMA channels, 3 USARTs, 2 SPIs, 2 I2C, ADC, DAC, RTC, lots of timers, CRC unit, two independent watchdogs.
  • Integrated ST-Link USB debugger/programmer unit. The debugger unit is also usable separately.
  • 8MHz HSE crystal.
  • 32768Hz LSE crystal.
  • USB power LED (red).
  • USB communication LED (red).
  • Two user LEDs (green, blue).
  • Reset button.
  • User button.
  • All the STM32 I/O pins are conveniently available on the board pin strips.

Required Software

  • ChibiOS/RT 2.2.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.0 or newer for flash programming.

Required Hardware


  • An STM32VL-Discovery board.
  • A 10KΩ resistive trimmer or linear potentiometer.
  • Some male pin strips.
  • 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 STM32 platform. The application demonstrates the use of the following components:

  • Cortex-M3 startup support.
  • Linker scripts for STM32.
  • STM32VL-Discovery specific board files.
  • RTOS kernel for multi-threading and synchronization.
  • HAL driver for the STM32 platform initialization (clock tree).
  • PAL driver (I/O ports abstraction).
  • DMA driver (shared DMA 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:

  • STM32 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. Connect the STM32VL-Discovery PA9 (TX) pin to the RS232 board transmitter input.
  2. Connect the STM32VL-Discovery PA10 (RX) pin to the RS232 board receiver output.
  3. Connect the STM32VL-Discovery 3V3 pin to the RS232 board VCC pin.
  4. Connect the STM32VL-Discovery 3V3 pin to the potentiometer pin 1.
  5. Connect the STM32VL-Discovery GND pin to the RS232 board GND pin.
  6. Connect the STM32VL-Discovery GND pin to the potentiometer pin 3.
  7. Connect the STM32VL-Discovery PC0 pin to the potentiometer pin 2 (center).
  8. Connect your analyzer to the SPI port pins (NSS=PA4, SCK=PA5, MOSI=PA7).
  9. Connect the RS232 board to a PC, run a terminal emulator setting the parameters 38400-8-N-1.
  10. Connect the STM32VL-Discovery board to a PC using an USB cable it should appear as an USB drive.

Building the Demo

The demo is located under ./demos/ARMCM3-STM32F100-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.jpg stvp_open.jpg stvp_erase.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 STM32F100xBxxB.
  3. Load the demo image file ”ch.hex”.
  4. Erase the STM32 flash memory.
  5. 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 problem 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 STM32, strip the test suite code from the Makefile (you won't need it) and start experimenting modifying the file main.c.

chibios/articles/stm32vl_discovery.txt · Last modified: 2012/11/05 18:46 by giovanni
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.3