Skip to main content
Visitor II
November 13, 2025
Question

STM32N6 timer One Pulse Mode with external trigger

  • November 13, 2025
  • 1 reply
  • 189 views

Hello

I have custom board with STM32N657. I have set timer 2 to output PWM pulse on channel3 and output compare pulse on channel 1 as trigger to another timer. The timer starts when external trigger - TIMER4_ETR (mapped to timer 2) detects rising edge. All works good, there are continuous pulses as expected.

I want timer2 to run once per trigger so enabling One Pulse Mode. 

static void MX_TIM2_Init(void)
{

 /* USER CODE BEGIN TIM2_Init 0 */

 /* USER CODE END TIM2_Init 0 */

 TIM_ClockConfigTypeDef sClockSourceConfig = {0};
 TIM_SlaveConfigTypeDef sSlaveConfig = {0};
 TIM_MasterConfigTypeDef sMasterConfig = {0};
 TIM_OC_InitTypeDef sConfigOC = {0};

 /* USER CODE BEGIN TIM2_Init 1 */

 /* USER CODE END TIM2_Init 1 */
 htim2.Instance = TIM2;
 htim2.Init.Prescaler = TIM2_PRESCALER;
 htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
 htim2.Init.Period = TIM2_PERIOD;
 htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
 if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
 {
 Error_Handler();
 }
 sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
 if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
 {
 Error_Handler();
 }
// if (HAL_TIM_OC_Init(&htim2) != HAL_OK)
// {
// Error_Handler();
// }
// if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
// {
// Error_Handler();
// }
 if (HAL_TIM_OnePulse_Init(&htim2, TIM_OPMODE_SINGLE) != HAL_OK)
 {
 Error_Handler();
 }
 sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
 sSlaveConfig.InputTrigger = TIM_TS_ETRF;
 sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_NONINVERTED;
 sSlaveConfig.TriggerPrescaler = TIM_TRIGGERPRESCALER_DIV1;
 sSlaveConfig.TriggerFilter = 0;
 if (HAL_TIM_SlaveConfigSynchro(&htim2, &sSlaveConfig) != HAL_OK)
 {
 Error_Handler();
 }
 HAL_TIMEx_RemapConfig(&htim2, TIM_TIM2_ETR_TIM4_ETR);
 sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC1;
 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
 if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
 {
 Error_Handler();
 }

 sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
 sConfigOC.Pulse = TIM2_PULSE_CH1;
 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
 if (HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
 {
 Error_Handler();
 }
 __HAL_TIM_ENABLE_OCxPRELOAD(&htim2, TIM_CHANNEL_1);
 sConfigOC.OCMode = TIM_OCMODE_PWM1;
 sConfigOC.Pulse = TIM2_PULSE_CH3;
 sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
 if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN TIM2_Init 2 */

 TIM_CCxChannelCmd(htim2.Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
 TIM_CCxChannelCmd(htim2.Instance, TIM_CHANNEL_3, TIM_CCx_ENABLE);

 /* USER CODE END TIM2_Init 2 */
 HAL_TIM_MspPostInit(&htim2);

}

//Then in main
HAL_TIM_Base_Start_IT(&htim2);

The above code configures timer2 to OPM mode but no output pules are generated when triggered.
When clearing OPM bit, TIM2->CR1 &= ~TIM_CR1_OPM, and starting timer with external trigger then output channels generate pulses again so configuration seems to be correct in non-OPM mode.

Any suggestion where might be a problem?

Examples show how to configure OPM with TIxFPx trigger but non with external trigger.

    This topic has been closed for replies.

    1 reply

    ST Employee
    November 19, 2025

    Hello,

    did you check that he following condition is met (refer to RN0486, section:50.3.22)

    FrancoisVILMAIN_0-1763564722031.png