ST AN3012 Application note

AN3012
Application note
Getting started with uClinux™
for STM32F10x high-density devices
Introduction
uClinux, pronounced “you-see-Linux”, literally means “microcontroller (µC) Linux®”. uClinux is a Linux kernel fork for microcontrollers (MCUs, embedded systems). It does not have a memory management unit (MMU). Originally derived from version 2.0 (1996) of the Linux kernel, it now has ports based on Linux 2.6. Since version 2.6, the major parts of uClinux have been integrated with the mainline kernel for a number of processor architectures. The project continues to develop patches and supporting tools to use Linux on microcontrollers. uClinux supports many architectures, and this new version supports the STM3210E-EVAL evaluation board.
The purpose of this application note is to explain you how to:
1. Install the uClinux operating system, the toolchain, and configure the kernel for the STM3210E-EVAL board
2. Build a uClinux image and download it to the STM3210E-EVAL board
3. Add applications to the kernel
September 2009 Doc ID 16051 Rev 2 1/36
www.st.com
Contents AN3012
Contents
1 Package description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Getting the tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1 uClinux package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.1 Standard distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.2 STM3210E-EVAL uClinux software kit . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 GNU toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 DFuSe & Flash loader demonstrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3.1 DFuSe applet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.3.2 Flash loader demonstrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4 Building the uClinux image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1 Installing the toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2 Preparing the source code tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Configure uClinux for STM3210E-EVAL . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3.1 Configuring the kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3.2 Application/library settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.4 Running the build process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5 Loading the images to the board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.1 Loading the “kernel loader / software updater” . . . . . . . . . . . . . . . . . . . . . 19
5.1.1 Software installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.1.2 Hardware installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.1.3 Load the hex file to the Flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.2 Loading the kernel/root file system images . . . . . . . . . . . . . . . . . . . . . . . 21
5.2.1 DfuSe demonstration installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.2.2 Generating the .dfu image and upgrading the board . . . . . . . . . . . . . . . 22
6 First run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7 Command examples/tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2/36 Doc ID 16051 Rev 2
AN3012 Contents
8 How to add new features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.1 How to add a new hardware driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.1.1 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.1.2 Example of a kernel driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.2 How to add a new application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Doc ID 16051 Rev 2 3/36
List of tables AN3012
List of tables
Table 1. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4/36 Doc ID 16051 Rev 2
AN3012 List of figures
List of figures
Figure 1. STM3210E-EVAL board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 2. Configuring the installation parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 3. uClinux-dist directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 4. uClinux kernel directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 5. uClinux configuration main menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 6. Vendor & Product selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 7. Kernel / Library / Defaults selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 8. System Type configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 9. STM3210-EVAL demonstration menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 10. Device Manager window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Figure 11. Flash loader demonstrator download configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Figure 12. Multi Bin injection window (STM3210E-EVAL-jffs configuration) . . . . . . . . . . . . . . . . . . . . 22
Figure 13. Multi Bin injection window (STM3210E-EVAL-MCU_Flash configuration) . . . . . . . . . . . . . 23
Figure 14. DfuSe demonstration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Figure 15. Example of MS HyperTherminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Figure 16. uClinux boot log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Figure 17. Linux device driver architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Figure 18. STM3210E-EVAL uart_driver struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Figure 19. STM3210E-EVAL uart_port struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Figure 20. STM3210E-EVAL uart_ops struct. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Figure 21. STM3210E-EVAL console struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Figure 22. STM3210E-EVAL console Init function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Figure 23. Simple GPIO file_operations struct. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Figure 24. Simple GPIO write operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Doc ID 16051 Rev 2 5/36
Package description AN3012

1 Package description

This section presents all the files in the package, that are needed to get started with uClinux on STM32F101xC/D/E and STM32F103xC/D/E devices.
uClinux_on_stm32.patch.gz: the uClinux patch, using which the ARM Cortex-M3 CPU
and STM3210E-EVAL board are supported.
AN3012.pdf: the purpose of this guide is to show all the steps necessary to
successfully configure, build and run uClinux on the board. It also presents the procedure to add new hardware driver and applications to the kernel.
Tiny_kernel_boot_loader.hex / kernel_boot_loader.hex: these are the boot loaders
required to boot up the board and load uClinux (kernel loader / firmware updater).
uClinux_on_stm32-jffs.dfu / uClinux_on_stm32-MCU_Flash.dfu: these are the binary
image files that can immediately be downloaded to the board to get uClinux running.
6/36 Doc ID 16051 Rev 2
AN3012 Hardware description

2 Hardware description

