Permalink
Browse files

Merge branch 'master' of https://github.com/texane/stlink

Conflicts:
	Makefile
	doc/tutorial/tutorial.pdf
	example/blink/Makefile
	flash/main.c
	src/stlink-common.c
	src/stlink-usb.c

Mostly whitespace conflicts it seems.
  • Loading branch information...
2 parents 52b626b + 5a37969 commit c98c487fa52651505871de11d65bacaeaf1cac39 @karlp karlp committed Nov 4, 2011
View
@@ -8,4 +8,5 @@ h0rr0rrdrag@gmail.com
mstempin@com1.fr
bon@elektron.ikp.physik.tu-darmstadt.de
nelsonjm@macpod.neta
-ned@bike-nomad.com
+ned@bike-nomad.com
+csamuelson@swingpal.com
View
@@ -5,7 +5,7 @@ VPATH=src
SOURCES_LIB=stlink-common.c stlink-usb.c stlink-sg.c uglylogging.c
OBJS_LIB=$(SOURCES_LIB:.c=.o)
TEST_PROGRAMS=test_usb test_sg
-LDFLAGS=-lusb-1.0 -L. -lstlink
+LDFLAGS=-L. -lstlink -lusb-1.0
CFLAGS+=-g
CFLAGS+=-DDEBUG=1
View
@@ -1,8 +1,5 @@
. 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
+ . improve flash writing, still use word fast write... too slow
. documentation
. make README points to doc/tutorial
Binary file not shown.
@@ -90,8 +90,8 @@ \section{Installing STLINK}
\newpage
-
-\section{Building and running a program}
+\section{Building and running a program in SRAM}
+\paragraph{}
A simple LED blinking example is provided in the example directory. It is built using:\\
\begin{small}
\begin{lstlisting}[frame=tb]
@@ -165,10 +165,9 @@ \section{Building and running a program}
All the LEDs on the board should now be blinking in time (those leds are near the user and reset buttons).
\newpage
-\section{Reading and writing to flash}
+\section{Building and flashing a program}
\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:\\
+FLASH memory reading and writing is done by a separate tool, as shown below:\\
\begin{small}
\begin{lstlisting}[frame=tb]
# change to the flash tool directory
@@ -188,6 +187,49 @@ \section{Reading and writing to flash}
\end{lstlisting}
\end{small}
+\paragraph{}
+A LED blinking example is provided:\\
+\begin{small}
+\begin{lstlisting}[frame=tb]
+# build the example, resulting in blink.bin
+$> cd stlink.git/example/blink_flash
+$> PATH=$TOOLCHAIN_PATH:$PATH make CONFIG_STM32L_DISCOVERY=1
+
+# write blink.bin into FLASH
+$> sudo ./flash write blink.bin 0x08000000
+\end{lstlisting}
+\end{small}
+
+\paragraph{}
+Upon reset, the board LEDs should be blinking.
+
+\newpage
+\section{Building and installing the CHIBIOS kernel}
+\paragraph{}
+CHIBIOS is an open source RTOS. More information can be found on the project website:
+\begin{center}
+http://www.chibios.org/dokuwiki/doku.php
+\end{center}
+
+\paragraph{}
+It supports several boards, including the STM32L DISCOVERY kit:
+\begin{center}
+http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:stm32l\_discovery
+\end{center}
+
+\paragraph{}
+The installation procedure is detailed below:\\
+\begin{small}
+\begin{lstlisting}[frame=tb]
+# checkout and build CHIBIOS for STM32L DISCOVERY kits
+svn checkout https://chibios.svn.sourceforge.net/svnroot/chibios/trunk
+cd chibios/trunk/demos/ARMCM3-STM32L152-DISCOVERY
+PATH=$TOOLCHAIN_PATH:$PATH make
+
+# flash the image into STM32L
+sudo ./flash write build/ch.bin 0x08000000
+\end{lstlisting}
+\end{small}
\newpage
\section{Notes}
@@ -4,30 +4,34 @@ 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
+CFLAGS=-O3 -mlittle-endian -mthumb
ifeq ($(CONFIG_STM32L_DISCOVERY), 1)
- CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY
+ CFLAGS+=-mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY=1
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
+CFLAGS+=-ffreestanding -nostdlib -nostdinc
# to run from FLASH
CFLAGS+=-Wl,-T,stm32_flash.ld
+# stm32l_discovery lib
+CFLAGS+=-I../libstm32l_discovery/inc
+CFLAGS+=-I../libstm32l_discovery/inc/base
+CFLAGS+=-I../libstm32l_discovery/inc/core_support
+CFLAGS+=-I../libstm32l_discovery/inc/device_support
+
all: $(BIN_IMAGE)
$(BIN_IMAGE): $(EXECUTABLE)
$(OBJCOPY) -O binary $^ $@
-$(EXECUTABLE): main.c startup_stm32l1xx_md.s
- $(CC) $(CFLAGS) $^ -o $@
+$(EXECUTABLE): main.c system_stm32l1xx.c startup_stm32l1xx_md.s
+ $(CC) $(CFLAGS) $^ -o $@ -L../libstm32l_discovery/build -lstm32l_discovery
clean:
rm -rf $(EXECUTABLE)
@@ -0,0 +1,61 @@
+ /**
+ ******************************************************************************
+ * @file discover_board.h
+ * @author Microcontroller Division
+ * @version V1.0.2
+ * @date September-2011
+ * @brief Input/Output defines
+ ******************************************************************************
+ * @copy
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+
+#ifndef __DISCOVER_BOARD_H
+#define __DISCOVER_BOARD_H
+
+/* Includes ------------------------------------------------------------------*/
+/* #include "stm32l1xx.h" */
+
+#define bool _Bool
+#define FALSE 0
+#define TRUE !FALSE
+
+/* MACROs for SET, RESET or TOGGLE Output port */
+
+#define GPIO_HIGH(a,b) a->BSRRL = b
+#define GPIO_LOW(a,b) a->BSRRH = b
+#define GPIO_TOGGLE(a,b) a->ODR ^= b
+
+#define USERBUTTON_GPIO_PORT GPIOA
+#define USERBUTTON_GPIO_PIN GPIO_Pin_0
+#define USERBUTTON_GPIO_CLK RCC_AHBPeriph_GPIOA
+
+#define LD_GPIO_PORT GPIOB
+#define LD_GREEN_GPIO_PIN GPIO_Pin_7
+#define LD_BLUE_GPIO_PIN GPIO_Pin_6
+#define LD_GPIO_PORT_CLK RCC_AHBPeriph_GPIOB
+
+#define CTN_GPIO_PORT GPIOC
+#define CTN_CNTEN_GPIO_PIN GPIO_Pin_13
+#define CTN_GPIO_CLK RCC_AHBPeriph_GPIOC
+
+#define WAKEUP_GPIO_PORT GPIOA
+
+#define IDD_MEASURE_PORT GPIOA
+#define IDD_MEASURE GPIO_Pin_4
+
+
+#endif
+
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
@@ -1,13 +1,23 @@
-/* missing type */
+/* base headers */
+#include "stdint.h"
-typedef unsigned int uint32_t;
+/* libstm32l_discovery headers */
+#include "stm32l1xx_gpio.h"
+#include "stm32l1xx_adc.h"
+#include "stm32l1xx_lcd.h"
+#include "stm32l1xx_rcc.h"
+#include "stm32l1xx_rtc.h"
+#include "stm32l1xx_exti.h"
+#include "stm32l1xx_pwr.h"
+#include "stm32l1xx_flash.h"
+#include "stm32l1xx_syscfg.h"
+#include "stm32l1xx_dbgmcu.h"
+/* board specific macros */
+#include "discover_board.h"
-/* hardware configuration */
-
-#define CONFIG_STM32L_DISCOVERY 1
-#define CONFIG_STM32VL_DISCOVERY 0
+/* hardware configuration */
#if CONFIG_STM32VL_DISCOVERY
@@ -35,7 +45,6 @@ static inline void switch_leds_off(void)
#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 */
@@ -50,27 +59,102 @@ static inline void setup_leds(void)
static inline void switch_leds_on(void)
{
- *(volatile uint32_t*)GPIOB_ODR = LED_BLUE | LED_GREEN;
+ GPIO_HIGH(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
+ GPIO_HIGH(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);
}
static inline void switch_leds_off(void)
{
- *(volatile uint32_t*)GPIOB_ODR = 0;
+ GPIO_LOW(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
+ GPIO_LOW(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);
}
#endif /* otherwise, error */
#define delay() \
do { \
- register unsigned int i; \
+ volatile unsigned int i; \
for (i = 0; i < 1000000; ++i) \
__asm__ __volatile__ ("nop\n\t":::"memory"); \
} while (0)
+
+static void RCC_Configuration(void)
+{
+ /* Enable HSI Clock */
+ RCC_HSICmd(ENABLE);
+
+ /*!< Wait till HSI is ready */
+ while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)
+ {}
+
+ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
+
+ RCC_MSIRangeConfig(RCC_MSIRange_6);
+
+ RCC_HSEConfig(RCC_HSE_OFF);
+ if(RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET )
+ {
+ while(1);
+ }
+}
+
+
+static void RTC_Configuration(void)
+{
+ /* Allow access to the RTC */
+ PWR_RTCAccessCmd(ENABLE);
+
+ /* Reset Backup Domain */
+ RCC_RTCResetCmd(ENABLE);
+ RCC_RTCResetCmd(DISABLE);
+
+ /* LSE Enable */
+ RCC_LSEConfig(RCC_LSE_ON);
+
+ /* Wait till LSE is ready */
+ while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
+ {}
+
+ RCC_RTCCLKCmd(ENABLE);
+
+ /* LCD Clock Source Selection */
+ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
+
+}
+
void main(void)
{
- setup_leds();
+ static RCC_ClocksTypeDef RCC_Clocks;
+ static GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Configure Clocks for Application need */
+ RCC_Configuration();
+
+ /* Configure RTC Clocks */
+ RTC_Configuration();
+
+ /* Set internal voltage regulator to 1.8V */
+ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
+
+ /* Wait Until the Voltage Regulator is ready */
+ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
+
+ /* configure gpios */
+
+ /* Enable GPIOs clock */
+ RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK, ENABLE);
+
+ /* Configure the GPIO_LED pins LD3 & LD4*/
+ GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure);
+ GPIO_LOW(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
+ GPIO_LOW(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);
while (1)
{
@@ -62,7 +62,6 @@ defined in linker script */
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
-
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
@@ -92,7 +91,7 @@ LoopFillZerobss:
bcc FillZerobss
/* Call the clock system intitialization function.*/
/* let main do the system initialization */
-/* bl SystemInit */
+ bl SystemInit
/* Call the application's entry point.*/
bl main
bx lr
Oops, something went wrong.

0 comments on commit c98c487

Please sign in to comment.