main.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include "hal.h"
  14. #include "cmsis_os.h"
  15. /*
  16. * This is a periodic thread that does absolutely nothing except flashing
  17. * a LED.
  18. */
  19. static void Thread1(void const *arg) {
  20. (void)arg;
  21. while (true) {
  22. palSetPad(GPIOD, GPIOD_LED3); /* Orange. */
  23. osDelay(500);
  24. palClearPad(GPIOD, GPIOD_LED3); /* Orange. */
  25. osDelay(500);
  26. }
  27. }
  28. /*
  29. * Thread definition block.
  30. */
  31. osThreadDef(Thread1, osPriorityAboveNormal, 128, "blinker");
  32. /*
  33. * Application entry point.
  34. */
  35. int main(void) {
  36. /* HAL initialization, this also initializes the configured device drivers
  37. and performs the board-specific initializations.*/
  38. halInit();
  39. /* The kernel is initialized but not started yet, this means that
  40. main() is executing with absolute priority but interrupts are
  41. already enabled.*/
  42. osKernelInitialize();
  43. /* Activates the serial driver 2 using the driver default configuration.
  44. PA2(TX) and PA3(RX) are routed to USART2.*/
  45. sdStart(&SD2, NULL);
  46. palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
  47. palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
  48. /* Creates the example thread, it does not start immediately.*/
  49. osThreadCreate(osThread(Thread1), NULL);
  50. /* Kernel started, the main() thread has priority osPriorityNormal
  51. by default.*/
  52. osKernelStart();
  53. /* In the ChibiOS/RT CMSIS RTOS implementation the main() is an
  54. usable thread, here we just sleep in a loop printing a message.*/
  55. while (true) {
  56. sdWrite(&SD2, (uint8_t *)"Hello World!\r\n", 14);
  57. osDelay(500);
  58. }
  59. }