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 #elif CONFIG_STM32F4_DISCOVERY
74 //#define GPIOD 0x40020C00 /* port D */
75 # define GPIOD_MODER (GPIOD + 0x00) /* port mode register */
76 # define GPIOD_ODR (GPIOD + 0x14) /* port output data register */
78 # define LED_GREEN (1 << 12) /* port B, pin 12 */
79 # define LED_ORANGE (1 << 13) /* port B, pin 13 */
80 # define LED_RED (1 << 14) /* port B, pin 14 */
81 # define LED_BLUE (1 << 15) /* port B, pin 15 */
86 static inline void setup_leds(void)
88 *(volatile uint32_t*)GPIOD_MODER |= (1 << (12 * 2)) | (1 << (13 * 2)) |
89 (1 << (13 * 2)) | (1 << (14 * 2)) | (1 << (15 * 2));
93 static inline void switch_leds_on(void)
95 *(volatile uint32_t*)GPIOD_ODR = LED_GREEN | LED_RED ;
98 static inline void switch_leds_off(void)
100 *(volatile uint32_t*)GPIOD_ODR = 0;
103 #endif /* otherwise, error */
108 volatile unsigned int i; \
109 for (i = 0; i < 1000000; ++i) \
110 __asm__ __volatile__ ("nop\n\t":::"memory"); \
114 static void RCC_Configuration(void)
116 /* Enable HSI Clock */
119 /*!< Wait till HSI is ready */
120 while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)
123 RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
125 RCC_MSIRangeConfig(RCC_MSIRange_6);
127 RCC_HSEConfig(RCC_HSE_OFF);
128 if(RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET )
135 static void RTC_Configuration(void)
137 /* Allow access to the RTC */
138 PWR_RTCAccessCmd(ENABLE);
140 /* Reset Backup Domain */
141 RCC_RTCResetCmd(ENABLE);
142 RCC_RTCResetCmd(DISABLE);
145 RCC_LSEConfig(RCC_LSE_ON);
147 /* Wait till LSE is ready */
148 while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
151 RCC_RTCCLKCmd(ENABLE);
153 /* LCD Clock Source Selection */
154 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
160 static RCC_ClocksTypeDef RCC_Clocks;
161 static GPIO_InitTypeDef GPIO_InitStructure;
163 /* Configure Clocks for Application need */
166 /* Configure RTC Clocks */
169 /* Set internal voltage regulator to 1.8V */
170 PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1);
172 /* Wait Until the Voltage Regulator is ready */
173 while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ;
175 /* configure gpios */
177 /* Enable GPIOs clock */
178 RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK, ENABLE);
180 /* Configure the GPIO_LED pins LD3 & LD4*/
181 GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN;
182 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
183 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
184 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
185 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
186 GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure);
187 GPIO_LOW(LD_GPIO_PORT, LD_GREEN_GPIO_PIN);
188 GPIO_LOW(LD_GPIO_PORT, LD_BLUE_GPIO_PIN);