cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H753XIH6, can't get HAL_HRTIM_Compare1EventCallback to trigger, can anyone help me?

J.dW
Associate II

Hi,

For a project I'm working on I need to use the HRTIM timer. This is a

timer I haven't used before and I can’t seem to get the

HAL_HRTIM_Compare1EventCallback to trigger. The ‘normal’

HAL_HRTIM_RepetitionEventCallback works so the timer runs (tested With the

Master Timer and with Timer A running together and only with the Master Timer

Started).

For the test I only set and reset digital IO during the Callback events.

But progam never seems to execute the HAL_HRTIM_Compare1EventCallback.

Can you help me to get the HAL_HRTIM_Compare1EventCallback to work?

Some information about the project:

In this project I need to use the following timers/compares to complete

a certain routine:

·        Master Timer

·        Master Compare 1

·        Master Compare 2

·        Timer A

·        Timer A compare 1

·        Timer B

·        Timer B Compare 1

·        Timer B Compare 2

·        Timer B Compare 3

·        Timer C

·        Timer C compare 1

The master timer and Timer A have to start together, MC1 triggers Timer

B, MC2 Trigger timer C, and the compare functions of the other timers have

different functions like setting or resetting a non-Timeroutput GPIO and other

funtions.

The code in the next post is the HRTIM.C file, generated by CUBEMX. The

compare values in this file are not the values needed over time but are only

set to generate default test code.

The HAL_HRTIM_RepetitionEventCallback triggers every 200ms, and all the

other timer/compare functions have to be handled within that time span.

If you can help me to get the HAL_HRTIM_Compare1EventCallback to work

with let’s say the master timer and Timer A, then I know I can build the

complete code I need. So that would be much appreciated.

I probably forgot a setting or have to change a setting, or…… But as

said, this is the first time I am using the HRTIM in any MCU so I could use

some help. I already read the HRTIM Cookbook but I couldn’t find the

information I needed from that file.

2 REPLIES 2
J.dW
Associate II
/**
  ******************************************************************************
  * File Name          : HRTIM.c
  * Description        : This file provides code for the configuration
  *                      of the HRTIM instances.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
 
/* Includes ------------------------------------------------------------------*/
#include "hrtim.h"
 
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
HRTIM_HandleTypeDef hhrtim;
 
