stlink/doc/tutorial/tutorial.tex

235 wiersze
6.3 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 open source environment.
2011-10-15 17:30:33 +00:00
\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 open source software to program and debug ST's STM32 Discovery kits. Those
2011-10-15 17:30:33 +00:00
kits have an onboard chip that translates USB commands sent by the host PC into
JTAG/SWD commands. This chip is called STLINK, (yes, isn't that confusing? suggest a better
name!) and comes in 2 versions (STLINK v1 and v2). From a software
point of view, those versions differ only in the transport layer used to communicate
(v1 uses SCSI passthru commands, while v2 uses raw USB). From a user point of view, they
are identical.
\paragraph{}
2011-10-22 02:11:04 +00:00
Before continuing, the following dependencies must be met:
\begin{itemize}
\item libusb-1.0
\item pkg-config
\item autotools
\end{itemize}
2011-10-22 02:11:04 +00:00
\paragraph{}
STLINK should run on any system meeting the above constraints.
2011-10-15 17:30:33 +00:00
\paragraph{}
The STLINK software source code is retrieved using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
2011-10-22 02:11:04 +00:00
$> git clone https://github.com/texane/stlink stlink.git
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
2011-10-22 02:11:04 +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-22 02:11:04 +00:00
$> cd stlink.git
$> ./autogen.sh
$> ./configure
$> make
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
2011-10-22 02:11:04 +00:00
It includes:
\begin{itemize}
\item a communication library (stlink.git/libstlink.a),
\item a GDB server (stlink.git/st-util),
\item a flash manipulation tool (stlink.git/st-flash).
2011-10-22 02:11:04 +00:00
\end{itemize}
2011-10-15 17:30:33 +00:00
\newpage
\section{Using the GDB server}
\paragraph{}
This assumes you have got the libopencm3 project downloaded in [ocm3]. The
libopencm3 project has some good, reliable examples for each of the Discovery boards.
Even if you don't plan on using libopencm3, the examples they provide will help you
verify that:
\begin{itemize}
\item Your installed toolchain is capable of compiling for cortex M3/M4 targets
\item stlink is functional
\item Your arm-none-eabi-gdb is functional
\item Your board is functional
\end{itemize}
2011-10-15 17:30:33 +00:00
\paragraph{}
A GDB server must be started to interact with the STM32. Depending on the discovery kit you
2011-10-15 22:14:12 +00:00
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 (onboard ST-link)
$> ./st-util --stlinkv1
2011-10-15 17:30:33 +00:00
# STM32L or STM32F4 discovery kit (onboard ST-link/V2)
$> ./st-util
# Full help for other options (listen port, version)
$> ./st-util --help
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 example_file.elf
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
From GDB, connect to the server using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
(gdb) target extended localhost:4242
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
GDB has memory maps for as many chips as it knows about, and will load your project
into either flash or SRAM based on how the project was linked. Linking projects
to boot from SRAM is beyond the scope of this document.
Because of these built in memory maps, after specifying the .elf at the command line, now
we can simply "load" the target:\\
2011-10-15 17:30:33 +00:00
\begin{small}
\begin{lstlisting}[frame=tb]
(gdb) load
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
st-util will load all sections into their appropriate addresses, and "correctly" set the PC
register. So, to run your freshly loaded program, simply "continue"\\
2011-10-15 17:30:33 +00:00
\begin{small}
\begin{lstlisting}[frame=tb]
(gdb) continue
2011-10-15 17:30:33 +00:00
\end{lstlisting}
\end{small}
2011-10-15 22:14:12 +00:00
\paragraph{}
Your program should now be running, and, if you used one of the blinking examples from
libopencm3, the LEDs on the board should be blinking for you.
2011-10-15 17:53:44 +00:00
2011-10-22 02:11:04 +00:00
\newpage
\section{Building and flashing a program}
2011-10-22 02:11:04 +00:00
\paragraph{}
If you want to simply flash binary files to arbitrary sections of memory, or
read arbitary addresses of memory out to a binary file, use the st-flash tool,
as shown below:\\
2011-10-22 02:11:04 +00:00
\begin{small}
\begin{lstlisting}[frame=tb]
# stlinkv1 command to read 4096 from flash into out.bin
$> ./st-flash read v1 out.bin 0x8000000 4096
2011-10-22 02:11:04 +00:00
# stlinkv2 command
$> ./st-flash read out.bin 0x8000000 4096
2011-10-22 02:11:04 +00:00
# stlinkv1 command to write the file in.bin into flash
$> ./st-flash write v1 in.bin 0x8000000
2011-10-22 02:11:04 +00:00
# stlinkv2 command
$> ./st-flash write in.bin 0x8000000
2011-10-22 02:11:04 +00:00
\end{lstlisting}
\end{small}
\paragraph{}
Of course, you can use this instead of the gdb server, if you prefer. Just remember
to use the ".bin" image, rather than the .elf file.\\
\begin{small}
\begin{lstlisting}[frame=tb]
# write blink.bin into FLASH
$> [sudo] ./st-flash write fancy_blink.bin 0x08000000
\end{lstlisting}
\end{small}
\paragraph{}
Upon reset, the board LEDs should be blinking.
2011-10-17 20:06:23 +00:00
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]
(gdb) disassemble 0x20000001
\end{lstlisting}
\end{small}
2011-10-22 02:11:04 +00:00
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
\item http://www.libopencm3.org\\
libopencm3, a project providing a firmware library, with solid examples for Cortex
M3, M4 and M0 processors from any vendor.
2011-10-15 17:53:44 +00:00
\end{itemize}
2011-10-15 17:30:33 +00:00
\end{document}