cancel
Showing results for 
Search instead for 
Did you mean: 

TIM6 and TIM7 identical, the interrupt is working for TIM6 and not for TIM7

Beppe101
Associate III

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:tim6.jpgtim7.jpg

Please help, I double checked all I could without finding a solution

 

1 ACCEPTED SOLUTION

Accepted Solutions

You called:

 

HAL_TIM_Base_Start(&htim7);

 

instead of:

 

HAL_TIM_Base_Start_IT(&htim7);

 

So add "_IT"

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

14 REPLIES 14
SofLit
ST Employee

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?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Beppe101
Associate III

Hi,

I disabled TIM6 as suggested, the callback above is only invoked with ( htim == &htim3 ).


@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?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Beppe101
Associate III

tim3.jpgHi,

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.

Could you please keep only TIM6 and TIM7 firing the interrupts just for the test?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Have you enabled the timers' interrupts? I can't see it on the screens you supplied.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
TDK
Guru

Are you starting TIM7?

Not really providing the full picture of the problem. Consider attaching your main.c at the least.

If you feel a post has answered your question, please click "Accept as Solution".
Beppe101
Associate III

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 */
Pavel A.
Evangelist III

Have you added the TIM7 ISR handler in your  stm.....it.c file?