Prusa MINI Firmware overview
stm32f4xx_hal_timebase_tim.c File Reference

HAL time base based on the hardware TIM. More...

#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_tim.h"

Functions

HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
 This function configures the TIM6 as a time base source. The time source is configured to have 1ms time base with a dedicated Tick interrupt priority. More...
 
void HAL_SuspendTick (void)
 Suspend Tick increment. More...
 
void HAL_ResumeTick (void)
 Resume Tick increment. More...
 

Variables

TIM_HandleTypeDef htim6
 

Detailed Description

HAL time base based on the hardware TIM.

This notice applies to any and all portions of this file that are not between comment pairs USER CODE BEGIN and USER CODE END. Other portions of this file, whether inserted by the user or by software development tools are owned by their respective copyright owners.

COPYRIGHT(c) 2019 STMicroelectronics

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ HAL_InitTick()

HAL_StatusTypeDef HAL_InitTick ( uint32_t  TickPriority)

This function configures the TIM6 as a time base source. The time source is configured to have 1ms time base with a dedicated Tick interrupt priority.

Note
This function is called automatically at the beginning of program after reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
Parameters
TickPriorityTick interrupt priority.
Return values
HALstatus
62  {
63  RCC_ClkInitTypeDef clkconfig;
64  uint32_t uwTimclock = 0;
65  uint32_t uwPrescalerValue = 0;
66  uint32_t pFLatency;
67 
68  /*Configure the TIM6 IRQ priority */
69  HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0);
70 
71  /* Enable the TIM6 global Interrupt */
72  HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
73 
74  /* Enable TIM6 clock */
75  __HAL_RCC_TIM6_CLK_ENABLE();
76 
77  /* Get clock configuration */
78  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
79 
80  /* Compute TIM6 clock */
81  uwTimclock = 2 * HAL_RCC_GetPCLK1Freq();
82 
83  /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
84  uwPrescalerValue = (uint32_t)((uwTimclock / 1000000) - 1);
85 
86  /* Initialize TIM6 */
87  htim6.Instance = TIM6;
88 
89  /* Initialize TIMx peripheral as follow:
90  + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
91  + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
92  + ClockDivision = 0
93  + Counter direction = Up
94  */
95  htim6.Init.Period = (1000000 / 1000) - 1;
96  htim6.Init.Prescaler = uwPrescalerValue;
99  if (HAL_TIM_Base_Init(&htim6) == HAL_OK) {
100  /* Start the TIM time Base generation in interrupt mode */
101  return HAL_TIM_Base_Start_IT(&htim6);
102  }
103 
104  /* Return function status */
105  return HAL_ERROR;
106 }
Here is the call graph for this function:

◆ HAL_SuspendTick()

void HAL_SuspendTick ( void  )

Suspend Tick increment.

Note
Disable the tick increment by disabling TIM6 update interrupt.
Parameters
None
Return values
None
114  {
115  /* Disable TIM6 update Interrupt */
117 }

◆ HAL_ResumeTick()

void HAL_ResumeTick ( void  )

Resume Tick increment.

Note
Enable the tick increment by Enabling TIM6 update interrupt.
Parameters
None
Return values
None
125  {
126  /* Enable TIM6 Update interrupt */
128 }

Variable Documentation

◆ htim6

HAL_RCC_GetPCLK1Freq
uint32_t HAL_RCC_GetPCLK1Freq(void)
TIM_Base_InitTypeDef::Period
uint32_t Period
Definition: stm32f4xx_hal_tim.h:71
HAL_TIM_Base_Init
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
HAL_OK
Definition: stm32f4xx_hal_def.h:57
RCC_ClkInitTypeDef
RCC System, AHB and APB busses clock configuration structure definition.
Definition: stm32f4xx_hal_rcc.h:93
HAL_TIM_Base_Start_IT
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
TIM_Base_InitTypeDef::ClockDivision
uint32_t ClockDivision
Definition: stm32f4xx_hal_tim.h:75
__HAL_TIM_ENABLE_IT
#define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__)
Enable the specified TIM interrupt.
Definition: stm32f4xx_hal_tim.h:932
__HAL_TIM_DISABLE_IT
#define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__)
Disable the specified TIM interrupt.
Definition: stm32f4xx_hal_tim.h:949
TIM_Base_InitTypeDef::CounterMode
uint32_t CounterMode
Definition: stm32f4xx_hal_tim.h:68
htim6
TIM_HandleTypeDef htim6
Definition: stm32f4xx_hal_timebase_tim.c:49
HAL_ERROR
Definition: stm32f4xx_hal_def.h:58
TIM_IT_UPDATE
#define TIM_IT_UPDATE
Definition: stm32f4xx_hal_tim.h:491
TIM_COUNTERMODE_UP
#define TIM_COUNTERMODE_UP
Definition: stm32f4xx_hal_tim.h:339
HAL_NVIC_SetPriority
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
TIM_HandleTypeDef::Instance
TIM_TypeDef * Instance
Definition: stm32f4xx_hal_tim.h:289
TIM_Base_InitTypeDef::Prescaler
uint32_t Prescaler
Definition: stm32f4xx_hal_tim.h:65
HAL_NVIC_EnableIRQ
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
TIM_HandleTypeDef::Init
TIM_Base_InitTypeDef Init
Definition: stm32f4xx_hal_tim.h:290
HAL_RCC_GetClockConfig
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)