You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.1 KiB

12 months ago
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32f4xx_hal_timebase_TIM.c
  5. * @brief HAL time base based on the hardware TIM.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2023 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 "gins.h"
  21. #include "stm32f4xx_hal.h"
  22. #include "stm32f4xx_hal_tim.h"
  23. HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
  24. RCC_ClkInitTypeDef clkconfig;
  25. uint32_t uwTimclock = 0U;
  26. uint32_t uwPrescalerValue = 0U;
  27. uint32_t pFLatency;
  28. HAL_StatusTypeDef status;
  29. /* Enable TIM11 clock */
  30. __HAL_RCC_TIM11_CLK_ENABLE();
  31. /* Get clock configuration */
  32. HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
  33. /* Compute TIM11 clock */
  34. uwTimclock = 2 * HAL_RCC_GetPCLK2Freq();
  35. /* Compute the prescaler value to have TIM11 counter clock equal to 1MHz */
  36. uwPrescalerValue = (uint32_t)((uwTimclock / 1000000U) - 1U);
  37. /* Initialize TIM11 */
  38. htim11.Instance = TIM11;
  39. /* Initialize TIMx peripheral as follow:
  40. + Period = [(TIM11CLK/1000) - 1]. to have a (1/1000) s time base.
  41. + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
  42. + ClockDivision = 0
  43. + Counter direction = Up
  44. */
  45. htim11.Init.Period = (1000000U / 1000U) - 1U;
  46. htim11.Init.Prescaler = uwPrescalerValue;
  47. htim11.Init.ClockDivision = 0;
  48. htim11.Init.CounterMode = TIM_COUNTERMODE_UP;
  49. htim11.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  50. status = HAL_TIM_Base_Init(&htim11);
  51. if (status == HAL_OK) {
  52. /* Start the TIM time Base generation in interrupt mode */
  53. status = HAL_TIM_Base_Start_IT(&htim11);
  54. if (status == HAL_OK) {
  55. /* Enable the TIM11 global Interrupt */
  56. HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);
  57. /* Configure the SysTick IRQ priority */
  58. if (TickPriority < (1UL << __NVIC_PRIO_BITS)) {
  59. /* Configure the TIM IRQ priority */
  60. HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn, TickPriority, 0U);
  61. uwTickPrio = TickPriority;
  62. } else {
  63. status = HAL_ERROR;
  64. }
  65. }
  66. }
  67. /* Return function status */
  68. return status;
  69. }
  70. /**
  71. * @brief Suspend Tick increment.
  72. * @note Disable the tick increment by disabling TIM11 update interrupt.
  73. * @param None
  74. * @retval None
  75. */
  76. void HAL_SuspendTick(void) {
  77. /* Disable TIM11 update Interrupt */
  78. __HAL_TIM_DISABLE_IT(&htim11, TIM_IT_UPDATE);
  79. }
  80. /**
  81. * @brief Resume Tick increment.
  82. * @note Enable the tick increment by Enabling TIM11 update interrupt.
  83. * @param None
  84. * @retval None
  85. */
  86. void HAL_ResumeTick(void) {
  87. /* Enable TIM11 Update interrupt */
  88. __HAL_TIM_ENABLE_IT(&htim11, TIM_IT_UPDATE);
  89. }