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