1 \documentclass[a4paper, 11pt]{article}
11 \title{Using STM32 discovery kits with open source tools}
12 \author{STLINK development team}
19 \addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
26 This guide details the use of STMicroelectronics STM32 discovery kits in
27 an open source environment.
32 \section{Installing a GNU toolchain}
34 Any toolchain supporting the cortex m3 should do. You can find the necessary
35 to install such a toolchain here:\\
37 \begin{lstlisting}[frame=tb]
38 https://github.com/esden/summon-arm-toolchain
43 Details for the installation are provided in the topmost README file.
44 This documentation assumes the toolchains is installed in a \$TOOLCHAIN\_PATH.
49 \section{Installing STLINK}
51 STLINK is open source software to program and debug ST's STM32 Discovery kits. Those
52 kits have an onboard chip that translates USB commands sent by the host PC into
53 JTAG/SWD commands. This chip is called STLINK, (yes, isn't that confusing? suggest a better
54 name!) and comes in 2 versions (STLINK v1 and v2). From a software
55 point of view, those versions differ only in the transport layer used to communicate
56 (v1 uses SCSI passthru commands, while v2 uses raw USB). From a user point of view, they
60 Before continuing, the following dependencies must be met:
66 STLINK should run on any system meeting the above constraints.
69 The STLINK software source code is retrieved using:\\
71 \begin{lstlisting}[frame=tb]
72 $> git clone https://github.com/texane/stlink stlink.git
77 Everything can be built from the top directory:\\
79 \begin{lstlisting}[frame=tb]
86 \item a communication library (stlink.git/libstlink.a),
87 \item a GDB server (stlink.git/gdbserver/st-util),
88 \item a flash manipulation tool (stlink.git/flash/flash).
93 \section{Building and running a program in SRAM}
95 A simple LED blinking example is provided in the example directory. It is built using:\\
97 \begin{lstlisting}[frame=tb]
98 cd stlink.git/example/blink ;
99 PATH=$TOOLCHAIN_PATH/bin:$PATH make
102 This builds three files, one for each of the Discovery boards currently
103 available, linked to run from SRAM. (So no risk of overwriting anything you didn't mean to)
104 These blink examples can safely be used to verify that:
107 \item Your installed toolchain is capable of compiling for cortex M3/M4 targets
108 \item stlink is functional
109 \item Your arm-none-eabi-gdb is functional
110 \item Your board is functional
114 A GDB server must be started to interact with the STM32. Depending on the discovery kit you
115 are using, you must run one of the 2 commands:\\
117 \begin{lstlisting}[frame=tb]
118 # STM32VL discovery kit (onboard ST-link)
119 $> ./st-util --stlinkv1
121 # STM32L or STM32F4 discovery kit (onboard ST-link/V2)
124 # Full help for other options (listen port, version)
130 Then, GDB can be used to interact with the kit:\\
132 \begin{lstlisting}[frame=tb]
133 $> $TOOLCHAIN_PATH/bin/arm-none-eabi-gdb
138 From GDB, connect to the server using:\\
140 \begin{lstlisting}[frame=tb]
141 $> target extended localhost:4242
146 By default, the program was linked such that the base address is 0x20000000. From the architecture
147 memory map, GDB knows this address belongs to SRAM. To load the program in SRAM, simply use:\\
149 \begin{lstlisting}[frame=tb]
150 $> # Choose one as appropriate for your Discovery kit
151 $> load blink_32L.elf | load blink_32VL.elf | load blink_F4.elf
156 GDB automatically set the PC register to the correct value, 0x20000000 in this case. Then, you
157 can run the program using:\\
159 \begin{lstlisting}[frame=tb]
165 All the LEDs on the board should now be blinking in time (those leds are near the user and reset buttons).
168 \section{Building and flashing a program}
170 FLASH memory reading and writing is done by a separate tool, as shown below:\\
172 \begin{lstlisting}[frame=tb]
173 # change to the flash tool directory
174 $> cd stlink.git/flash ;
176 # stlinkv1 command to read 4096 from flash into out.bin
177 $> ./flash read v1 out.bin 0x8000000 4096
180 $> ./flash read out.bin 0x8000000 4096
182 # stlinkv1 command to write the file in.bin into flash
183 $> ./flash write v1 in.bin 0x8000000
186 $> ./flash write in.bin 0x8000000
191 A LED blinking example is provided:\\
193 \begin{lstlisting}[frame=tb]
194 # build the example, resulting in blink.bin
195 $> cd stlink.git/example/blink_flash
196 $> PATH=$TOOLCHAIN_PATH:$PATH make CONFIG_STM32L_DISCOVERY=1
198 # write blink.bin into FLASH
199 $> sudo ./flash write blink.bin 0x08000000
204 Upon reset, the board LEDs should be blinking.
207 \section{Building and installing the CHIBIOS kernel}
209 CHIBIOS is an open source RTOS. More information can be found on the project website:
211 http://www.chibios.org/dokuwiki/doku.php
215 It supports several boards, including the STM32L DISCOVERY kit:
217 http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:stm32l\_discovery
221 The installation procedure is detailed below:\\
223 \begin{lstlisting}[frame=tb]
224 # checkout and build CHIBIOS for STM32L DISCOVERY kits
225 svn checkout https://chibios.svn.sourceforge.net/svnroot/chibios/trunk
226 cd chibios/trunk/demos/ARMCM3-STM32L152-DISCOVERY
227 PATH=$TOOLCHAIN_PATH:$PATH make
229 # flash the image into STM32L
230 sudo ./flash write build/ch.bin 0x08000000
237 \subsection{Disassembling THUMB code in GDB}
239 By default, the disassemble command in GDB operates in ARM mode. The programs running on CORTEX-M3
240 are compiled in THUMB mode. To correctly disassemble them under GDB, uses an odd address. For instance,
241 if you want to disassemble the code at 0x20000000, use:\\
243 \begin{lstlisting}[frame=tb]
244 $> disassemble 0x20000001
249 \subsection{libstm32l\_discovery}
251 The repository includes the STM32L discovery library source code from ST original firmware packages,
254 \begin{lstlisting}[frame=tb]
255 http://www.st.com/internet/evalboard/product/250990.jsp#FIRMWARE
262 \begin{lstlisting}[frame=tb]
263 $> cd stlink.git/example/libstm32l_discovery/build
269 An example using the library can be built using:\\
271 \begin{lstlisting}[frame=tb]
272 $> cd stlink.git/example/lcd
281 \item http://www.st.com/internet/mcu/product/248823.jsp\\
282 documentation related to the STM32L mcu
283 \item http://www.st.com/internet/evalboard/product/250990.jsp\\
284 documentation related to the STM32L discovery kit