Skip to content

Commit

Permalink
Merge upstream texane/master
Browse files Browse the repository at this point in the history
  • Loading branch information
karlp committed Oct 22, 2011
1 parent 234e144 commit 9bc72d4
Show file tree
Hide file tree
Showing 23 changed files with 1,626 additions and 336 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
libstlink.a
test_usb
test_sg
gdbserver/st-utils
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ [email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
41 changes: 33 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@

# make ... for both libusb and libsg
#
# make CONFIG_USE_LIBSG=0 ...
# for just libusb
#
VPATH=src

SOURCES_LIB=stlink-common.c stlink-usb.c stlink-sg.c
SOURCES_LIB=stlink-common.c stlink-usb.c
OBJS_LIB=$(SOURCES_LIB:.c=.o)
TEST_PROGRAMS=test_usb
LDFLAGS=-lusb-1.0 -L. -lstlink

ifeq ($(CONFIG_USE_LIBSG),)
CONFIG_USE_LIBSG=1
endif

ifneq ($(CONFIG_USE_LIBSG),0)
SOURCES_LIB+=stlink-sg.c
CFLAGS+=-DCONFIG_USE_LIBSG=1
LDFLAGS+=-lsgutils2
TEST_PROGRAMS+=test_sg
endif

CFLAGS+=-g
CFLAGS+=-DCONFIG_USE_LIBUSB
CFLAGS+=-DCONFIG_USE_LIBSG
CFLAGS+=-DDEBUG
CFLAGS+=-DCONFIG_USE_LIBUSB=1
CFLAGS+=-DDEBUG=1
CFLAGS+=-std=gnu99
CFLAGS+=-Wall -Wextra

LDFLAGS=-lstlink -lusb-1.0 -lsgutils2 -L.

LIBRARY=libstlink.a

all: $(LIBRARY) test_usb test_sg
all: $(LIBRARY) flash gdbserver $(TEST_PROGRAMS)

$(LIBRARY): $(OBJS_LIB)
@echo "objs are $(OBJS_LIB)"
Expand All @@ -42,5 +57,15 @@ clean:
rm -rf $(LIBRARY)
rm -rf test_usb*
rm -rf test_sg*

distclean: clean
$(MAKE) -C flash clean
$(MAKE) -C gdbserver clean

.PHONY: clean all
flash:
$(MAKE) -C flash CONFIG_USE_LIBSG="$(CONFIG_USE_LIBSG)"

gdbserver:
$(MAKE) -C gdbserver

.PHONY: clean all flash gdbserver
15 changes: 11 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
. flash writing is not working from GDB
add a standalone application, flash/
. flash tool
. test support for reading
. writing is not working. refer to the specs, may have changed for stm32l
. then test with blink_flash example
. then update the documentation

. add a startup.S based example
. documentation
. make README points to doc/tutorial

. remove libsg dependency using:
https://github.com/afaerber/stlink/tree/master/libstlink

. compile and test a realtime kernel, for instance:
http://www.chibios.org/dokuwiki/doku.php?id=start
http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:stm32l_discovery
svn checkout https://chibios.svn.sourceforge.net/svnroot/chibios/trunk ;
cd chibios/trunk/demos/ARMCM3-STM32L152-DISCOVERY ;
make ;
Binary file modified doc/tutorial/tutorial.pdf
Binary file not shown.
65 changes: 55 additions & 10 deletions doc/tutorial/tutorial.tex
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,37 @@ \section{Installing STLINK}
(v1 uses SCSI passthru commands, while v2 uses raw USB).

\paragraph{}
Before continuing, the following dependencies are required:
Before continuing, the following dependencies must be met:
\begin{itemize}
\item libusb-1.0
\item libsg2
\item libsgutils2 (optionnal)
\end{itemize}

\paragraph{}
STLINK should run on any system meeting the above constraints.

\paragraph{}
The STLINK software source code is retrieved using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
git clone https://github.com/texane/stlink stlink.git
$> git clone https://github.com/texane/stlink stlink.git
\end{lstlisting}
\end{small}

\paragraph{}
The GDB server is called st-util and is built using:\\
Everything can be built from the top directory:\\
\begin{small}
\begin{lstlisting}[frame=tb]
$> cd stlink.git;
$> make ;
$> cd gdbserver ;
$> make ;
$> cd stlink.git
$> make CONFIG_USE_LIBSG=0
\end{lstlisting}
\end{small}
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}


