Skip to main content
Associate II
September 21, 2026
Solved

Timer1 configured but not enabled by CubeMX

I’m just getting started with Cube MX and IDE. (MX: 6.18.1, IDE:2.2.0, Debian Trixie platform)

I have the Nucleo-144 board with STM32F412GTx device. I’ve tried to configure the TIM1 as PWM,and enabled the interrupts in MX. Generated the code, opened in IDE, built and uploaded to the neucleo board with no significant problems. 

However, whilst the timer is configured pretty much as specified in MX, the timer is not enabled, none of the interrupts are enabled and the output is not enabled.

I can see that whilst a motor control program would not want either the timer or the timer output enabled at boot, not having the interrupts enabled seems strange. I managed to enable these by looking up in the reference manual and manually setting the registers in the debug mode, but that does not affect the Flashed code. (Modifying CR1, DIER and CCER registers)

I did find one article describing how to enable the timer, and added that code to the timer init function, but so far I’ve not found the commands to either enable the output(s) or the interrupts. I think that it would be better - particularly for new learners- to have these commands AUTOMATICALLY generated by MX, but commented out, so that they can be easily implemented. Please can someone suggest the appropriate commands for enabling the output & interrupts? like

 

/* USER CODE BEGIN TIM1_Init 2 */

HAL_TIM_Base_Start(&htim1);

/* USER CODE END TIM1_Init 2 */

Thanks.

 

MikeD2Best answer
Associate II
October 8, 2026

Easiest solution is to use LL commands like:

LL_TIM_CC_EnableChannel (TIM1, LL_TIM_CHANNEL_CH1|LL_TIM_CHANNEL_CH1N|LL_TIM_CHANNEL_CH2|LL_TIM_CHANNEL_CH2N|LL_TIM_CHANNEL_CH3|LL_TIM_CHANNEL_CH3N);

LL_TIM_DisableBRK(TIM1);

LL_TIM_EnableCounter(TIM1);

4 replies

Ghofrane GSOURI
ST Technical Moderator
September 22, 2026

Hello ​@MikeD2 

What you see is normal behavior in CubeMX-generated code. CubeMX configures TIM1, but it does not automatically start the timer or enable PWM outputs, because this is left to the application.

To enable PWM output, call for example:

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

or, if interrupts are needed:

HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1);

and for timer update interrupts:

HAL_TIM_Base_Start_IT(&htim1);

Also, there is a good reference example available: TIM_PWMOutput for STM32F412G-DISCO.

Even if it targets the Discovery board and uses TIM4, it shows the correct HAL startup sequence for PWM generation and can be used as inspiration for TIM1 on your board .

THX

Ghofrane

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.
MikeD2Author
Associate II
September 23, 2026

Thank you for your reply.  did find - eventually the HAL programing guide for the chip, which will be useful, but your reply clears up several issues. It might help to have the UM1725 document referenced in the processor & Nucleo board product page documents section.

Further question, is it possible to  OR the channel values to activate more than one output?

•
•
htim: TIM Output Compare handle
Channel: TIM Channel to be disabled This parameter can be one of the following values:
–
–
–
–
TIM_CHANNEL_1: TIM Channel 1 selected
TIM_CHANNEL_2: TIM Channel 2 selected
TIM_CHANNEL_3: TIM Channel 3 selected
TIM_CHANNEL_4: TIM Channel 4 selected

 

e.g TIM_CHANNEL_1 | TIM_CHANNEL_2  etc.?

Explorer II
September 23, 2026

Step into the HAL functions you can see how the implmentation is.

Unluckily, HAL codes did not support multi-channel operation as your request.

But you can easily create an outer function to implement it. Something like:
 

MIKE_StatusTypeDef MIKE_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
{
if (Channel | TIM_CHANNEL_1) {
HAL_TIM_PWM_Start(htim, TIM_CHANNEL_1);
}
if (Channel | TIM_CHANNEL_2) {
HAL_TIM_PWM_Start(htim, TIM_CHANNEL_2);
}
if (Channel | TIM_CHANNEL_3) {
HAL_TIM_PWM_Start(htim, TIM_CHANNEL_3);
}
if (Channel | TIM_CHANNEL_4) {
HAL_TIM_PWM_Start(htim, TIM_CHANNEL_4);
}
}

But unfortunately, 

#define TIM_CHANNEL_1                      0x00000000U                          /*!< Capture/compare channel 1 identifier      */
#define TIM_CHANNEL_2 0x00000004U /*!< Capture/compare channel 2 identifier */
#define TIM_CHANNEL_3 0x00000008U /*!< Capture/compare channel 3 identifier */
#define TIM_CHANNEL_4 0x0000000CU /*!< Capture/compare channel 4 identifier */
#define TIM_CHANNEL_ALL 0x0000003CU /*!< Global Capture/compare channel identifier */

so you have to build your own #defines.

MikeD2AuthorBest answer
Associate II
October 8, 2026

Easiest solution is to use LL commands like:

LL_TIM_CC_EnableChannel (TIM1, LL_TIM_CHANNEL_CH1|LL_TIM_CHANNEL_CH1N|LL_TIM_CHANNEL_CH2|LL_TIM_CHANNEL_CH2N|LL_TIM_CHANNEL_CH3|LL_TIM_CHANNEL_CH3N);

LL_TIM_DisableBRK(TIM1);

LL_TIM_EnableCounter(TIM1);