main.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. ChibiOS - Copyright (C) 2016..2018 Theodore Ateba
  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 "ch.h"
  14. #include "hal.h"
  15. /**
  16. * @brief USARTC0 configuration structure.
  17. */
  18. const UARTConfig usart1cfg = {
  19. NULL, /* Transmission buffer callback. */
  20. NULL, /* End of physical transmission callback. */
  21. NULL, /* Received buffer filled callback. */
  22. NULL, /* Caractere received while output. */
  23. NULL, /* Received error callback. */
  24. 115200, /* Usart baud rate. */
  25. false, /* Double transmission speed. */
  26. false, /* Multiprocessor communication mode bit. */
  27. false, /* Transmission bit 8. */
  28. USART_CMODE_ASYNCHRONOUS, /* Communication mode. */
  29. USART_PMODE_DISABLE, /* Parity mode. */
  30. false, /* False=1bit stop, true=2bit stop. */
  31. USART_CHSIZE_8BIT, /* Caractere size. */
  32. };
  33. static THD_WORKING_AREA(waThread1, 32);
  34. static THD_FUNCTION(Thread1, arg) {
  35. (void)arg;
  36. chRegSetThreadName("Blinker");
  37. while (true) {
  38. palClearPad(IOPORT5, PORTE_LED);
  39. chThdSleepMilliseconds(2000);
  40. palSetPad(IOPORT5, PORTE_LED);
  41. chThdSleepMilliseconds(50);
  42. }
  43. }
  44. /*
  45. * Application entry point.
  46. */
  47. int main(void) {
  48. /*
  49. * System initializations.
  50. * - HAL initialization, this also initializes the configured device drivers
  51. * and performs the board-specific initializations.
  52. * - Kernel initialization, the main() function becomes a thread and the
  53. * RTOS is active.
  54. */
  55. halInit();
  56. chSysInit();
  57. /*
  58. * Set the TX and the RX pin to use the USARTC0 module.
  59. * PIN3 (TXD0) as output for USARTC0.
  60. * PIN2 (RXD0) as input for USARTC0.
  61. */
  62. palSetPadMode(IOPORT3, PIN3, PAL_MODE_OUTPUT_PUSHPULL);
  63. palSetPadMode(IOPORT3, PIN2, PAL_MODE_INPUT_PULLUP);
  64. /* Start the USART1 (USARTC0). */
  65. uartStart(&USART1D, &usart1cfg);
  66. /*
  67. * Starts the LED blinker thread.
  68. */
  69. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  70. while (TRUE) {
  71. uartStartSend(&USART1D,14, (const uint8_t *)"Hello world!\r\n");
  72. chThdSleepMilliseconds(2000);
  73. }
  74. }