diff options
Diffstat (limited to 'lib/chibios/demos/STM32/NIL-STM32F303-DISCOVERY/main.c')
-rw-r--r-- | lib/chibios/demos/STM32/NIL-STM32F303-DISCOVERY/main.c | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/lib/chibios/demos/STM32/NIL-STM32F303-DISCOVERY/main.c b/lib/chibios/demos/STM32/NIL-STM32F303-DISCOVERY/main.c new file mode 100644 index 000000000..37d81225b --- /dev/null +++ b/lib/chibios/demos/STM32/NIL-STM32F303-DISCOVERY/main.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #include "hal.h" | ||
18 | #include "ch.h" | ||
19 | #include "nil_test_root.h" | ||
20 | #include "oslib_test_root.h" | ||
21 | |||
22 | /* | ||
23 | * Blinker thread #1. | ||
24 | */ | ||
25 | static THD_WORKING_AREA(waThread1, 128); | ||
26 | static THD_FUNCTION(Thread1, arg) { | ||
27 | |||
28 | (void)arg; | ||
29 | |||
30 | while (true) { | ||
31 | palSetPad(GPIOE, GPIOE_LED3_RED); | ||
32 | chThdSleepMilliseconds(125); | ||
33 | palClearPad(GPIOE, GPIOE_LED3_RED); | ||
34 | chThdSleepMilliseconds(125); | ||
35 | palSetPad(GPIOE, GPIOE_LED7_GREEN); | ||
36 | chThdSleepMilliseconds(125); | ||
37 | palClearPad(GPIOE, GPIOE_LED7_GREEN); | ||
38 | chThdSleepMilliseconds(125); | ||
39 | palSetPad(GPIOE, GPIOE_LED10_RED); | ||
40 | chThdSleepMilliseconds(125); | ||
41 | palClearPad(GPIOE, GPIOE_LED10_RED); | ||
42 | chThdSleepMilliseconds(125); | ||
43 | palSetPad(GPIOE, GPIOE_LED6_GREEN); | ||
44 | chThdSleepMilliseconds(125); | ||
45 | palClearPad(GPIOE, GPIOE_LED6_GREEN); | ||
46 | chThdSleepMilliseconds(125); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | /* | ||
51 | * Blinker thread #2. | ||
52 | */ | ||
53 | static THD_WORKING_AREA(waThread2, 128); | ||
54 | static THD_FUNCTION(Thread2, arg) { | ||
55 | |||
56 | (void)arg; | ||
57 | |||
58 | while (true) { | ||
59 | chThdSleepMilliseconds(125); | ||
60 | palSetPad(GPIOE, GPIOE_LED5_ORANGE); | ||
61 | chThdSleepMilliseconds(125); | ||
62 | palClearPad(GPIOE, GPIOE_LED5_ORANGE); | ||
63 | chThdSleepMilliseconds(125); | ||
64 | palSetPad(GPIOE, GPIOE_LED9_BLUE); | ||
65 | chThdSleepMilliseconds(125); | ||
66 | palClearPad(GPIOE, GPIOE_LED9_BLUE); | ||
67 | chThdSleepMilliseconds(125); | ||
68 | palSetPad(GPIOE, GPIOE_LED8_ORANGE); | ||
69 | chThdSleepMilliseconds(125); | ||
70 | palClearPad(GPIOE, GPIOE_LED8_ORANGE); | ||
71 | chThdSleepMilliseconds(125); | ||
72 | palSetPad(GPIOE, GPIOE_LED4_BLUE); | ||
73 | chThdSleepMilliseconds(125); | ||
74 | palClearPad(GPIOE, GPIOE_LED4_BLUE); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | /* | ||
79 | * Tester thread. | ||
80 | */ | ||
81 | THD_WORKING_AREA(waThread3, 256); | ||
82 | THD_FUNCTION(Thread3, arg) { | ||
83 | |||
84 | (void)arg; | ||
85 | |||
86 | /* | ||
87 | * Activates the serial driver 1 using the driver default configuration. | ||
88 | * PA9 and PA10 are routed to USART1. | ||
89 | */ | ||
90 | sdStart(&SD1, NULL); | ||
91 | palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); /* USART1 TX. */ | ||
92 | palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); /* USART1 RX. */ | ||
93 | |||
94 | /* Welcome message.*/ | ||
95 | chnWrite(&SD1, (const uint8_t *)"Hello World!\r\n", 14); | ||
96 | |||
97 | /* Waiting for button push and activation of the test suite.*/ | ||
98 | while (true) { | ||
99 | if (palReadLine(LINE_BUTTON)) { | ||
100 | test_execute((BaseSequentialStream *)&SD1, &nil_test_suite); | ||
101 | test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite); | ||
102 | } | ||
103 | chThdSleepMilliseconds(500); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | /* | ||
108 | * Threads creation table, one entry per thread. | ||
109 | */ | ||
110 | THD_TABLE_BEGIN | ||
111 | THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL) | ||
112 | THD_TABLE_THREAD(1, "blinker2", waThread2, Thread2, NULL) | ||
113 | THD_TABLE_THREAD(4, "tester", waThread3, Thread3, NULL) | ||
114 | THD_TABLE_END | ||
115 | |||
116 | /* | ||
117 | * Application entry point. | ||
118 | */ | ||
119 | int main(void) { | ||
120 | |||
121 | /* | ||
122 | * System initializations. | ||
123 | * - HAL initialization, this also initializes the configured device drivers | ||
124 | * and performs the board-specific initializations. | ||
125 | * - Kernel initialization, the main() function becomes a thread and the | ||
126 | * RTOS is active. | ||
127 | */ | ||
128 | halInit(); | ||
129 | chSysInit(); | ||
130 | |||
131 | /* This is now the idle thread loop, you may perform here a low priority | ||
132 | task but you must never try to sleep or wait in this loop. Note that | ||
133 | this tasks runs at the lowest priority level so any instruction added | ||
134 | here will be executed after all other tasks have been started.*/ | ||
135 | while (true) { | ||
136 | } | ||
137 | } | ||