/* HRTIM init function */
void MX_HRTIM_Init(void)
{
  HRTIM_BurstModeCfgTypeDef pBurstModeCfg = {0};
  HRTIM_TimeBaseCfgTypeDef pTimeBaseCfg = {0};
  HRTIM_TimerCfgTypeDef pTimerCfg = {0};
  HRTIM_CompareCfgTypeDef pCompareCfg = {0};
 
  hhrtim.Instance = HRTIM1;
  hhrtim.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
  hhrtim.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
  if (HAL_HRTIM_Init(&hhrtim) != HAL_OK)
  {
    Error_Handler();
  }
  pBurstModeCfg.Mode = HRTIM_BURSTMODE_SINGLESHOT;
  pBurstModeCfg.ClockSource = HRTIM_BURSTMODECLOCKSOURCE_MASTER;
  pBurstModeCfg.Prescaler = HRTIM_BURSTMODEPRESCALER_DIV1;
  pBurstModeCfg.PreloadEnable = HRIM_BURSTMODEPRELOAD_DISABLED;
  pBurstModeCfg.Trigger = HRTIM_BURSTMODETRIGGER_NONE;
  pBurstModeCfg.IdleDuration = 0x0000;
  pBurstModeCfg.Period = 0x0001;
  if (HAL_HRTIM_BurstModeConfig(&hhrtim, &pBurstModeCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pTimeBaseCfg.Period = 0xfffd;
  pTimeBaseCfg.RepetitionCounter = 0x00B6;
  pTimeBaseCfg.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV4;
  pTimeBaseCfg.Mode = HRTIM_MODE_CONTINUOUS;
  if (HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_MASTER, &pTimeBaseCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pTimerCfg.InterruptRequests = HRTIM_MASTER_IT_NONE;
  pTimerCfg.DMARequests = HRTIM_MASTER_DMA_NONE;
  pTimerCfg.DMASrcAddress = 0x0000;
  pTimerCfg.DMADstAddress = 0x0000;
  pTimerCfg.DMASize = 0x1;
  pTimerCfg.HalfModeEnable = HRTIM_HALFMODE_DISABLED;
  pTimerCfg.StartOnSync = HRTIM_SYNCSTART_DISABLED;
  pTimerCfg.ResetOnSync = HRTIM_SYNCRESET_DISABLED;
  pTimerCfg.DACSynchro = HRTIM_DACSYNC_NONE;
  pTimerCfg.PreloadEnable = HRTIM_PRELOAD_DISABLED;
  pTimerCfg.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
  pTimerCfg.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
  pTimerCfg.RepetitionUpdate = HRTIM_UPDATEONREPETITION_DISABLED;
  if (HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_MASTER, &pTimerCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pCompareCfg.CompareValue = 0x0FF1;
  if (HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_MASTER, HRTIM_COMPAREUNIT_1, &pCompareCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pCompareCfg.CompareValue = 0x0AA2;
  if (HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_MASTER, HRTIM_COMPAREUNIT_2, &pCompareCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pTimeBaseCfg.Period = 0xFFFD;
  pTimeBaseCfg.RepetitionCounter = 0xb6;
  if (HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &pTimeBaseCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pTimerCfg.InterruptRequests = HRTIM_TIM_IT_NONE;
  pTimerCfg.DMARequests = HRTIM_TIM_DMA_NONE;
  pTimerCfg.DMASrcAddress = 0x0000;
  pTimerCfg.DMADstAddress = 0x0000;
  pTimerCfg.DMASize = 0x1;
  pTimerCfg.PushPull = HRTIM_TIMPUSHPULLMODE_DISABLED;
  pTimerCfg.FaultEnable = HRTIM_TIMFAULTENABLE_NONE;
  pTimerCfg.FaultLock = HRTIM_TIMFAULTLOCK_READWRITE;
  pTimerCfg.DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_DISABLED;
  pTimerCfg.DelayedProtectionMode = HRTIM_TIMER_A_B_C_DELAYEDPROTECTION_DISABLED;
  pTimerCfg.UpdateTrigger = HRTIM_TIMUPDATETRIGGER_NONE;
  pTimerCfg.ResetTrigger = HRTIM_TIMRESETTRIGGER_NONE;
  pTimerCfg.ResetUpdate = HRTIM_TIMUPDATEONRESET_DISABLED;
  if (HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &pTimerCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pTimerCfg.DMASrcAddress = 0x0000;
  pTimerCfg.DMADstAddress = 0x0000;
  pTimerCfg.DMASize = 0x1;
  if (HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, &pTimerCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pTimerCfg.DMASrcAddress = 0x0000;
  pTimerCfg.DMADstAddress = 0x0000;
  pTimerCfg.DMASize = 0x1;
  if (HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_C, &pTimerCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pCompareCfg.CompareValue = 0xFFF1;
  if (HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, &pCompareCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pCompareCfg.CompareValue = 0xFFFC;
  pCompareCfg.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
  pCompareCfg.AutoDelayedTimeout = 0x0000;
 
  if (HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_2, &pCompareCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pTimeBaseCfg.Period = 0xFFFD;
  pTimeBaseCfg.RepetitionCounter = 0xb6;
  if (HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, &pTimeBaseCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pCompareCfg.CompareValue = 0xFFFA;
  if (HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, &pCompareCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pCompareCfg.CompareValue = 0xFFF3;
  if (HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_3, &pCompareCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pTimeBaseCfg.Period = 0xFFFD;
  pTimeBaseCfg.RepetitionCounter = 0xb6;
  if (HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_C, &pTimeBaseCfg) != HAL_OK)
  {
    Error_Handler();
  }
  pCompareCfg.CompareValue = 0xFFF7;
  if (HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_C, HRTIM_COMPAREUNIT_1, &pCompareCfg) != HAL_OK)
  {
    Error_Handler();
  }
 
}
 
void HAL_HRTIM_MspInit(HRTIM_HandleTypeDef* hrtimHandle)
{
 
  if(hrtimHandle->Instance==HRTIM1)
  {
  /* USER CODE BEGIN HRTIM1_MspInit 0 */
 
  /* USER CODE END HRTIM1_MspInit 0 */
    /* HRTIM1 clock enable */
    __HAL_RCC_HRTIM1_CLK_ENABLE();
 
    /* HRTIM1 interrupt Init */
    HAL_NVIC_SetPriority(HRTIM1_Master_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(HRTIM1_Master_IRQn);
    HAL_NVIC_SetPriority(HRTIM1_TIMA_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(HRTIM1_TIMA_IRQn);
    HAL_NVIC_SetPriority(HRTIM1_TIMB_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(HRTIM1_TIMB_IRQn);
    HAL_NVIC_SetPriority(HRTIM1_TIMC_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(HRTIM1_TIMC_IRQn);
  /* USER CODE BEGIN HRTIM1_MspInit 1 */
 
  /* USER CODE END HRTIM1_MspInit 1 */
  }
}
 
void HAL_HRTIM_MspDeInit(HRTIM_HandleTypeDef* hrtimHandle)
{
 
  if(hrtimHandle->Instance==HRTIM1)
  {
  /* USER CODE BEGIN HRTIM1_MspDeInit 0 */
 
  /* USER CODE END HRTIM1_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_HRTIM1_CLK_DISABLE();
 
    /* HRTIM1 interrupt Deinit */
    HAL_NVIC_DisableIRQ(HRTIM1_Master_IRQn);
    HAL_NVIC_DisableIRQ(HRTIM1_TIMA_IRQn);
    HAL_NVIC_DisableIRQ(HRTIM1_TIMB_IRQn);
    HAL_NVIC_DisableIRQ(HRTIM1_TIMC_IRQn);
  /* USER CODE BEGIN HRTIM1_MspDeInit 1 */
 
  /* USER CODE END HRTIM1_MspDeInit 1 */
  }
} 
 
/* USER CODE BEGIN 1 */
 
/* USER CODE END 1 */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

A main.c Snippet

void HAL_HRTIM_RepetitionEventCallback(HRTIM_HandleTypeDef *hhrtim,  uint32_t TimerIdx)
{
 
	if(TimerIdx == HRTIM_TIMERINDEX_MASTER)
	{
 
	  if(HRTIMPassed == 1)
	  {
		  HRTIMPassed = 0;
		  T_OUT3_GPIO_Port -> BSRR = (uint32_t)T_OUT3_Pin << (16U); // turn off PAM
 
	  }
	  else
	  {
		HRTIMPassed = 1;
		T_OUT3_GPIO_Port -> BSRR = (uint32_t)T_OUT3_Pin; // turn on PAM
	  }
	}
 
	if(TimerIdx == HRTIM_TIMERINDEX_TIMER_A)
	{
		  if(HRTIMCE1Passed == 1)
		  {
			  HRTIMCE1Passed = 0;
			  T_OUT1_GPIO_Port -> BSRR = (uint32_t)T_OUT1_Pin << (16U); // turn off PAM
 
		  }
		  else
		  {
			  HRTIMCE1Passed = 1;
			T_OUT1_GPIO_Port -> BSRR = (uint32_t)T_OUT1_Pin; // turn on PAM
		  }
	}
 
}
 
void HAL_HRTIM_Compare1EventCallback(HRTIM_HandleTypeDef *hhrtim,  uint32_t TimerIdx)
{
 
	  if(HRTIMCE1Passed == 1)
	  {
		  HRTIMCE1Passed = 0;
		  T_OUT1_GPIO_Port -> BSRR = (uint32_t)T_OUT1_Pin << (16U); // turn off PAM
 
	  }
	  else
	  {
		  HRTIMCE1Passed = 1;
		T_OUT1_GPIO_Port -> BSRR = (uint32_t)T_OUT1_Pin; // turn on PAM
	  }
 
}

J.dW
Associate II

Hi,

Does no one have a idea on how to help me a step further?

If you have, please do reply on this post, even if it is just a little nudge in the right direction.

Thank you in advance!