aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c')
-rw-r--r--lib/chibios/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/chibios/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c b/lib/chibios/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c
new file mode 100644
index 000000000..aa237fb26
--- /dev/null
+++ b/lib/chibios/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c
@@ -0,0 +1,74 @@
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 "cmsis_os.h"
19
20/*
21 * This is a periodic thread that does absolutely nothing except flashing
22 * a LED.
23 */
24static void Thread1(void const *arg) {
25
26 (void)arg;
27
28 while (true) {
29 palSetPad(GPIOD, GPIOD_LED3); /* Orange. */
30 osDelay(500);
31 palClearPad(GPIOD, GPIOD_LED3); /* Orange. */
32 osDelay(500);
33 }
34}
35
36/*
37 * Thread definition block.
38 */
39osThreadDef(Thread1, osPriorityAboveNormal, 128, "blinker");
40
41/*
42 * Application entry point.
43 */
44int main(void) {
45
46 /* HAL initialization, this also initializes the configured device drivers
47 and performs the board-specific initializations.*/
48 halInit();
49
50 /* The kernel is initialized but not started yet, this means that
51 main() is executing with absolute priority but interrupts are
52 already enabled.*/
53 osKernelInitialize();
54
55 /* Activates the serial driver 2 using the driver default configuration.
56 PA2(TX) and PA3(RX) are routed to USART2.*/
57 sdStart(&SD2, NULL);
58 palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
59 palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
60
61 /* Creates the example thread, it does not start immediately.*/
62 osThreadCreate(osThread(Thread1), NULL);
63
64 /* Kernel started, the main() thread has priority osPriorityNormal
65 by default.*/
66 osKernelStart();
67
68 /* In the ChibiOS/RT CMSIS RTOS implementation the main() is an
69 usable thread, here we just sleep in a loop printing a message.*/
70 while (true) {
71 sdWrite(&SD2, (uint8_t *)"Hello World!\r\n", 14);
72 osDelay(500);
73 }
74}