Skip to main content
Associate
July 9, 2026
Solved

Cubemx2 : IAR toolchain had a problem

  • July 9, 2026
  • 1 reply
  • 44 views

Hi

 

I recently started using CubeMX2 and my board is the Nucleo-C542RC.

 

The issue is: I'm trying to use a timer interrupt, but the IRQ Handler doesn't seem to trigger when using the IAR toolchain. (The timer value itself increases normally when I use 'get Value', so the timer peripheral is working).

 

However, it works perfectly when I use CMake. 

 

Are there any additional settings I should check in the configuration?

 

Here’s my Main and Timer code :

 

 

 

Main :

/**
******************************************************************************
* file : main.c
* brief : Main program body
* Calls target system initialization then loop in main.
******************************************************************************
*
* 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions prototype -----------------------------------------------*/


/**
* brief: The application entry point.
* retval: none but we specify int to comply with C99 standard
*/
int main(void)
{
/** System Init: this code placed in targets folder initializes your system.
* It calls the initialization (and sets the initial configuration) of the peripherals.
* You can use STM32CubeMX to generate and call this code or not in this project.
* It also contains the HAL initialization and the initial clock configuration.
*/
if (mx_system_init() != SYSTEM_OK)
{
return (-1);
}
else
{
/*
* You can start your application code here
*/


if (HAL_TIM_Start_IT(mx_tim2_gethandle()) != HAL_OK)
{

}
while (1) {}
}
} /* end main */

 

 

 

Tim2 :

/**
******************************************************************************
* @file : mx_tim2.c
* @brief : Peripheral initialization
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the mx_stm32c5xx_hal_drivers_license.md file
* in the same directory as the generated code.
* If no mx_stm32c5xx_hal_drivers_license.md file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include "mx_tim2.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions prototype------------------------------------------------*/
/* Exported variables by reference--------------------------------------------*/
static hal_tim_handle_t hTIM2;

/* Exported function definition ----------------------------------------------*/
/******************************************************************************/
/* Exported functions for TIM2 in HAL layer */
/******************************************************************************/
hal_tim_handle_t *mx_tim2_init(void)
{
if (HAL_TIM_Init(&hTIM2, HAL_TIM2) != HAL_OK)
{
return NULL;
}

HAL_RCC_TIM2_EnableClock();

/* Timer configuration to reach the output frequency at 100 Hz */
hal_tim_config_t config;
config.prescaler = 1439;
config.counter_mode = HAL_TIM_COUNTER_UP;
config.period = 0x3E7;
config.repetition_counter = 0;
config.clock_sel.clock_source = HAL_TIM_CLK_INTERNAL;
if (HAL_TIM_SetConfig(&hTIM2, &config) != HAL_OK)
{
return NULL;
}

/* Sampling Clock */
if (HAL_TIM_SetDTSPrescaler(&hTIM2, HAL_TIM_DTS_DIV1) != HAL_OK)
{
return NULL;
}
if (HAL_TIM_SetDTS2Prescaler(&hTIM2, HAL_TIM_DTS2_DIV1) != HAL_OK)
{
return NULL;
}

/* Update Event Management */
if (HAL_TIM_SetUpdateSource(&hTIM2, HAL_TIM_UPDATE_REGULAR) != HAL_OK)
{
return NULL;
}
if (HAL_TIM_EnableUpdateGeneration(&hTIM2) != HAL_OK)
{
return NULL;
}
/* Master Mode Configuration */
/* No GPIO configuration required for TIM2 */
/* Enable the Timer global interrupt */
HAL_CORTEX_NVIC_SetPriority(TIM2_IRQn, HAL_CORTEX_NVIC_PREEMP_PRIORITY_0, HAL_CORTEX_NVIC_SUB_PRIORITY_0);
HAL_CORTEX_NVIC_EnableIRQ(TIM2_IRQn);

return &hTIM2;
}

void mx_tim2_deinit(void)
{
(void)HAL_TIM_DeInit(&hTIM2);

HAL_RCC_TIM2_DisableClock();

HAL_RCC_TIM2_Reset();

/* No GPIO de-initialization required for TIM2 */
/* Disable Timer global interrupt */
HAL_CORTEX_NVIC_DisableIRQ(TIM2_IRQn);
}

hal_tim_handle_t *mx_tim2_gethandle(void)
{
return &hTIM2;
}

/******************************************************************************/
/* TIM2 global interrupt */
/******************************************************************************/
void TIM2_IRQHandler(void)
{
HAL_TIM_IRQHandler(&hTIM2);
}

 

Best answer by ptb

Hi

 

I Solved it

 

 

 

1 reply

ptbAuthorBest answer
Associate
July 16, 2026

Hi

 

I Solved it