]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_Keil_STM32Cube/ST_Code/Core/Src/stm32l4xx_hal_timebase_tim.c
Make vSetupTimerInterrupt weak in the RVDS M4 MPU port to give the
[freertos] / FreeRTOS / Demo / CORTEX_MPU_STM32L4_Discovery_Keil_STM32Cube / ST_Code / Core / Src / stm32l4xx_hal_timebase_tim.c
1 /* USER CODE BEGIN Header */\r
2 /**\r
3   ******************************************************************************\r
4   * @file    stm32l4xx_hal_timebase_TIM.c \r
5   * @brief   HAL time base based on the hardware TIM.\r
6   ******************************************************************************\r
7   * @attention\r
8   *\r
9   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.\r
10   * All rights reserved.</center></h2>\r
11   *\r
12   * This software component is licensed by ST under BSD 3-Clause license,\r
13   * the "License"; You may not use this file except in compliance with the\r
14   * License. You may obtain a copy of the License at:\r
15   *                        opensource.org/licenses/BSD-3-Clause\r
16   *\r
17   ******************************************************************************\r
18   */\r
19 /* USER CODE END Header */\r
20 \r
21 /* Includes ------------------------------------------------------------------*/\r
22 #include "stm32l4xx_hal.h"\r
23 #include "stm32l4xx_hal_tim.h"\r
24  \r
25 /* Private typedef -----------------------------------------------------------*/\r
26 /* Private define ------------------------------------------------------------*/\r
27 /* Private macro -------------------------------------------------------------*/\r
28 /* Private variables ---------------------------------------------------------*/\r
29 TIM_HandleTypeDef        htim6; \r
30 /* Private function prototypes -----------------------------------------------*/\r
31 /* Private functions ---------------------------------------------------------*/\r
32 \r
33 /**\r
34   * @brief  This function configures the TIM6 as a time base source. \r
35   *         The time source is configured  to have 1ms time base with a dedicated \r
36   *         Tick interrupt priority. \r
37   * @note   This function is called  automatically at the beginning of program after\r
38   *         reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). \r
39   * @param  TickPriority: Tick interrupt priority.\r
40   * @retval HAL status\r
41   */\r
42 HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)\r
43 {\r
44   RCC_ClkInitTypeDef    clkconfig;\r
45   uint32_t              uwTimclock = 0;\r
46   uint32_t              uwPrescalerValue = 0;\r
47   uint32_t              pFLatency;\r
48   \r
49   /*Configure the TIM6 IRQ priority */\r
50   HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0); \r
51   \r
52   /* Enable the TIM6 global Interrupt */\r
53   HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); \r
54   \r
55   /* Enable TIM6 clock */\r
56   __HAL_RCC_TIM6_CLK_ENABLE();\r
57   \r
58   /* Get clock configuration */\r
59   HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);\r
60   \r
61   /* Compute TIM6 clock */\r
62   uwTimclock = HAL_RCC_GetPCLK1Freq();\r
63    \r
64   /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */\r
65   uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000) - 1);\r
66   \r
67   /* Initialize TIM6 */\r
68   htim6.Instance = TIM6;\r
69   \r
70   /* Initialize TIMx peripheral as follow:\r
71   + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.\r
72   + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.\r
73   + ClockDivision = 0\r
74   + Counter direction = Up\r
75   */\r
76   htim6.Init.Period = (1000000 / 1000) - 1;\r
77   htim6.Init.Prescaler = uwPrescalerValue;\r
78   htim6.Init.ClockDivision = 0;\r
79   htim6.Init.CounterMode = TIM_COUNTERMODE_UP;\r
80   if(HAL_TIM_Base_Init(&htim6) == HAL_OK)\r
81   {\r
82     /* Start the TIM time Base generation in interrupt mode */\r
83     return HAL_TIM_Base_Start_IT(&htim6);\r
84   }\r
85   \r
86   /* Return function status */\r
87   return HAL_ERROR;\r
88 }\r
89 \r
90 /**\r
91   * @brief  Suspend Tick increment.\r
92   * @note   Disable the tick increment by disabling TIM6 update interrupt.\r
93   * @param  None\r
94   * @retval None\r
95   */\r
96 void HAL_SuspendTick(void)\r
97 {\r
98   /* Disable TIM6 update Interrupt */\r
99   __HAL_TIM_DISABLE_IT(&htim6, TIM_IT_UPDATE);                                                  \r
100 }\r
101 \r
102 /**\r
103   * @brief  Resume Tick increment.\r
104   * @note   Enable the tick increment by Enabling TIM6 update interrupt.\r
105   * @param  None\r
106   * @retval None\r
107   */\r
108 void HAL_ResumeTick(void)\r
109 {\r
110   /* Enable TIM6 Update interrupt */\r
111   __HAL_TIM_ENABLE_IT(&htim6, TIM_IT_UPDATE);\r
112 }\r
113 \r
114 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r