stlink/doc/tutorial/tutorial.tex

231 wiersze
5.8 KiB
TeX
Czysty Zwykły widok Historia

2011-10-15 17:30:33 +00:00
\documentclass[a4paper, 11pt]{article}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{color}
\begin{document}
\title{Using STM32 discovery kits with open source tools}
\author{STLINK development team}
\date{}
\maketitle
\newpage
\tableofcontents
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\newpage
\section{Overview}
\paragraph{}
This guide details the use of STMicroelectronics STM32 discovery kits in
an opensource environment.
\newpage
\section{Installing a GNU toolchain}
\paragraph{}
Any toolchain supporting the cortex m3 should do. You can find the necessary
to install such a toolchain here:\\
\begin{small}
\begin{lstlisting}[frame=tb]
https://github.com/esden/summon-arm-toolchain
\end{lstlisting}
\end{small}
\paragraph{}
Details for the installation are provided in the topmost README file.
This documentation assumes the toolchains is installed in a \$TOOLCHAIN\_PATH.
\newpage
\section{Installing STLINK}
\paragraph{}
STLINK is an opensource software to program and debug the discovery kits. Those
kits have an onboard chip that translates USB commands sent by the host PC into
JTAG commands. This chip is called STLINK, which is confusing since the software
has the same name. It comes into 2 versions (STLINK v1 and v2). From a software
point of view, those versions differ only in the transport layer used to communicate
2011-10-15 17:30:33 +00:00
(v1 uses SCSI passthru commands, while v2 uses raw USB).
\paragraph{}
Before continuing, the following dependencies are required:
\begin{itemize}
\item libusb-1.0
\item libsg2
\end{itemize}
2011-10-15 17:30:33 +00:00
\paragraph{}
The STLINK software source code is retrieved using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
git clone https://github.com/texane/stlink stlink.git
\end{lstlisting}
\end{small}
\paragraph{}
2011-10-20 05:38:50 +00:00
Everything can be built from the top directory:\\
2011-10-15 17:30:33 +00:00
\begin{small}
\begin{lstlisting}[frame=tb]
2011-10-20 05:38:50 +00:00
$> cd stlink.git ;
2011-10-15 21:40:47 +00:00
$> make ;
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
2011-10-20 05:38:50 +00:00
It includes:
\begin{itemize}
\item a communication library (stlink.git/libstlink.a),
\item a GDB server (stlink.git/gdbserver/st-util),
\item a flash manipulation tool (stlink.git/flash/flash).
\end{itemize}
2011-10-15 17:30:33 +00:00
\newpage
\section{Building and running a program}
A simple LED blinking example is provided in the example directory. It is built using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
# update the make option accordingly to your architecture
2011-10-16 06:28:57 +00:00
cd stlink.git/example/blink ;
PATH=$TOOLCHAIN_PATH/bin:$PATH make CONFIG_STM32L_DISCOVERY=1;
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
2011-10-15 22:14:12 +00:00
A GDB server must be start to interact with the STM32. Depending on the discovery kit you
are using, you must run one of the 2 commands:\\
2011-10-15 17:30:33 +00:00
\begin{small}
\begin{lstlisting}[frame=tb]
# STM32VL discovery kit
$> sudo ./st-util /dev/sg2
# STM32L discovery kit
2011-10-20 21:39:23 +00:00
# 2 dummy command line arguments needed, will be fixed soon
$> sudo ./st-util fu bar
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
Then, GDB can be used to interact with the kit:\\
\begin{small}
\begin{lstlisting}[frame=tb]
$> $TOOLCHAIN_PATH/bin/arm-none-eabi-gdb
\end{lstlisting}
\end{small}
\paragraph{}
From GDB, connect to the server using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
2011-10-15 18:18:26 +00:00
$> target extended localhost:4242
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
2011-10-15 22:20:56 +00:00
By default, the program was linked such that the base address is 0x20000000. From the architecture
memory map, GDB knows this address belongs to SRAM. To load the program in SRAM, simply use:\\
2011-10-15 17:30:33 +00:00
\begin{small}
\begin{lstlisting}[frame=tb]
2011-10-15 20:15:33 +00:00
$> load blink.elf
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
2011-10-15 22:15:50 +00:00
GDB automatically set the PC register to the correct value, 0x20000000 in this case. Then, you
can run the program using:\\
2011-10-15 17:30:33 +00:00
\begin{small}
\begin{lstlisting}[frame=tb]
2011-10-15 22:20:56 +00:00
$> continue
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
2011-10-15 22:14:12 +00:00
\paragraph{}
The board BLUE and GREEN leds should be blinking (those leds are near the user and reset buttons).
2011-10-15 17:53:44 +00:00
2011-10-17 20:06:23 +00:00
\newpage
\section{Reading and writing to flash}
\paragraph{}
Flash memory reading and writing is done by a separate tool. A binary running in flash is assumed to
be linked against address 0x8000000. The flash tool is then used as shown below:\\
\begin{small}
\begin{lstlisting}[frame=tb]
2011-10-20 05:38:50 +00:00
# change to the flash tool directory
$> cd stlink.git/flash ;
2011-10-17 20:06:23 +00:00
# stlinkv1 command to read 4096 from flash into out.bin
$> ./flash read /dev/sg2 out.bin 0x8000000 4096
# stlinkv2 command
$> ./flash read out.bin 0x8000000 4096
# stlinkv1 command to write the file in.bin into flash
$> ./flash write /dev/sg2 in.bin 0x8000000
# stlinkv2 command
$> ./flash write in.bin 0x8000000
\end{lstlisting}
\end{small}
2011-10-16 08:24:45 +00:00
\newpage
\section{Notes}
2011-10-16 08:48:27 +00:00
\subsection{Disassembling THUMB code in GDB}
2011-10-16 08:24:45 +00:00
\paragraph{}
By default, the disassemble command in GDB operates in ARM mode. The programs running on CORTEX-M3
are compiled in THUMB mode. To correctly disassemble them under GDB, uses an odd address. For instance,
if you want to disassemble the code at 0x20000000, use:\\
\begin{small}
\begin{lstlisting}[frame=tb]
$> disassemble 0x20000001
\end{lstlisting}
\end{small}
2011-10-16 15:59:51 +00:00
\subsection{libstm32l\_discovery}
\paragraph{}
The repository includes the STM32L discovery library source code from ST original firmware packages,
available here:\\
\begin{small}
\begin{lstlisting}[frame=tb]
http://www.st.com/internet/evalboard/product/250990.jsp#FIRMWARE
\end{lstlisting}
\end{small}
\paragraph{}
It is built using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
$> cd stlink.git/example/libstm32l_discovery/build
$> make
\end{lstlisting}
\end{small}
\paragraph{}
An example using the library can be built using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
$> cd stlink.git/example/lcd
$> make
\end{lstlisting}
\end{small}
2011-10-15 17:53:44 +00:00
\newpage
\section{References}
\begin{itemize}
\item http://www.st.com/internet/mcu/product/248823.jsp\\
2011-10-15 18:18:26 +00:00
documentation related to the STM32L mcu
\item http://www.st.com/internet/evalboard/product/250990.jsp\\
documentation related to the STM32L discovery kit
2011-10-15 17:53:44 +00:00
\end{itemize}
2011-10-15 17:30:33 +00:00
\end{document}