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