\newpage
Expand All @@ -88,8 +95,9 @@ \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
cd stlink.git/example/blink ;
PATH=$TOOLCHAIN_PATH/bin:$PATH make ;
PATH=$TOOLCHAIN_PATH/bin:$PATH make CONFIG_STM32L_DISCOVERY=1;
\end{lstlisting}
\end{small}

Expand All @@ -102,7 +110,8 @@ \section{Building and running a program}
$> sudo ./st-util /dev/sg2

# STM32L discovery kit
$> sudo ./st-util
# 2 dummy command line arguments needed, will be fixed soon
$> sudo ./st-util fu bar
\end{lstlisting}
\end{small}

Expand Down Expand Up @@ -144,6 +153,31 @@ \section{Building and running a program}
The board BLUE and GREEN leds should be blinking (those leds are near the user and reset buttons).


\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]
# change to the flash tool directory
$> cd stlink.git/flash ;

# 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}


\newpage
\section{Notes}

Expand Down Expand Up @@ -187,6 +221,17 @@ \subsection{libstm32l\_discovery}
\end{lstlisting}
\end{small}

\subsection{STM32VL support}
\paragraph{}
It seems support for STM32VL is quite broken. If it does not work, try build STLINK using libsg:
\begin{small}
\begin{lstlisting}[frame=tb]
$> cd stlink.git
$> make CONFIG_USE_LIBSG=1
\end{lstlisting}
\end{small}


\newpage
\section{References}
\begin{itemize}
Expand Down
11 changes: 9 additions & 2 deletions example/blink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ BIN_IMAGE=blink.bin
CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy

CFLAGS=-O2 -mlittle-endian -mthumb -g
CFLAGS+=-mcpu=cortex-m3 -ffreestanding -nostdlib -nostdinc
CFLAGS=-g -O2 -mlittle-endian -mthumb
ifeq ($(CONFIG_STM32L_DISCOVERY), 1)
CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY
else ifeq ($(CONFIG_STM32VL_DISCOVERY), 1)
CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32VL_DISCOVERY=1
else ifeq ($(CONFIG_STM32F4_DISCOVERY), 1)
CFLAGS+=-mcpu=cortex-m4 -DCONFIG_STM32F4_DISCOVERY=1
endif
CFLAGS+=-ffreestanding -nostdlib -nostdinc

# to run from SRAM
CFLAGS+=-Wl,-Ttext,0x20000000 -Wl,-e,0x20000000
Expand Down
34 changes: 30 additions & 4 deletions example/blink/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ typedef unsigned int uint32_t;

/* hardware configuration */

#define CONFIG_STM32L_DISCOVERY 1
#define CONFIG_STM32VL_DISCOVERY 0


#if CONFIG_STM32VL_DISCOVERY

# define GPIOC 0x40011000 /* port C */
Expand Down Expand Up @@ -58,6 +54,36 @@ static inline void switch_leds_off(void)
*(volatile uint32_t*)GPIOB_ODR = 0;
}

#elif CONFIG_STM32F4_DISCOVERY

#define GPIOD 0x40020C00 /* port D */
# define GPIOD_MODER (GPIOD + 0x00) /* port mode register */
# define GPIOD_ODR (GPIOD + 0x14) /* port output data register */

# define LED_GREEN (1 << 12) /* port B, pin 12 */
# define LED_ORANGE (1 << 13) /* port B, pin 13 */
# define LED_RED (1 << 14) /* port B, pin 14 */
# define LED_BLUE (1 << 15) /* port B, pin 15 */

static inline void setup_leds(void)
{
*(volatile uint32_t*)GPIOD_MODER |= (1 << (12 * 2)) | (1 << (13 * 2)) |
(1 << (13 * 2)) | (1 << (14 * 2)) | (1 << (15 * 2));
}


