[mv] blink source into example/blink
[fw/stlink] / example / blink / main.c
1 /* missing type */
2
3 typedef unsigned int uint32_t;
4
5
6 /* boot mode configuration */
7
8 #define CONFIG_BOOT_SRAM 1
9 #define CONFIG_BOOT_FLASH 0
10
11
12 /* hardware configuration */
13
14 #define CONFIG_STM32L_DISCOVERY 1
15 #define CONFIG_STM32VL_DISCOVERY 0
16
17
18 #if CONFIG_STM32VL_DISCOVERY
19
20 # define GPIOC 0x40011000 /* port C */
21 # define GPIOC_CRH (GPIOC + 0x04) /* port configuration register high */
22 # define GPIOC_ODR (GPIOC + 0x0c) /* port output data register */
23
24 # define LED_BLUE (1 << 8) /* port C, pin 8 */
25 # define LED_GREEN (1 << 9) /* port C, pin 9 */
26
27 static inline void setup_leds(void)
28 {
29   *(volatile uint32_t*)GPIOC_CRH = 0x44444411;
30 }
31
32 static inline void switch_leds_on(void)
33 {
34   *(volatile uint32_t*)GPIOC_ODR = LED_BLUE | LED_GREEN;
35 }
36
37 static inline void switch_leds_off(void)
38 {
39   *(volatile uint32_t*)GPIOC_ODR = 0;
40 }
41
42 #elif CONFIG_STM32L_DISCOVERY
43
44 # define GPIOB 0x40020400 /* port B */
45 # define GPIOB_MODER (GPIOB + 0x00) /* port mode register */
46 # define GPIOB_ODR (GPIOB + 0x14) /* port output data register */
47
48 # define LED_BLUE (1 << 6) /* port B, pin 6 */
49 # define LED_GREEN (1 << 7) /* port B, pin 7 */
50
51 static inline void setup_leds(void)
52 {
53   /* configure port 6 and 7 as output */
54   *(volatile uint32_t*)GPIOB_MODER |= (1 << (7 * 2)) | (1 << (6 * 2));
55 }
56
57 static inline void switch_leds_on(void)
58 {
59   *(volatile uint32_t*)GPIOB_ODR = LED_BLUE | LED_GREEN;
60 }
61
62 static inline void switch_leds_off(void)
63 {
64   *(volatile uint32_t*)GPIOB_ODR = 0;
65 }
66
67 #endif /* otherwise, error */
68
69
70 #define delay()                                         \
71 do {                                                    \
72   register unsigned int i;                              \
73   for (i = 0; i < 1000000; ++i)                         \
74     __asm__ __volatile__ ("nop\n\t":::"memory");        \
75 } while (0)
76
77 static void __attribute__((naked)) __attribute__((used)) main(void)
78 {
79   setup_leds();
80
81   while (1)
82   {
83     switch_leds_on();
84     delay();
85     switch_leds_off();
86     delay();
87   }
88 }