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 # update the make option accordingly to your architecture
92 cd stlink.git/example/blink ;
93 PATH=$TOOLCHAIN_PATH/bin:$PATH make CONFIG_STM32L_DISCOVERY=1;
98 A GDB server must be start to interact with the STM32. Depending on the discovery kit you
99 are using, you must run one of the 2 commands:\\
101 \begin{lstlisting}[frame=tb]
102 # STM32VL discovery kit
103 $> sudo ./st-util /dev/sg2
105 # STM32L discovery kit
111 Then, GDB can be used to interact with the kit:\\
113 \begin{lstlisting}[frame=tb]
114 $> $TOOLCHAIN_PATH/bin/arm-none-eabi-gdb
119 From GDB, connect to the server using:\\
121 \begin{lstlisting}[frame=tb]
122 $> target extended localhost:4242
127 By default, the program was linked such that the base address is 0x20000000. From the architecture
128 memory map, GDB knows this address belongs to SRAM. To load the program in SRAM, simply use:\\
130 \begin{lstlisting}[frame=tb]
136 GDB automatically set the PC register to the correct value, 0x20000000 in this case. Then, you
137 can run the program using:\\
139 \begin{lstlisting}[frame=tb]
145 The board BLUE and GREEN leds should be blinking (those leds are near the user and reset buttons).
149 \section{Reading and writing to flash}
151 Flash memory reading and writing is done by a separate tool. A binary running in flash is assumed to
152 be linked against address 0x8000000. The flash tool is then used as shown below:\\
154 \begin{lstlisting}[frame=tb]
155 # build the flash tool
156 $> cd stlink.git/flash ; make ;
158 # stlinkv1 command to read 4096 from flash into out.bin
159 $> ./flash read /dev/sg2 out.bin 0x8000000 4096
162 $> ./flash read out.bin 0x8000000 4096
164 # stlinkv1 command to write the file in.bin into flash
165 $> ./flash write /dev/sg2 in.bin 0x8000000
168 $> ./flash write in.bin 0x8000000
176 \subsection{Disassembling THUMB code in GDB}
178 By default, the disassemble command in GDB operates in ARM mode. The programs running on CORTEX-M3
179 are compiled in THUMB mode. To correctly disassemble them under GDB, uses an odd address. For instance,
180 if you want to disassemble the code at 0x20000000, use:\\
182 \begin{lstlisting}[frame=tb]
183 $> disassemble 0x20000001
188 \subsection{libstm32l\_discovery}
190 The repository includes the STM32L discovery library source code from ST original firmware packages,
193 \begin{lstlisting}[frame=tb]
194 http://www.st.com/internet/evalboard/product/250990.jsp#FIRMWARE
201 \begin{lstlisting}[frame=tb]
202 $> cd stlink.git/example/libstm32l_discovery/build
208 An example using the library can be built using:\\
210 \begin{lstlisting}[frame=tb]
211 $> cd stlink.git/example/lcd
219 \item http://www.st.com/internet/mcu/product/248823.jsp\\
220 documentation related to the STM32L mcu
221 \item http://www.st.com/internet/evalboard/product/250990.jsp\\
222 documentation related to the STM32L discovery kit