tim.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. ******************************************************************************
  3. * File Name : TIM.c
  4. * Description : This file provides code for the configuration
  5. * of the TIM instances.
  6. ******************************************************************************
  7. * This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * Copyright (c) 2019 STMicroelectronics International N.V.
  14. * All rights reserved.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted, provided that the following conditions are met:
  18. *
  19. * 1. Redistribution of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * 3. Neither the name of STMicroelectronics nor the names of other
  25. * contributors to this software may be used to endorse or promote products
  26. * derived from this software without specific written permission.
  27. * 4. This software, including modifications and/or derivative works of this
  28. * software, must execute solely and exclusively on microcontroller or
  29. * microprocessor devices manufactured by or for STMicroelectronics.
  30. * 5. Redistribution and use of this software other than as permitted under
  31. * this license is void and will automatically terminate your rights under
  32. * this license.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  35. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  37. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  38. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  39. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  40. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  42. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  45. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. ******************************************************************************
  48. */
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "tim.h"
  51. /* USER CODE BEGIN 0 */
  52. bool Read_Collect485_Flag;
  53. bool StartUpdate_Screen_Flag;
  54. /* USER CODE END 0 */
  55. TIM_HandleTypeDef htim2;
  56. TIM_HandleTypeDef htim6;
  57. /* TIM2 init function */
  58. void MX_TIM2_Init(void)
  59. {
  60. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  61. TIM_MasterConfigTypeDef sMasterConfig = {0};
  62. htim2.Instance = TIM2;
  63. htim2.Init.Prescaler = (108-1);
  64. htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  65. htim2.Init.Period = (1000-1);
  66. htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  67. htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  68. if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  69. {
  70. Error_Handler();
  71. }
  72. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  73. if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  74. {
  75. Error_Handler();
  76. }
  77. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  78. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  79. if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  80. {
  81. Error_Handler();
  82. }
  83. }
  84. /* TIM6 init function */
  85. void MX_TIM6_Init(void)
  86. {
  87. TIM_MasterConfigTypeDef sMasterConfig = {0};
  88. htim6.Instance = TIM6;
  89. htim6.Init.Prescaler = (108-1);
  90. htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  91. htim6.Init.Period = (1000-1);
  92. htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  93. if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  94. {
  95. Error_Handler();
  96. }
  97. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  98. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  99. if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  100. {
  101. Error_Handler();
  102. }
  103. }
  104. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
  105. {
  106. if(tim_baseHandle->Instance==TIM2)
  107. {
  108. /* USER CODE BEGIN TIM2_MspInit 0 */
  109. /* USER CODE END TIM2_MspInit 0 */
  110. /* TIM2 clock enable */
  111. __HAL_RCC_TIM2_CLK_ENABLE();
  112. /* TIM2 interrupt Init */
  113. HAL_NVIC_SetPriority(TIM2_IRQn, 7, 0);
  114. HAL_NVIC_EnableIRQ(TIM2_IRQn);
  115. /* USER CODE BEGIN TIM2_MspInit 1 */
  116. /* USER CODE END TIM2_MspInit 1 */
  117. }
  118. else if(tim_baseHandle->Instance==TIM6)
  119. {
  120. /* USER CODE BEGIN TIM6_MspInit 0 */
  121. /* USER CODE END TIM6_MspInit 0 */
  122. /* TIM6 clock enable */
  123. __HAL_RCC_TIM6_CLK_ENABLE();
  124. /* TIM6 interrupt Init */
  125. HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 7, 0);
  126. HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
  127. /* USER CODE BEGIN TIM6_MspInit 1 */
  128. /* USER CODE END TIM6_MspInit 1 */
  129. }
  130. }
  131. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
  132. {
  133. if(tim_baseHandle->Instance==TIM2)
  134. {
  135. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  136. /* USER CODE END TIM2_MspDeInit 0 */
  137. /* Peripheral clock disable */
  138. __HAL_RCC_TIM2_CLK_DISABLE();
  139. /* TIM2 interrupt Deinit */
  140. HAL_NVIC_DisableIRQ(TIM2_IRQn);
  141. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  142. /* USER CODE END TIM2_MspDeInit 1 */
  143. }
  144. else if(tim_baseHandle->Instance==TIM6)
  145. {
  146. /* USER CODE BEGIN TIM6_MspDeInit 0 */
  147. /* USER CODE END TIM6_MspDeInit 0 */
  148. /* Peripheral clock disable */
  149. __HAL_RCC_TIM6_CLK_DISABLE();
  150. /* TIM6 interrupt Deinit */
  151. HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn);
  152. /* USER CODE BEGIN TIM6_MspDeInit 1 */
  153. /* USER CODE END TIM6_MspDeInit 1 */
  154. }
  155. }
  156. /* USER CODE BEGIN 1 */
  157. /* USER CODE END 1 */
  158. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/