4 /* libstm32l_discovery headers */
5 #include "stm32l1xx_gpio.h"
6 #include "stm32l1xx_adc.h"
7 #include "stm32l1xx_lcd.h"
8 #include "stm32l1xx_rcc.h"
9 #include "stm32l1xx_rtc.h"
10 #include "stm32l1xx_exti.h"
11 #include "stm32l1xx_pwr.h"
12 #include "stm32l1xx_flash.h"
13 #include "stm32l1xx_syscfg.h"
14 #include "stm32l1xx_dbgmcu.h"
16 /* board specific macros */
17 #include "discover_board.h"
20 /* hardware configuration */
22 #if CONFIG_STM32VL_DISCOVERY
24 # define GPIOC 0x40011000 /* port C */
25 # define GPIOC_CRH (GPIOC + 0x04) /* port configuration register high */
26 # define GPIOC_ODR (GPIOC + 0x0c) /* port output data register */
28 # define LED_BLUE (1 << 8) /* port C, pin 8 */
29 # define LED_GREEN (1 << 9) /* port C, pin 9 */
31 static inline void setup_leds(void)
33 *(volatile uint32_t*)GPIOC_CRH = 0x44444411;
36 static inline void switch_leds_on(void)
38 *(volatile uint32_t*)GPIOC_ODR = LED_BLUE | LED_GREEN;
41 static inline void switch_leds_off(void)
43 *(volatile uint32_t*)GPIOC_ODR = 0;
46 #elif CONFIG_STM32L_DISCOVERY
48 # define GPIOB_MODER (GPIOB + 0x00) /* port mode register */
49 # define GPIOB_ODR (GPIOB + 0x14) /* port output data register */
51 # define LED_BLUE (1 << 6) /* port B, pin 6 */
52 # define LED_GREEN (1 << 7) /* port B, pin 7 */
54 static inline void setup_leds(void)
56 /* configure port 6 and 7 as output */
57 *(volatile uint32_t*)GPIOB_MODER |= (1 << (7 * 2)) | (1 << (6 * 2));
60 static inline void switch_leds_on(void)
62 GPIO_HIGH(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
63 GPIO_HIGH(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);
66 static inline void switch_leds_off(void)
68 GPIO_LOW(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
69 GPIO_LOW(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);
72 #endif /* otherwise, error */
77 volatile unsigned int i; \
78 for (i = 0; i < 1000000; ++i) \
79 __asm__ __volatile__ ("nop\n\t":::"memory"); \
83 static void RCC_Configuration(void)
85 /* Enable HSI Clock */
88 /*!< Wait till HSI is ready */
89 while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)
92 RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
94 RCC_MSIRangeConfig(RCC_MSIRange_6);
96 RCC_HSEConfig(RCC_HSE_OFF);
97 if(RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET )
104 static void RTC_Configuration(void)
106 /* Allow access to the RTC */
107 PWR_RTCAccessCmd(ENABLE);
109 /* Reset Backup Domain */
110 RCC_RTCResetCmd(ENABLE);
111 RCC_RTCResetCmd(DISABLE);
114 RCC_LSEConfig(RCC_LSE_ON);
116 /* Wait till LSE is ready */
117 while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
120 RCC_RTCCLKCmd(ENABLE);
122 /* LCD Clock Source Selection */
123 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
129 static RCC_ClocksTypeDef RCC_Clocks;
130 static GPIO_InitTypeDef GPIO_InitStructure;
132 /* Configure Clocks for Application need */
135 /* Configure RTC Clocks */
138 /* Set internal voltage regulator to 1.8V */
139 PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
141 /* Wait Until the Voltage Regulator is ready */
142 while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
144 /* configure gpios */
146 /* Enable GPIOs clock */
147 RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK, ENABLE);
149 /* Configure the GPIO_LED pins LD3 & LD4*/
150 GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN;
151 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
152 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
153 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
154 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
155 GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure);
156 GPIO_LOW(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
157 GPIO_LOW(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);