comparison examples/c3/burn2.c3 @ 300:158068af716c

yafm
author Windel Bouwman
date Tue, 03 Dec 2013 18:00:22 +0100
parents test/c3examples/burn2.c3@bd2593de3ff8
children b145f8e6050b
comparison
equal deleted inserted replaced
299:674789d9ff37 300:158068af716c
1 /*
2
3 This file blinks a LED on the STM32F4 discovery board.
4
5 the board has 4 leds on PD12, PD13, PD14 and PD15
6
7 */
8
9 module burn2;
10
11 import stm32f4xx;
12
13 function int add(int a, int b)
14 {
15 return a + b;
16 }
17
18 function void init(int pin)
19 {
20 if (pin < 12)
21 {
22 return;
23 }
24
25 if (pin > 15)
26 {
27 return;
28 }
29
30 var stm32f4xx:RCC_Type RCC;
31 RCC = cast<stm32f4xx:RCC_Type>(0x40023800);
32
33 // Enable the clock to port D:
34 RCC->AHB1ENR = RCC->AHB1ENR | (1 << 3);
35 // Memory mapped control registers:
36 var stm32f4xx:GPIO_Type GPIOD;
37 GPIOD = cast<stm32f4xx:GPIO_Type>(0x40020C00);
38
39 // PD13 == output (01)
40 GPIOD->MODER = (1 << (pin << 1));
41 GPIOD->ODR = (1 << pin);
42 }
43
44
45 function void main()
46 {
47 // Vary between 12 and 15:
48 init(13);
49
50 var int a;
51 a = 0
52 while (a < 1000)
53 {
54 a = add(a, 1);
55 }
56
57 while(true) {}
58 }
59