2024-02-08 07:43 AM - last edited on 2024-02-08 09:35 AM by SofLit
Hi,
I added TIM7 to application and configured it the same way TIM6 was.
I need to use two timers for my app, code contains all the same setups for TIM6 and TIM7, except for the timer expiration counters, and I observe that the callback
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
never enters in the conditional block it contains:
if ( htim == &htim7 )
{
/* code block */
}
the callback above is invoked when htim == &tim6.
The timers setup are:
Please help, I double checked all I could without finding a solution
Solved! Go to Solution.
2024-02-08 08:53 AM - edited 2024-02-08 09:20 AM
You called:
HAL_TIM_Base_Start(&htim7);
instead of:
HAL_TIM_Base_Start_IT(&htim7);
So add "_IT"
2024-02-08 07:45 AM - edited 2024-02-08 07:52 AM
Hello,
And if you disable TIM6 and keep TIM7, what is the behavior? TIM7 still not working?
Did you check TIM7 counter? is it really counting?
2024-02-08 08:10 AM
Hi,
I disabled TIM6 as suggested, the callback above is only invoked with ( htim == &htim3 ).
2024-02-08 08:15 AM - edited 2024-02-08 08:15 AM
@Beppe101 wrote:
Hi,
I disabled TIM6 as suggested, the callback above is only invoked with ( htim == &htim3 ).
Didn't understand. You are using TIM6 and TIM7. What TIM3 is doing here?
How many timers are you using in the callback?
2024-02-08 08:21 AM - edited 2024-02-08 08:32 AM
Hi,
the app works correctly with timers TIM3, TIM6, TIM14 together. I add TIM7 and TIM7 doesn't work as expected no matter if TIM6 is present or not. TIM14 used for PWM generation does not fire callback above. TIM3 has 2 channels for input capture and it fires the callback that does nothing with TIM3.
2024-02-08 08:41 AM
Could you please keep only TIM6 and TIM7 firing the interrupts just for the test?
2024-02-08 08:41 AM
Have you enabled the timers' interrupts? I can't see it on the screens you supplied.
2024-02-08 08:43 AM
Are you starting TIM7?
Not really providing the full picture of the problem. Consider attaching your main.c at the least.
2024-02-08 08:49 AM
Here is main.c
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 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.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "crc.h"
#include "dma.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/**************************************
* Includes *
**************************************/
#include <stdio.h>
#include <string.h>
#include "Core_interface.h"
#include "AlertsManager_interface.h"
#include "AntennaGainControl_interface.h"
#include "SerialBusManager_interface.h"
#ifdef DEBUG
#include "SerialConsoleManager_interface.h"
#endif /* DEBUG */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/**************************************
* Global variables *
**************************************/
/* ADC1 converted values */
uint32_t adc1Values[ADC1_NUMBER_OF_CHANNELS];
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();
MX_ADC1_Init();
MX_TIM14_Init();
MX_USART1_UART_Init();
MX_CRC_Init();
MX_TIM3_Init();
MX_TIM1_Init();
MX_TIM7_Init();
/* USER CODE BEGIN 2 */
HAL_UART_MspInit(&huart1);
HAL_UART_MspInit(&huart2);
// HAL_TIM_Base_Start_IT(&htim6);
HAL_TIM_Base_Start_IT(&htim3);
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1);
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&htim14, TIM_CHANNEL_1);
HAL_TIM_Base_Start(&htim14);
HAL_TIM_Base_Start(&htim7);
__HAL_RCC_CRC_CLK_ENABLE();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
TIM7->CNT = 0;
TIM7->ARR = 500;
while (1)
{
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
RCC_OscInitStruct.PLL.PLLN = 8;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1) {
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @PAram file: pointer to the source file name
* @PAram line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
2024-02-08 08:50 AM
Have you added the TIM7 ISR handler in your stm.....it.c file?