- Code Metrics on ohloh.net
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.
ChibiOS/RT offers an excellent support for the STM32L platform. The application demonstrates the use of the following components:
All drivers are “native” in order to minimize the memory footprint, the bulky ST library has not been used (but is supported).
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:
The demo code can be previewed here.
Now let's connect the various parts:
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.
In order to upload the demo to your board you can use the ST Visual Programmer tool. Its use is very simple:
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).
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.
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.
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.
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.