tim.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file tim.c
  5. * @brief This file provides code for the configuration
  6. * of the TIM instances.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2024 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "tim.h"
  22. /* USER CODE BEGIN 0 */
  23. /* USER CODE END 0 */
  24. TIM_HandleTypeDef htim2;
  25. /* TIM2 init function */
  26. void MX_TIM2_Init(void)
  27. {
  28. /* USER CODE BEGIN TIM2_Init 0 */
  29. /* USER CODE END TIM2_Init 0 */
  30. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  31. TIM_MasterConfigTypeDef sMasterConfig = {0};
  32. /* USER CODE BEGIN TIM2_Init 1 */
  33. /* USER CODE END TIM2_Init 1 */
  34. htim2.Instance = TIM2;
  35. htim2.Init.Prescaler = 71;
  36. htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  37. htim2.Init.Period = 3360-1;
  38. htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  39. htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  40. if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  41. {
  42. Error_Handler();
  43. }
  44. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  45. if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  46. {
  47. Error_Handler();
  48. }
  49. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  50. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  51. if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  52. {
  53. Error_Handler();
  54. }
  55. /* USER CODE BEGIN TIM2_Init 2 */
  56. /* USER CODE END TIM2_Init 2 */
  57. }
  58. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
  59. {
  60. if(tim_baseHandle->Instance==TIM2)
  61. {
  62. /* USER CODE BEGIN TIM2_MspInit 0 */
  63. /* USER CODE END TIM2_MspInit 0 */
  64. /* TIM2 clock enable */
  65. __HAL_RCC_TIM2_CLK_ENABLE();
  66. /* TIM2 interrupt Init */
  67. HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0);
  68. HAL_NVIC_EnableIRQ(TIM2_IRQn);
  69. /* USER CODE BEGIN TIM2_MspInit 1 */
  70. /* USER CODE END TIM2_MspInit 1 */
  71. }
  72. }
  73. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
  74. {
  75. if(tim_baseHandle->Instance==TIM2)
  76. {
  77. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  78. /* USER CODE END TIM2_MspDeInit 0 */
  79. /* Peripheral clock disable */
  80. __HAL_RCC_TIM2_CLK_DISABLE();
  81. /* TIM2 interrupt Deinit */
  82. HAL_NVIC_DisableIRQ(TIM2_IRQn);
  83. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  84. /* USER CODE END TIM2_MspDeInit 1 */
  85. }
  86. }
  87. /* USER CODE BEGIN 1 */
  88. /* USER CODE END 1 */