Make the blink example build for all platforms.
authorKarl Palsson <karlp@tweak.net.au>
Sat, 22 Oct 2011 15:46:19 +0000 (15:46 +0000)
committerKarl Palsson <karlp@tweak.net.au>
Sat, 22 Oct 2011 15:46:19 +0000 (15:46 +0000)
Less mucking around with make parameters, it's a tiny build.  Verified with a
VL and L board.

Removed the old obsolete bin file

doc/tutorial/tutorial.pdf
doc/tutorial/tutorial.tex
example/blink/Makefile
example/blink/main.c
example/blink/o.bin [deleted file]

index 4ffcc3e563b3df294e331eb3fae97f9843f31817..371f805a0f1a4ddc103155c3fecc8c3a3fc972a0 100644 (file)
Binary files a/doc/tutorial/tutorial.pdf and b/doc/tutorial/tutorial.pdf differ
index a5548058fe18d70e53727fda8bae7492527fa83c..9f8694d0608c643d3dbe0f8b69463cd4c81b21af 100644 (file)
@@ -97,19 +97,21 @@ A simple LED blinking example is provided in the example directory. It is built
 \begin{lstlisting}[frame=tb]
 # update the make option accordingly to your architecture
 cd stlink.git/example/blink ;
-PATH=$TOOLCHAIN_PATH/bin:$PATH make CONFIG_STM32L_DISCOVERY=1;
+PATH=$TOOLCHAIN_PATH/bin:$PATH make
 \end{lstlisting}
 \end{small}
+This builds three files, one for each of the Discovery boards currently
+available.
 
 \paragraph{}
-A GDB server must be start to interact with the STM32. Depending on the discovery kit you
+A GDB server must be started to interact with the STM32. Depending on the discovery kit you
 are using, you must run one of the 2 commands:\\
 \begin{small}
 \begin{lstlisting}[frame=tb]
 # STM32VL discovery kit (onboard ST-link)
 $> sudo ./st-util --stlinkv1 [-d /dev/sg2]
 
-# STM32L discovery kit (onboard ST-link/V2)
+# STM32L or STM32F4 discovery kit (onboard ST-link/V2)
 $> sudo ./st-util 
 
 # Full help for other options (listen port, version)
index e5f704525a8da8eccb63c0d1857764deb96949ea..cf7221da81cb33c234d59978c9872f2d7e56a1c7 100644 (file)
@@ -1,35 +1,32 @@
-EXECUTABLE=blink.elf
-BIN_IMAGE=blink.bin
-
 CC=arm-none-eabi-gcc
 OBJCOPY=arm-none-eabi-objcopy
 
-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
+DEF_CFLAGS=-g -O2 -mlittle-endian -mthumb -ffreestanding -nostdlib -nostdinc
 
 # to run from SRAM
-CFLAGS+=-Wl,-Ttext,0x20000000 -Wl,-e,0x20000000
+DEF_CFLAGS+=-Wl,-Ttext,0x20000000 -Wl,-e,0x20000000
 
 # to write to flash then run
-# CFLAGS+=-Wl,-Ttext,0x08000000 -Wl,-e,0x08000000
+# DEF_CFLAGS+=-Wl,-Ttext,0x08000000 -Wl,-e,0x08000000
+
+CFLAGS_VL=$(DEF_CFLAGS) -mcpu=cortex-m3 -DCONFIG_STM32VL_DISCOVERY=1
+CFLAGS_L=$(DEF_CFLAGS) -mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY
+CFLAGS_F4=$(DEF_CFLAGS) -mcpu=cortex-m4 -DCONFIG_STM32F4_DISCOVERY=1
 
-all: $(BIN_IMAGE)
+all: blink_32VL.elf blink_32L.elf blink_F4.elf
 
-$(BIN_IMAGE): $(EXECUTABLE)
+%.bin: %.elf
        $(OBJCOPY) -O binary $^ $@
 
-$(EXECUTABLE): main.c
-       $(CC) $(CFLAGS) $^ -o $@
+blink_32VL.elf: main.c
+       $(CC) $(CFLAGS_VL) $^ -o $@
+blink_32L.elf: main.c
+       $(CC) $(CFLAGS_L) $^ -o $@
+blink_F4.elf: main.c
+       $(CC) $(CFLAGS_F4) $^ -o $@
 
 clean:
-       rm -rf $(EXECUTABLE)
-       rm -rf $(BIN_IMAGE)
+       rm -rf *.elf
+       rm -rf *.bin
 
 .PHONY: all clean
index 0889b81619a4850b2514db5e3d27ec46af051594..e0438a0dbdec1678b7ff34d823588dceb9e6919d 100644 (file)
@@ -7,36 +7,30 @@ typedef unsigned int uint32_t;
 
 #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 GPIOC 0x40011000 /* port C */
+#define GPIOC_CRH (GPIOC + 0x04) /* port configuration register high */
+#define LED_PORT_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 */
+#define LED_BLUE (1 << 8) /* port C, pin 8 */
+#define LED_GREEN (1 << 9) /* port C, pin 9 */
+#define LED_ORANGE 0
+#define LED_RED 0
 
 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 GPIOB 0x40020400 /* port B */
+#define GPIOB_MODER (GPIOB + 0x00) /* port mode register */
+#define LED_PORT_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 */
+#define LED_BLUE (1 << 6) /* port B, pin 6 */
+#define LED_GREEN (1 << 7) /* port B, pin 7 */
+#define LED_ORANGE 0
+#define LED_RED 0
 
 static inline void setup_leds(void)
 {
@@ -44,26 +38,16 @@ static inline void setup_leds(void)
   *(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;
-}
-
 #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 GPIOD_MODER (GPIOD + 0x00) /* port mode register */
+#define LED_PORT_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 */
+#define LED_GREEN (1 << 12) /* port D, pin 12 */
+#define LED_ORANGE (1 << 13) /* port D, pin 13 */
+#define LED_RED (1 << 14) /* port D, pin 14 */
+#define LED_BLUE (1 << 15) /* port D, pin 15 */
 
 static inline void setup_leds(void)
 {
@@ -71,22 +55,20 @@ static inline void setup_leds(void)
        (1 << (13 * 2)) | (1 << (14 * 2)) | (1 << (15 * 2));
 }
 
+#else
+#error "Architecture must be defined!"
+#endif /* otherwise, error */
 
 static inline void switch_leds_on(void)
 {
-  *(volatile uint32_t*)GPIOD_ODR = LED_GREEN | LED_ORANGE | LED_RED | LED_BLUE;
+  *(volatile uint32_t*)LED_PORT_ODR = LED_BLUE | LED_GREEN | LED_ORANGE | LED_RED;
 }
 
 static inline void switch_leds_off(void)
 {
-  *(volatile uint32_t*)GPIOD_ODR = 0;
+  *(volatile uint32_t*)LED_PORT_ODR = 0;
 }
 
-#else
-#error "Architecture must be defined!"
-#endif /* otherwise, error */
-
-
 #define delay()                                                \
 do {                                                   \
   register unsigned int i;                             \
diff --git a/example/blink/o.bin b/example/blink/o.bin
deleted file mode 100755 (executable)
index 76324f7..0000000
Binary files a/example/blink/o.bin and /dev/null differ