freertos.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : freertos.c
  5. * Description : Code for freertos applications
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2024 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "FreeRTOS.h"
  21. #include "task.h"
  22. #include "main.h"
  23. #include "cmsis_os.h"
  24. /* Private includes ----------------------------------------------------------*/
  25. /* USER CODE BEGIN Includes */
  26. #include "event_groups.h"
  27. #include <stdio.h>
  28. #include "iwdg.h"
  29. #define LED_STATE_GPIO_Port GPIOC
  30. #define LED_STATE_Pin GPIO_PIN_13
  31. /* USER CODE END Includes */
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* USER CODE BEGIN PTD */
  34. /* USER CODE END PTD */
  35. /* Private define ------------------------------------------------------------*/
  36. /* USER CODE BEGIN PD */
  37. /* USER CODE END PD */
  38. /* Private macro -------------------------------------------------------------*/
  39. /* USER CODE BEGIN PM */
  40. /* USER CODE END PM */
  41. /* Private variables ---------------------------------------------------------*/
  42. /* USER CODE BEGIN Variables */
  43. /* USER CODE END Variables */
  44. /* Definitions for defaultTask */
  45. osThreadId_t defaultTaskHandle;
  46. const osThreadAttr_t defaultTask_attributes = {
  47. .name = "defaultTask",
  48. .stack_size = 128 * 4,
  49. .priority = (osPriority_t) osPriorityRealtime,
  50. };
  51. /* Private function prototypes -----------------------------------------------*/
  52. /* USER CODE BEGIN FunctionPrototypes */
  53. /* USER CODE END FunctionPrototypes */
  54. void StartDefaultTask(void *argument);
  55. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  56. /**
  57. * @brief FreeRTOS initialization
  58. * @param None
  59. * @retval None
  60. */
  61. void MX_FREERTOS_Init(void) {
  62. /* USER CODE BEGIN Init */
  63. /* USER CODE END Init */
  64. /* USER CODE BEGIN RTOS_MUTEX */
  65. /* add mutexes, ... */
  66. /* USER CODE END RTOS_MUTEX */
  67. /* USER CODE BEGIN RTOS_SEMAPHORES */
  68. /* add semaphores, ... */
  69. /* USER CODE END RTOS_SEMAPHORES */
  70. /* USER CODE BEGIN RTOS_TIMERS */
  71. /* start timers, add new ones, ... */
  72. /* USER CODE END RTOS_TIMERS */
  73. /* USER CODE BEGIN RTOS_QUEUES */
  74. /* add queues, ... */
  75. /* USER CODE END RTOS_QUEUES */
  76. /* Create the thread(s) */
  77. /* creation of defaultTask */
  78. defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
  79. /* USER CODE BEGIN RTOS_THREADS */
  80. /* add threads, ... */
  81. /* USER CODE END RTOS_THREADS */
  82. /* USER CODE BEGIN RTOS_EVENTS */
  83. /* add events, ... */
  84. /* USER CODE END RTOS_EVENTS */
  85. }
  86. /* USER CODE BEGIN Header_StartDefaultTask */
  87. /**
  88. * @brief Function implementing the defaultTask thread.
  89. * @param argument: Not used
  90. * @retval None
  91. */
  92. /* USER CODE END Header_StartDefaultTask */
  93. void StartDefaultTask(void *argument)
  94. {
  95. /* USER CODE BEGIN StartDefaultTask */
  96. /* Infinite loop */
  97. DEBUG_PRINTF("The system starts running.\r\n");
  98. uint8_t iwdg_count = 0;
  99. for (;;)
  100. {
  101. HAL_GPIO_TogglePin(LED_STATE_GPIO_Port, LED_STATE_Pin);
  102. if(iwdg_count >= 10){
  103. HAL_IWDG_Refresh(&hiwdg); // 喂狗
  104. iwdg_count = 0;
  105. // DEBUG_PRINTF("IWDG feeding.\r\n");
  106. }
  107. iwdg_count++;
  108. osDelay(600);
  109. }
  110. /* USER CODE END StartDefaultTask */
  111. }
  112. /* Private application code --------------------------------------------------*/
  113. /* USER CODE BEGIN Application */
  114. /* USER CODE END Application */