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
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)
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)
--- /dev/null
+ /**\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>© 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
-/* 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 */
#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 */
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)
{
.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
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