[fixme] blink_flash example working. more initialization needed, use libstm32_discovery.
authorFabien Le Mentec <texane@gmail.com>
Sun, 23 Oct 2011 13:23:38 +0000 (08:23 -0500)
committerFabien Le Mentec <texane@gmail.com>
Sun, 23 Oct 2011 13:23:38 +0000 (08:23 -0500)
example/blink/Makefile
example/blink_flash/Makefile
example/blink_flash/discover_board.h [new file with mode: 0644]
example/blink_flash/main.c
example/blink_flash/startup_stm32l1xx_md.s

index e5f704525a8da8eccb63c0d1857764deb96949ea..1906b9159e6f0e2b9cc6f22d8ef94e46170aa6d3 100644 (file)
@@ -12,7 +12,7 @@ else ifeq ($(CONFIG_STM32VL_DISCOVERY), 1)
 else ifeq ($(CONFIG_STM32F4_DISCOVERY), 1)
        CFLAGS+=-mcpu=cortex-m4 -DCONFIG_STM32F4_DISCOVERY=1    
 endif
-       CFLAGS+=-ffreestanding -nostdlib -nostdinc
+CFLAGS+=-ffreestanding -nostdlib -nostdinc
 
 # to run from SRAM
 CFLAGS+=-Wl,-Ttext,0x20000000 -Wl,-e,0x20000000
index 2c74c32e7c67c67d48969d2c4d47d126df990b19..46117311e4a98df7c6523d6123d37e4abb9aa011 100644 (file)
@@ -4,9 +4,7 @@ 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=1
 else ifeq ($(CONFIG_STM32VL_DISCOVERY), 1)
@@ -16,18 +14,24 @@ else ifeq ($(CONFIG_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)
diff --git a/example/blink_flash/discover_board.h b/example/blink_flash/discover_board.h
new file mode 100644 (file)
index 0000000..d93a184
--- /dev/null
@@ -0,0 +1,61 @@
+ /**\r
+  ******************************************************************************\r
+  * @file    discover_board.h\r
+  * @author  Microcontroller Division\r
+  * @version V1.0.2\r
+  * @date    September-2011\r
+  * @brief   Input/Output defines\r
+  ******************************************************************************\r
+  * @copy\r
+  *\r
+  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
+  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
+  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
+  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
+  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
+  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
+  *\r
+  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>\r
+  */\r
+\r
+/* Define to prevent recursive inclusion -------------------------------------*/\r
+\r
+#ifndef __DISCOVER_BOARD_H\r
+#define __DISCOVER_BOARD_H\r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+/* #include "stm32l1xx.h"   */\r
+\r
+#define bool _Bool\r
+#define FALSE 0\r
+#define TRUE !FALSE\r
+\r
+/* MACROs for SET, RESET or TOGGLE Output port */\r
+\r
+#define GPIO_HIGH(a,b)                 a->BSRRL = b\r
+#define GPIO_LOW(a,b)          a->BSRRH = b\r
+#define GPIO_TOGGLE(a,b)       a->ODR ^= b \r
+\r
+#define USERBUTTON_GPIO_PORT   GPIOA\r
+#define USERBUTTON_GPIO_PIN     GPIO_Pin_0\r
+#define USERBUTTON_GPIO_CLK     RCC_AHBPeriph_GPIOA\r
+\r
+#define LD_GPIO_PORT           GPIOB\r
+#define LD_GREEN_GPIO_PIN              GPIO_Pin_7\r
+#define LD_BLUE_GPIO_PIN             GPIO_Pin_6\r
+#define LD_GPIO_PORT_CLK             RCC_AHBPeriph_GPIOB\r
+\r
+#define CTN_GPIO_PORT           GPIOC\r
+#define CTN_CNTEN_GPIO_PIN      GPIO_Pin_13\r
+#define CTN_GPIO_CLK            RCC_AHBPeriph_GPIOC\r
+\r
+#define WAKEUP_GPIO_PORT        GPIOA\r
+\r
+#define IDD_MEASURE_PORT       GPIOA\r
+#define IDD_MEASURE             GPIO_Pin_4\r
+\r
+\r
+#endif\r
+\r
+\r
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/\r
index 6a893560e9d9ce1254c8270913b5fdd19acec16a..d27ef7f9babf941879869fe13875c4e8dcdc30a0 100644 (file)
@@ -1,6 +1,20 @@
-/* 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 */
@@ -31,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 */
 
@@ -46,12 +59,14 @@ 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 */
@@ -59,14 +74,87 @@ static inline void switch_leds_off(void)
 
 #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)
   {
index 4ec8203b022c9f250c343f775b7271b1840595ad..9a8389c9f7a1071cd92a527ec05049ecca95de68 100644 (file)
@@ -62,7 +62,6 @@ defined in linker script */
   .weak Reset_Handler\r
   .type Reset_Handler, %function\r
 Reset_Handler:\r
-\r
 /* Copy the data segment initializers from flash to SRAM */  \r
   movs r1, #0\r
   b LoopCopyDataInit\r
@@ -92,7 +91,7 @@ LoopFillZerobss:
   bcc FillZerobss\r
 /* Call the clock system intitialization function.*/\r
 /* let main do the system initialization */\r
-/* bl  SystemInit */\r
+  bl  SystemInit\r
 /* Call the application's entry point.*/\r
   bl main\r
   bx lr\r