aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/demos/STM32/NIL-STM32F051-DISCOVERY/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/demos/STM32/NIL-STM32F051-DISCOVERY/main.c')
-rw-r--r--lib/chibios/demos/STM32/NIL-STM32F051-DISCOVERY/main.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/lib/chibios/demos/STM32/NIL-STM32F051-DISCOVERY/main.c b/lib/chibios/demos/STM32/NIL-STM32F051-DISCOVERY/main.c
new file mode 100644
index 000000000..976506f94
--- /dev/null
+++ b/lib/chibios/demos/STM32/NIL-STM32F051-DISCOVERY/main.c
@@ -0,0 +1,113 @@
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 * Thread 1.
24 */
25THD_WORKING_AREA(waThread1, 128);
26THD_FUNCTION(Thread1, arg) {
27
28 (void)arg;
29
30 while (true) {
31 palSetPad(GPIOC, GPIOC_LED4);
32 chThdSleepMilliseconds(500);
33 palClearPad(GPIOC, GPIOC_LED4);
34 chThdSleepMilliseconds(500);
35 }
36}
37
38/*
39 * Thread 2.
40 */
41THD_WORKING_AREA(waThread2, 128);
42THD_FUNCTION(Thread2, arg) {
43
44 (void)arg;
45
46 while (true) {
47 palSetPad(GPIOC, GPIOC_LED3);
48 chThdSleepMilliseconds(250);
49 palClearPad(GPIOC, GPIOC_LED3);
50 chThdSleepMilliseconds(250);
51 }
52}
53
54/*
55 * Thread 3.
56 */
57THD_WORKING_AREA(waThread3, 256);
58THD_FUNCTION(Thread3, arg) {
59
60 (void)arg;
61
62 /*
63 * Activates the serial driver 1 using the driver default configuration.
64 * PA9 and PA10 are routed to USART1.
65 */
66 sdStart(&SD1, NULL);
67 palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1)); /* USART1 TX. */
68 palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(1)); /* USART1 RX. */
69
70 /* Welcome message.*/
71 chnWrite(&SD1, (const uint8_t *)"Hello World!\r\n", 14);
72
73 /* Waiting for button push and activation of the test suite.*/
74 while (true) {
75 if (palReadLine(LINE_BUTTON)) {
76 test_execute((BaseSequentialStream *)&SD1, &nil_test_suite);
77 test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
78 }
79 chThdSleepMilliseconds(500);
80 }
81}
82
83/*
84 * Threads creation table, one entry per thread.
85 */
86THD_TABLE_BEGIN
87 THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL)
88 THD_TABLE_THREAD(1, "blinker2", waThread2, Thread2, NULL)
89 THD_TABLE_THREAD(4, "tester", waThread3, Thread3, NULL)
90THD_TABLE_END
91
92/*
93 * Application entry point.
94 */
95int main(void) {
96
97 /*
98 * System initializations.
99 * - HAL initialization, this also initializes the configured device drivers
100 * and performs the board-specific initializations.
101 * - Kernel initialization, the main() function becomes a thread and the
102 * RTOS is active.
103 */
104 halInit();
105 chSysInit();
106
107 /* This is now the idle thread loop, you may perform here a low priority
108 task but you must never try to sleep or wait in this loop. Note that
109 this tasks runs at the lowest priority level so any instruction added
110 here will be executed after all other tasks have been started.*/
111 while (true) {
112 }
113}