Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
stm32h7xx_hal_timebase_tim.c File Reference

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

#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_tim.h"
Include dependency graph for stm32h7xx_hal_timebase_tim.c:

Go to the source code of this file.

Functions

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

Variables

TIM_HandleTypeDef htim4
 

Detailed Description

HAL time base based on the hardware TIM.

Attention

Copyright (c) 2025 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

Definition in file stm32h7xx_hal_timebase_tim.c.

Function Documentation

◆ HAL_InitTick()

HAL_StatusTypeDef HAL_InitTick ( uint32_t  TickPriority)

This function configures the TIM4 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

Definition at line 41 of file stm32h7xx_hal_timebase_tim.c.

42{
43 RCC_ClkInitTypeDef clkconfig;
44 uint32_t uwTimclock, uwAPB1Prescaler;
45 uint32_t uwPrescalerValue;
46 uint32_t pFLatency;
47
48 /*Configure the TIM4 IRQ priority */
49 if (TickPriority < (1UL << __NVIC_PRIO_BITS))
50 {
51 HAL_NVIC_SetPriority(TIM4_IRQn, TickPriority ,0);
52
53 /* Enable the TIM4 global Interrupt */
54 HAL_NVIC_EnableIRQ(TIM4_IRQn);
55 uwTickPrio = TickPriority;
56 }
57 else
58 {
59 return HAL_ERROR;
60 }
61
62 /* Enable TIM4 clock */
63 __HAL_RCC_TIM4_CLK_ENABLE();
64
65 /* Get clock configuration */
66 HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
67
68 /* Get APB1 prescaler */
69 uwAPB1Prescaler = clkconfig.APB1CLKDivider;
70 /* Compute TIM4 clock */
71 if (uwAPB1Prescaler == RCC_HCLK_DIV1)
72 {
73 uwTimclock = HAL_RCC_GetPCLK1Freq();
74 }
75 else
76 {
77 uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
78 }
79
80 /* Compute the prescaler value to have TIM4 counter clock equal to 1MHz */
81 uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
82
83 /* Initialize TIM4 */
84 htim4.Instance = TIM4;
85
86 /* Initialize TIMx peripheral as follow:
87 * Period = [(TIM4CLK/1000) - 1]. to have a (1/1000) s time base.
88 * Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
89 * ClockDivision = 0
90 * Counter direction = Up
91 */
92 htim4.Init.Period = (1000000U / 1000U) - 1U;
93 htim4.Init.Prescaler = uwPrescalerValue;
94 htim4.Init.ClockDivision = 0;
95 htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
96
97 if(HAL_TIM_Base_Init(&htim4) == HAL_OK)
98 {
99 /* Start the TIM time Base generation in interrupt mode */
100 return HAL_TIM_Base_Start_IT(&htim4);
101 }
102
103 /* Return function status */
104 return HAL_ERROR;
105}
TIM_HandleTypeDef htim4
@ HAL_ERROR
@ HAL_OK

References HAL_ERROR, HAL_OK, and htim4.

◆ HAL_ResumeTick()

void HAL_ResumeTick ( void  )

Resume Tick increment.

Note
Enable the tick increment by Enabling TIM4 update interrupt.
Parameters
None
Return values
None

Definition at line 125 of file stm32h7xx_hal_timebase_tim.c.

126{
127 /* Enable TIM4 Update interrupt */
128 __HAL_TIM_ENABLE_IT(&htim4, TIM_IT_UPDATE);
129}

References htim4.

◆ HAL_SuspendTick()

void HAL_SuspendTick ( void  )

Suspend Tick increment.

Note
Disable the tick increment by disabling TIM4 update interrupt.
Parameters
None
Return values
None

Definition at line 113 of file stm32h7xx_hal_timebase_tim.c.

114{
115 /* Disable TIM4 update Interrupt */
116 __HAL_TIM_DISABLE_IT(&htim4, TIM_IT_UPDATE);
117}

References htim4.

Variable Documentation

◆ htim4

TIM_HandleTypeDef htim4