The STM3210E-EVAL evaluation board is designed as a complete development platform for STMicroelectronics's ARM™ Cortex delivered in 144-pin packages. This device features: full speed USB2.0, CAN2.0A/B compliant interface, two I
2
S channels, two I2C channels, five USART channels with
®
-M3 core-based STM32F103xx microcontrollers
Smartcard support, three SPI channels, two DAC channels, FSMC interface, SDIO, 64 Kbyte of internal SRAM and 512 Kbyte of Flash memory, JTAG and SWD debug support.
The STM3210E-EVAL has the following onboard hardware features:
Three 5 V power supply options: power jack, USB connector or daughterboard
Boot from user Flash memory, system memory or SRAM
I2S audio DAC, stereo audio jack
128 Mbyte MicroSD card
A- and B-type Smartcard support
64 or 128 Mbit serial Flash memory, 512 Kbit × 16 SRAM, 512 Mbit or 1 Gbit NAND
Flash and 128 Mbit NOR Flash memory
I2C/SMBus compatible serial interface temperature sensor
Two RS-232 channels with RTS/CTS handshake support on one channel
IrDA transceiver
USB2.0 full speed connection
CAN2.0A/B compliant connection
Inductor motor control connector
JTAG and trace debug support
240 × 320 TFT color LCD
Joystick with 4-direction control and selector
Reset, wakeup, tamper and user buttons
4 color LEDs
RTC with backup battery
Doc ID 16051 Rev 2 7/36
Hardware description AN3012

Figure 1. STM3210E-EVAL board

8/36 Doc ID 16051 Rev 2
AN3012 Getting the tools

3 Getting the tools

This section explains how to get the software tools that are required to build and run uClinux on the STM3210E-EVAL evaluation board.

3.1 uClinux package

3.1.1 Standard distribution

You should first download the original uClinux source files from the uClinux project page (http://www.uclinux.org/), or simply follow the following direct link:
http://www.uclinux.org/pub/uClinux/dist/uClinux-dist-20080808.tar.bz2
To get the uClinux-dist-20080808.tar.bz2 file (281Mbytes), which is compatible with the STM3210E-EVAL uClinux kit.
Porting is based on the latest stable version of uClinux which implements the Linux kernel
2.6.26-uc0.
You also need the uClinux distribution update patch file: uClinux-dist-20080808-
20090112.patch.gz (47.1 Mbytes) available from:
http://www.uclinux.org/pub/uClinux/dist/patches/uClinux-dist-20080808-20090112.patch.gz

3.1.2 STM3210E-EVAL uClinux software kit

This package contains the kernel patch (update of 399 files) and the kernel boot loader (see
Section 1: Package description). The package is available from http://www.st.com/stm32.

3.2 GNU toolchain

A toolchain known to successfully build the kernel for ARM Cortex-M3 targets can be downloaded from the CodeSourcery web site http://www.codesourcery.com/, or using the following link: http://www.codesourcery.com/sgpp/lite/arm/portal/release827
The G++ Lite 2009q1 toolchain is a free version of the CodeSourcery G++ toolchain, which is an improvement of the GNU toolchain for ARM processors. It supports ARM, thumb and thumb-2 compilation for all architectures, including Version 7 of the ARM Architecture.
Note: 1 This application note only shows how to Install the “easy-to-install recommended
packages”.
2 You need a PC running on the Linux operating system to be able to install and compile
uClinux. The Linux distribution (Fedora, Mandriva, Ubuntu, etc.) should have the kernel development kit.

3.3 DFuSe & Flash loader demonstrator

These two tools are needed to load the final binary images to the board.
Doc ID 16051 Rev 2 9/36
Getting the tools AN3012

3.3.1 DFuSe applet

DFuSe stands for Device firmware upgrade application. This applet, coupled to the kernel boot loader firmware, allows the upgrade of the final .dfu file to the on-board Flash memory.
It can be downloaded from the STMicroelectronics website or directly, using the following link: http://www.st.com/stonline/products/support/micro/files/um0412.zip.

3.3.2 Flash loader demonstrator

This applet, together with the System memory boot loader capabilities, is used to upgrade kernel_boot_loader.hex to the STM32F101/103xC/D/E’s 512-Kbyte internal Flash memory.
The Flash loader demonstrator is available from st.com at:
http://www.st.com/stonline/products/support/micro/files/um0462.zip
Note: You need a PC running on the Microsoft
use these two applets.
®
Windows® operating system to be able to run and
10/36 Doc ID 16051 Rev 2
AN3012 Building the uClinux image

4 Building the uClinux image

This section shows the kernel building process from scratch; to successfully build the uClinux image, you have to Install GNU toolchain, extract the uClinux source files, apply the path to the source, configure uClinux for the STM3210E-EVAL board and finally run the build process.

4.1 Installing the toolchain

On a host PC running with the Linux OS:
1. Move to the directory containing the previously downloaded arm-2009q1-163-arm- uclinuxeabi.bin file.
2. Execute the installer by double clicking on the bin file or from the command line by typing:
#./arm-2009q1-163-arm-uclinuxeabi.bin
3. Follow the installer Wizard to install the typical toolchain settings.

Figure 2. Configuring the installation parameters

Note: When no windowing server is running you can use the console installation mode, which is
enabled with the “-i console” parameter:
# ./arm-2009q1-163-arm-uclinuxeabi.bin -i console
Doc ID 16051 Rev 2 11/36
Loading...
+ 25 hidden pages