Hi,
I'm developping on an Arduino OPTA (STM32H74x) Portenta H7 and I want to use the high-resolution timer for driving some interrupts-based actions, actually using only the master hr-timer (no output).
Problem: The code doesn't want to fire any interrupts aka the HRTIM_MASTER_IT_MREP or the HRTIM_MASTER_IT_MUPD.
I used STM32CubeMX freshly downloaded for generating the code body.
HAL and STM32 Driver are already installed into the Arduino IDE, so the code compile without problems.
Anyone could suggest me some clues, please ?
Documents and ressources:
AN4539 - Application note - HRTIM cookbook - https://www.st.com/resource/en/application_note/an4539-hrtim-cookbook-stmicroelectronics.pdf
The code is attached below:
#include <Arduino.h>
#define HAL_MODULE_ENABLED
#define HAL_HRTIM_MODULE_ENABLED
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
HRTIM_HandleTypeDef hhrtim = {0};
HRTIM_TimeBaseCfgTypeDef hrTimeBaseCfg = {0};
HRTIM_TimerCfgTypeDef hrTimerCfg = {0};
volatile bool doIt = false;
volatile uint32_t counter = 0;
void Error_Handler(void) {
Serial.println("Erreur HAL");
while(1) {
// Error Loop
}
}
// Callback pour l'interruption HRTIM1
void HAL_HRTIM_RepetitionEventCallback(HRTIM_HandleTypeDef *hhrtim, uint32_t TimerIdx) {
// Code de traitement de l'interruption
if( TimerIdx == HRTIM_TIMERINDEX_MASTER )
digitalWrite(LEDB, !digitalRead(LEDB) ); // Allume la LED pour montrer que l'Opta est en fonctionnement
}
void setup() {
Serial.begin( 115200 );
while( !Serial ) {}
Serial.println("Starting......");
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
//--- Init HAL & System Clock ------------------------------------------------------------//
Serial.println("Starting HAL......");
HAL_Init();
SystemClock_Config();
//--- Init HR_Timer ----------------------------------------------------------------------//
Serial.println("Starting Init HRTimer......");
hhrtim.Instance = HRTIM1;
hhrtim.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
hhrtim.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
if( HAL_HRTIM_Init(&hhrtim) != HAL_OK )
{
Error_Handler();
}
//--- Config HR_Timer Basetime Period and Repetition -------------------------------------//
Serial.println("Starting TimeBaseConfig......");
hrTimeBaseCfg.Period = 64000;
hrTimeBaseCfg.RepetitionCounter = 16;
hrTimeBaseCfg.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV1;
hrTimeBaseCfg.Mode = HRTIM_MODE_CONTINUOUS;
if( HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_MASTER, &hrTimeBaseCfg) != HAL_OK )
{
Error_Handler();
}
//--- Config HR_Timer Master Timer Config -----------------------------------------------//
Serial.println("Starting WaveForm Timer Config......");
hrTimerCfg.InterruptRequests = HRTIM_MASTER_IT_MREP|HRTIM_MASTER_IT_MUPD;
hrTimerCfg.DMARequests = HRTIM_MASTER_DMA_NONE;
hrTimerCfg.DMASrcAddress = 0x0000;
hrTimerCfg.DMADstAddress = 0x0000;
hrTimerCfg.DMASize = 0x1;
hrTimerCfg.HalfModeEnable = HRTIM_HALFMODE_DISABLED;
hrTimerCfg.StartOnSync = HRTIM_SYNCSTART_DISABLED;
hrTimerCfg.ResetOnSync = HRTIM_SYNCRESET_DISABLED;
hrTimerCfg.DACSynchro = HRTIM_DACSYNC_NONE;
hrTimerCfg.PreloadEnable = HRTIM_PRELOAD_DISABLED;
hrTimerCfg.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
hrTimerCfg.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
hrTimerCfg.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED;
if( HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_MASTER, &hrTimerCfg) != HAL_OK )
{
Error_Handler();
}
/* HRTIM1 interrupt Init */
HAL_NVIC_SetPriority(HRTIM1_Master_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(HRTIM1_Master_IRQn);
/*--- Start HRTIM counter -----------------------------------------------------------------------------------------*/
Serial.println("Starting HRTimer Counter.......");
if( HAL_HRTIM_WaveformCountStart_IT(&hhrtim, HRTIM_TIMERINDEX_MASTER ) != HAL_OK )
{
Error_Handler();
}
}
// Fonction d'interruption HRTIM IRQ Master
void HRTIM1_Master_IRQHandler(void) {
HAL_HRTIM_IRQHandler(&hhrtim, HRTIM_TIMERINDEX_MASTER);
digitalWrite(LEDG, !digitalRead(LEDG) ); // Allume la LED pour montrer que l'Opta est en fonctionnement
counter++;
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** 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_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
Serial.println("RCC Oscillator init config");
int res = HAL_RCC_OscConfig(&RCC_OscInitStruct);
if( res != HAL_OK )
{
Serial.println(res);
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
Serial.println("Bus Clock config");
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
void loop() {
// Code de la boucle principale
delay(4000);
Serial.print("Loop......"); Serial.println(counter);
}
Thx