static inline void switch_leds_on(void)
{
*(volatile uint32_t*)GPIOD_ODR = LED_GREEN | LED_ORANGE | LED_RED | LED_BLUE;
}

static inline void switch_leds_off(void)
{
*(volatile uint32_t*)GPIOD_ODR = 0;
}

#else
#error "Architecture must be defined!"
#endif /* otherwise, error */


Expand Down
36 changes: 36 additions & 0 deletions example/blink_flash/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
EXECUTABLE=blink.elf
BIN_IMAGE=blink.bin

CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy

CFLAGS=-O2 -mlittle-endian -mthumb

CFLAGS=-g -O2 -mlittle-endian -mthumb
ifeq ($(CONFIG_STM32L_DISCOVERY), 1)
CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY
else ifeq ($(CONFIG_STM32VL_DISCOVERY), 1)
CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32VL_DISCOVERY=1
else ifeq ($(CONFIG_STM32F4_DISCOVERY), 1)
CFLAGS+=-mcpu=cortex-m4 -DCONFIG_STM32F4_DISCOVERY=1
else
$(error "must specify CONFIG_ for board!")
endif
CFLAGS+=-ffreestanding -nostdlib -nostdinc

# to run from FLASH
CFLAGS+=-Wl,-T,stm32_flash.ld

all: $(BIN_IMAGE)

$(BIN_IMAGE): $(EXECUTABLE)
$(OBJCOPY) -O binary $^ $@

$(EXECUTABLE): main.c startup_stm32l1xx_md.s
$(CC) $(CFLAGS) $^ -o $@

clean:
rm -rf $(EXECUTABLE)
rm -rf $(BIN_IMAGE)

.PHONY: all clean
82 changes: 82 additions & 0 deletions example/blink_flash/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* missing type */

typedef unsigned int uint32_t;


/* hardware configuration */

#define CONFIG_STM32L_DISCOVERY 1
#define CONFIG_STM32VL_DISCOVERY 0


#if CONFIG_STM32VL_DISCOVERY

# define GPIOC 0x40011000 /* port C */
# define GPIOC_CRH (GPIOC + 0x04) /* port configuration register high */
# define GPIOC_ODR (GPIOC + 0x0c) /* port output data register */

# define LED_BLUE (1 << 8) /* port C, pin 8 */
# define LED_GREEN (1 << 9) /* port C, pin 9 */

static inline void setup_leds(void)
{
*(volatile uint32_t*)GPIOC_CRH = 0x44444411;
}

static inline void switch_leds_on(void)
{
*(volatile uint32_t*)GPIOC_ODR = LED_BLUE | LED_GREEN;
}

static inline void switch_leds_off(void)
{
*(volatile uint32_t*)GPIOC_ODR = 0;
}

#elif CONFIG_STM32L_DISCOVERY

# define GPIOB 0x40020400 /* port B */
# define GPIOB_MODER (GPIOB + 0x00) /* port mode register */
# define GPIOB_ODR (GPIOB + 0x14) /* port output data register */

# define LED_BLUE (1 << 6) /* port B, pin 6 */
# define LED_GREEN (1 << 7) /* port B, pin 7 */

static inline void setup_leds(void)
{
/* configure port 6 and 7 as output */
*(volatile uint32_t*)GPIOB_MODER |= (1 << (7 * 2)) | (1 << (6 * 2));
}

static inline void switch_leds_on(void)
{
*(volatile uint32_t*)GPIOB_ODR = LED_BLUE | LED_GREEN;
}

static inline void switch_leds_off(void)
{
*(volatile uint32_t*)GPIOB_ODR = 0;
}

#endif /* otherwise, error */


#define delay() \
do { \
register unsigned int i; \
for (i = 0; i < 1000000; ++i) \
__asm__ __volatile__ ("nop\n\t":::"memory"); \
} while (0)

void main(void)
{
setup_leds();

while (1)
{
switch_leds_on();
delay();
switch_leds_off();
delay();
}
}
Loading

0 comments on commit 9bc72d4

Please sign in to comment.