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 opensource 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 an opensource software to program and debug the discovery kits. Those
52 kits have an onboard chip that translates USB commands sent by the host PC into
53 JTAG commands. This chip is called STLINK, which is confusing since the software
54 has the same name. It comes into 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).
59 Before continuing, the following dependencies are required:
66 The STLINK software source code is retrieved using:\\
68 \begin{lstlisting}[frame=tb]
69 git clone https://github.com/texane/stlink stlink.git
74 The GDB server is called st-util and is built using:\\
76 \begin{lstlisting}[frame=tb]
87 \section{Building and running a program}
88 A simple LED blinking example is provided in the example directory. It is built using:\\
90 \begin{lstlisting}[frame=tb]
91 cd stlink.git/example/blink ;
92 PATH=$TOOLCHAIN_PATH/bin:$PATH make ;
97 A GDB server must be start to interact with the STM32. Depending on the discovery kit you
98 are using, you must run one of the 2 commands:\\
100 \begin{lstlisting}[frame=tb]
101 # STM32VL discovery kit
102 $> sudo ./st-util /dev/sg2
104 # STM32L discovery kit
110 Then, GDB can be used to interact with the kit:\\
112 \begin{lstlisting}[frame=tb]
113 $> $TOOLCHAIN_PATH/bin/arm-none-eabi-gdb
118 From GDB, connect to the server using:\\
120 \begin{lstlisting}[frame=tb]
121 $> target extended localhost:4242
126 By default, the program was linked such that the base address is 0x20000000. From the architecture
127 memory map, GDB knows this address belongs to SRAM. To load the program in SRAM, simply use:\\
129 \begin{lstlisting}[frame=tb]
135 GDB automatically set the PC register to the correct value, 0x20000000 in this case. Then, you
136 can run the program using:\\
138 \begin{lstlisting}[frame=tb]
144 The board BLUE and GREEN leds should be blinking (those leds are near the user and reset buttons).
150 \subsection{Disassembling THUMB code in GDB}
152 By default, the disassemble command in GDB operates in ARM mode. The programs running on CORTEX-M3
153 are compiled in THUMB mode. To correctly disassemble them under GDB, uses an odd address. For instance,
154 if you want to disassemble the code at 0x20000000, use:\\
156 \begin{lstlisting}[frame=tb]
157 $> disassemble 0x20000001
162 \subsection{libstm32l\_discovery}
164 The repository includes the STM32L discovery library source code from ST original firmware packages,
167 \begin{lstlisting}[frame=tb]
168 http://www.st.com/internet/evalboard/product/250990.jsp#FIRMWARE
175 \begin{lstlisting}[frame=tb]
176 $> cd stlink.git/example/libstm32l_discovery/build
182 An example using the library can be built using:\\
184 \begin{lstlisting}[frame=tb]
185 $> cd stlink.git/example/lcd
193 \item http://www.st.com/internet/mcu/product/248823.jsp\\
194 documentation related to the STM32L mcu
195 \item http://www.st.com/internet/evalboard/product/250990.jsp\\
196 documentation related to the STM32L discovery kit