1
0

drv_led.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * File : drv_led.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2015, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-08-25 LongfeiMa the first version for stm32h7xx
  23. */
  24. #include <rtthread.h>
  25. #include <board.h>
  26. #include "drv_led.h"
  27. static void led_thread_entry(void *parameter)
  28. {
  29. while (1)
  30. {
  31. led_on();
  32. rt_thread_delay(RT_TICK_PER_SECOND);
  33. led_off();
  34. rt_thread_delay(RT_TICK_PER_SECOND);
  35. }
  36. }
  37. int led_hw_init(void)
  38. {
  39. GPIO_InitTypeDef GPIO_InitStruct;
  40. /* GPIO Ports Clock Enable */
  41. __HAL_RCC_GPIOB_CLK_ENABLE();
  42. /* Configure GPIO pin: PI1 (LD2) */
  43. GPIO_InitStruct.Pin = GPIO_PIN_14;
  44. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  45. GPIO_InitStruct.Pull = GPIO_NOPULL;
  46. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  47. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  48. return 0;
  49. }
  50. INIT_BOARD_EXPORT(led_hw_init);
  51. int led_init(void)
  52. {
  53. rt_thread_t tid;
  54. tid = rt_thread_create("led",
  55. led_thread_entry, RT_NULL,
  56. 512, 12, 5);
  57. if (tid != RT_NULL)
  58. rt_thread_startup(tid);
  59. return 0;
  60. }
  61. INIT_APP_EXPORT(led_init);