diff options
Diffstat (limited to 'lib/chibios/demos/STM32/RT-STM32F303-DISCOVERY/main.c')
-rw-r--r-- | lib/chibios/demos/STM32/RT-STM32F303-DISCOVERY/main.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/lib/chibios/demos/STM32/RT-STM32F303-DISCOVERY/main.c b/lib/chibios/demos/STM32/RT-STM32F303-DISCOVERY/main.c new file mode 100644 index 000000000..81845c921 --- /dev/null +++ b/lib/chibios/demos/STM32/RT-STM32F303-DISCOVERY/main.c | |||
@@ -0,0 +1,105 @@ | |||
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 "ch.h" | ||
18 | #include "hal.h" | ||
19 | #include "rt_test_root.h" | ||
20 | #include "oslib_test_root.h" | ||
21 | |||
22 | /* | ||
23 | * Blinker thread #1. | ||
24 | */ | ||
25 | THD_WORKING_AREA(waThread1, 128); | ||
26 | THD_FUNCTION(Thread1, arg) { | ||
27 | |||
28 | (void)arg; | ||
29 | |||
30 | chRegSetThreadName("blinker 1"); | ||
31 | while (true) { | ||
32 | palToggleLine(LINE_LED3_RED); | ||
33 | chThdSleepMilliseconds(100); | ||
34 | palToggleLine(LINE_LED7_GREEN); | ||
35 | chThdSleepMilliseconds(100); | ||
36 | palToggleLine(LINE_LED10_RED); | ||
37 | chThdSleepMilliseconds(100); | ||
38 | palToggleLine(LINE_LED6_GREEN); | ||
39 | chThdSleepMilliseconds(100); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | /* | ||
44 | * Blinker thread #2. | ||
45 | */ | ||
46 | THD_WORKING_AREA(waThread2, 128); | ||
47 | THD_FUNCTION(Thread2, arg) { | ||
48 | |||
49 | (void)arg; | ||
50 | |||
51 | chRegSetThreadName("blinker 2"); | ||
52 | while (true) { | ||
53 | chThdSleepMilliseconds(50); | ||
54 | palToggleLine(LINE_LED5_ORANGE); | ||
55 | chThdSleepMilliseconds(100); | ||
56 | palToggleLine(LINE_LED9_BLUE); | ||
57 | chThdSleepMilliseconds(100); | ||
58 | palToggleLine(LINE_LED8_ORANGE); | ||
59 | chThdSleepMilliseconds(100); | ||
60 | palToggleLine(LINE_LED4_BLUE); | ||
61 | chThdSleepMilliseconds(50); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * Application entry point. | ||
67 | */ | ||
68 | int main(void) { | ||
69 | |||
70 | /* | ||
71 | * System initializations. | ||
72 | * - HAL initialization, this also initializes the configured device drivers | ||
73 | * and performs the board-specific initializations. | ||
74 | * - Kernel initialization, the main() function becomes a thread and the | ||
75 | * RTOS is active. | ||
76 | */ | ||
77 | halInit(); | ||
78 | chSysInit(); | ||
79 | |||
80 | /* | ||
81 | * Activates the serial driver 1 using the driver default configuration. | ||
82 | */ | ||
83 | sdStart(&SD1, NULL); | ||
84 | palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); /* USART1 TX. */ | ||
85 | palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); /* USART1 RX. */ | ||
86 | |||
87 | /* | ||
88 | * Creates the example threads. | ||
89 | */ | ||
90 | chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+1, Thread1, NULL); | ||
91 | chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO+1, Thread2, NULL); | ||
92 | |||
93 | /* | ||
94 | * Normal main() thread activity, in this demo it does nothing except | ||
95 | * sleeping in a loop and check the button state, when the button is | ||
96 | * pressed the test procedure is launched. | ||
97 | */ | ||
98 | while (true) { | ||
99 | if (palReadPad(GPIOA, GPIOA_BUTTON)) { | ||
100 | test_execute((BaseSequentialStream *)&SD1, &rt_test_suite); | ||
101 | test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite); | ||
102 | } | ||
103 | chThdSleepMilliseconds(500); | ||
104 | } | ||
105 | } | ||