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).
94 \section{Building and running a program}
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{Reading and writing to flash}
170 Flash memory reading and writing is done by a separate tool. A binary running in flash is assumed to
171 be linked against address 0x8000000. The flash tool is then used as shown below:\\
173 \begin{lstlisting}[frame=tb]
174 # change to the flash tool directory
175 $> cd stlink.git/flash ;
177 # stlinkv1 command to read 4096 from flash into out.bin
178 $> ./flash read v1 out.bin 0x8000000 4096
181 $> ./flash read out.bin 0x8000000 4096
183 # stlinkv1 command to write the file in.bin into flash
184 $> ./flash write v1 in.bin 0x8000000
187 $> ./flash write in.bin 0x8000000
195 \subsection{Disassembling THUMB code in GDB}
197 By default, the disassemble command in GDB operates in ARM mode. The programs running on CORTEX-M3
198 are compiled in THUMB mode. To correctly disassemble them under GDB, uses an odd address. For instance,
199 if you want to disassemble the code at 0x20000000, use:\\
201 \begin{lstlisting}[frame=tb]
202 $> disassemble 0x20000001
207 \subsection{libstm32l\_discovery}
209 The repository includes the STM32L discovery library source code from ST original firmware packages,
212 \begin{lstlisting}[frame=tb]
213 http://www.st.com/internet/evalboard/product/250990.jsp#FIRMWARE
220 \begin{lstlisting}[frame=tb]
221 $> cd stlink.git/example/libstm32l_discovery/build
227 An example using the library can be built using:\\
229 \begin{lstlisting}[frame=tb]
230 $> cd stlink.git/example/lcd
239 \item http://www.st.com/internet/mcu/product/248823.jsp\\
240 documentation related to the STM32L mcu
241 \item http://www.st.com/internet/evalboard/product/250990.jsp\\
242 documentation related to the STM32L discovery kit