🌐
Openstm32
openstm32.org › forumthread3008
OpenSTM32 Community Site | pwm with one shot timer
timer “output compare CHx” mode “inactive on match” “one pulse mode” in CubeMX gives: void MX_TIM2_Init(void) { TIM_MasterConfigTypeDef sMasterConfig; TIM_OC_InitTypeDef sConfigOC; htim2.Instance = TIM2; htim2.Init.Prescaler = 35; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 9999; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; if (HAL_TIM_OC_Init(&htim2) != HAL_OK) { Error_Handler(); } if (HAL_TIM_OnePulse_Init(&htim2, TIM_OPMODE_SINGLE) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MA
🌐
EmbeddedExpertIO
blog.embeddedexpert.io
STM32 Timers Applications: One Pulse Mode – EmbeddedExpertIO
One Pulse Mode (OPM) in STM32 timers is a specialized operating configuration in which the timer generates a single output pulse in response to a defined trigger event and then automatically halts its counter operation. Unlike continuous PWM or periodic output modes, OPM is designed for ...
Discussions

Trying to trigger one-shot timer on TIM1 from TIM2 interrupt not working
I have seen this post and it appears they're trying to do something similar - the main difference is I don't care about the interrupt and I want the pulse to show up on the CH1 output. https://community.st.com/s/question/0D53W00001Pv0W6SAJ/help-with-timer-in-retriggerable-one-pulse-mode More on reddit.com
🌐 r/stm32
4
1
December 20, 2022
stm32 - Timer1 on stm32f4 - Electrical Engineering Stack Exchange
Im giving a try to stm32 after a long time programming on avr, and seems like im struggling with timer. I want to use timer for handling freezes: HAL_TIM_Base_Start_IT(&htim1); while ((GPIOA... More on electronics.stackexchange.com
🌐 electronics.stackexchange.com
microcontroller - Unable to initialize STM32 timer in one pulse mode with ST HAL - Electrical Engineering Stack Exchange
I use an STM32F401C discovery board with STM32F401VCT6 microcontroller and want to set up a timer in one pulse mode, generating an interrupt after elapsed period. The interrupt handler is to toggle... More on electronics.stackexchange.com
🌐 electronics.stackexchange.com
stm32 - STM32F103 simple countdown timer (with no interrupts) - Electrical Engineering Stack Exchange
I'm trying to create a simple countdown timer (without using interrupts) - to use to check for timeout while waiting for an external event to occur. Ideally, I'd like to preload a timer counter wi... More on electronics.stackexchange.com
🌐 electronics.stackexchange.com
People also ask

Can I use FreeRTOS software timers inside an interrupt (ISR)?
No, you cannot directly call osTimerStart() or osTimerStop() from an ISR. These APIs are not ISR-safe. Instead, trigger a task using a semaphore or event flag, and control the timer from that task.
🌐
controllerstech.com
controllerstech.com › home › stm32 tutorials › freertos tutorials › software timers: periodic & one-shot
STM32 FreeRTOS Software Timers: Periodic & One-Shot with CMSIS-OS V2
How many software timers can I create in FreeRTOS?
There is no fixed limit. The number depends on available heap memory and the timer queue length configured in FreeRTOS (configTIMER_QUEUE_LENGTH).
🌐
controllerstech.com
controllerstech.com › home › stm32 tutorials › freertos tutorials › software timers: periodic & one-shot
STM32 FreeRTOS Software Timers: Periodic & One-Shot with CMSIS-OS V2
Is it safe to use printf inside a timer callback?
It is generally safe if you have enabled newlib reentrant support, but it is still not recommended for time-critical systems. printf can be slow and may delay other timer callbacks.
🌐
controllerstech.com
controllerstech.com › home › stm32 tutorials › freertos tutorials › software timers: periodic & one-shot
STM32 FreeRTOS Software Timers: Periodic & One-Shot with CMSIS-OS V2
🌐
ControllersTech®
controllerstech.com › home › stm32 tutorials › freertos tutorials › software timers: periodic & one-shot
STM32 FreeRTOS Software Timers: Periodic & One-Shot with CMSIS-OS V2
Create FreeRTOS software timers on STM32 with CMSIS-OS V2. Covers osTimerNew, osTimerStart, osTimerStop, osTimerIsRunning, periodic callbacks, and one-shot LED timer. Free download.
Published   May 6, 2026
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › how-to-stop-and-then-re-start-one-shot-timer › td-p › 110804
How to stop and then re-start one-shot timer? - STMicroelectronics Community
December 20, 2022 - I suggest you to enable TIM6 interrupts into CubeMX TIM6 NVIC Settings Tab and not at the end of MX_TIM6_Init(), then regenerate the code, because the low level peripheral clock, gpio and interrupt configuration are performed into HAL_TIM_Base_MspInit() function (before one pulse init). Then you should call usual functions to start and stop Timer in non-blocking mode: ... I see HAL_TIM_PeriodElapsedCallback() implementation in your code. But do you have TIM6_IRQHandler() implemented in stm32l4xx_it.c ?
🌐
Reddit
reddit.com › r/stm32 › trying to trigger one-shot timer on tim1 from tim2 interrupt not working
r/stm32 on Reddit: Trying to trigger one-shot timer on TIM1 from TIM2 interrupt not working
December 20, 2022 -

I have setup a system where TIM2 is measuring a frequency, and each time a new frequency measurement is ready I want to start a One Pulse timer on TIM1 with the same frequency and a specific duty cycle. My frequency measurements are working perfectly (tested with mains power and calculated 59.94 Hz)

I have debugged my code and I am setting the ARR and CCRx registers correctly, and I am writing a 1 to the CEN bit to start the counter, but from what I can tell the counter is not starting and I am getting no output pulse on the pin. If anyone can share a tip for what to check or an example of what I'm trying to accomplish that would be appreciated.

🌐
Stm32World
stm32world.com › 2021 › 03 › 23 › how-to-use-a-one-shot-timer-to-create-delay
How to use a one-shot timer to create delay – Stm32World
March 23, 2021 - Just wrote an article about how to use a timer to create a delay. Please check it here: https://stm32world.com/wiki/STM32_LED_Pulse
🌐
HackMD
hackmd.io › @ampheo › how-do-i-use-stm32-timers-for-delay-and-periodic-tasks
How do I use STM32 timers for delay and periodic tasks? - HackMD
August 14, 2025 - **Recipe C — One-shot (precise) delay using output-compare or one-pulse** Goal: fire a single ISR after N microseconds (no busy-wait). ``` // Assume TIM2 ticking at 1 MHz as above void timer_one_shot_start(uint32_t us){ __HAL_TIM_DISABLE_IT(&htim2, TIM_IT_CC1); __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, __HAL_TIM_GET_COUNTER(&htim2) + us); __HAL_TIM_CLEAR_IT(&htim2, TIM_IT_CC1); __HAL_TIM_ENABLE_IT(&htim2, TIM_IT_CC1); // enable compare match IRQ } void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef* htim){ if (htim->Instance == TIM2 && htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1){ // One-shot event fired // do your task...
Find elsewhere
🌐
DeepBlue
deepbluembedded.com › home › blog › stm32 timers tutorial | hardware timers explained
STM32 Timers Explained Tutorial - Timer Modes Examples Interrupts pwm
January 20, 2024 - STM32 Timers Explained Tutorial - Timer Modes Examples Interrupts pwm prescaler. Timers encoder mode, pulse measurement, counter, compare
🌐
STMicroelectronics Community
community.st.com › t5 › stm32cubemx-mcus › starting-one-shot-tim1-and-catching-interrupt-of-count-down › td-p › 145640
Starting one shot TIM1 and catching interrupt of c... - STMicroelectronics Community
December 18, 2022 - Starting one shot TIM1 and catching interrupt of c... ... My idea is, to implement a timer (TIM1 in this case). Given a certain key pressed, I want to fire it up, let it count down causing an interrupt. This are the parameters I gave it in the init procedure. (STM32F103C8T6)
Top answer
1 of 3
4

I don't really like the HAL, so here is how to do what you want by just accessing the timer peripheral directly:

// SETUP STUFF:

// Enable the timer clock. I use the HAL for this
// as it adds the required startup delay. The code
// is pretty simple though.
__HAL_RCC_TIM1_CLK_ENABLE();

// Reset the control register. This gives us the 
// default operation which is counting up with no
// divider.
TIM1->CR1 = 0;

// Set prescaler
TIM1->PSC = 16799;

// Will generate interrupt when this value is reached
TIM1->ARR = 4999;

// The PSC and ARR values are currently in the preload
// registers. To load them into the active registers we
// need an update event. We can do this manually as
// follows (or we could wait for the timer to expire).
TIM1->EGR |= TIM_EGR_UG;

// Timer is now ready to use.

// POLLING OPERATION:

// Next we setup the interrupts. We should first clear
// the update interrupt flag in case it has already been
// set.
TIM1->SR = ~TIM_SR_UIF;

// Then we can enable the update interrupt source
TIM1->DIER |= TIM_DIER_UIE;

// Note: we also need to setup the interrupt channel on
// the NVIC. Once that is done the isr will fire
// when the timer reaches 5000.

// We can now start the timer running...
TIM1->CR1 |= TIM_CR_CEN;

while ((GPIOA->IDR  & GPIO_PIN_3) == 0x08) 
{
    Clk_h
    DWT_Delay(200);
    Clk_l
    DWT_Delay(200);
}

// ...and stop the timer when we're done
TIM1->CR1 &= ~TIM_CR_CEN;

// Note if we want to repeat the polling loop again we should
// issue another TIM1->EGR |= TIM_EGR_UG event as this
// resets the timer to zero.
2 of 3
4

My solution would be almost identical to @Jon's, but I'd start the timer in one-shot mode, to avoid getting a second interrupt when processing the first takes too long. This way, no timer stop function is needed.

void TIM1_Init() {
    // edit: added clock and interrupt enable
    __HAL_RCC_TIM1_CLK_ENABLE();
    NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 0);
    NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn);

    TIM1->PSC = 16799;         // prescaler
    TIM1->EGR = TIM_EGR_UG;    // generate an update event to load the prescaler
    TIM1->ARR = 4999;          // counter limit
    TIM1->SR = 0;              // clear interrupt status after the update event
    TIM1->DIER = TIM_DIER_UIE; // enable interrupt on update (overflow) event
}

void TIM1_Stop() {
    TIM1->CR1 = 0;             // stop timer by clearing CEN (and everything else) in CR1
    TIM1->CNT = 0;             // reset counter, so it will start from 0 at restart
}

void TIM1_Start() {
    TIM1->CR1 = TIM_CR1_CEN    // start the timer
        | TIM_CR1_OPM;         // in one-pulse-mode
}

void TIM1_UP_TIM10_IRQHandler(void) {
    TIM1->SR = 0;
    strcpy(str123,"<<FAIL>>"); // sprintf should not be used in an interrupt handler
    CDC_Transmit_FS((uint8_t*)str123,strlen(str123));
}
🌐
Blogger
arm-stm.blogspot.com › 2015 › 12 › stm32-timer-one-pulse-mode.html
ARM Cortex STM32: STM32 Timer One Pulse Mode
December 27, 2015 - 3. Select the one pulse mode by setting the OPM bit in CR1 register, if only one pulse is to be generated. Otherwise this bit should be reset. Delay = CCRy/(TIMx_CLK/(PSC + 1)) Pulse-Length = (ARR - CCRy)/(TIMx_CLK/(PSC + 1)) For more details on using the timer in this mode, refer to the examples provided in the STM32xx standard peripheral libraries, in the /Project/STM32xx_StdPeriph_Examples/ TIM/OnePulse folder void Init_TIM15(void) { RCC->APB2ENR |= RCC_APB2ENR_TIM15EN; // TIM15 clock enable (Master) TIM15->PSC = PERIOD - 1; TIM15->ARR = LCD_BUFFER_SIZE + PULSE - 1; TIM15->CCR1 = PULSE; //
Top answer
1 of 2
1

I have finally figured out, what was missing in my code.

Apart from HAL_TIM_OnePulse_Start_IT(), also HAL_TIM_Base_Start() has to be called in order to set up the timer operation in one pulse mode.

Now my main function looks like below and the interrupt is fired when after the set time.

int main(void)
{
  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();
  MX_TIM10_Init();

  HAL_TIM_Base_Start(&htim10);
  HAL_TIM_OnePulse_Start_IT(&htim10, TIM_CHANNEL_1);

  while (1)
  {

  }
}
2 of 2
0

You haven't shown us all the code. For example, where is the Timer and GPIO peripherals enabled? And where is the Timer interrupt enabled?

Typically with STM32Cube HAL applications, the functions like HAL_TIM_Base_Init() call another function like HAL_TIM_Base_MspInit(), which you may have to provide an implementation for. The xxx_MspInit() functions are typically implemented in a file called stm32xxxx_hal_msp.c. ST provides a template for this file with the HAL but I believe the expectation is that you will copy the template to your project file and customize it. (I'm not familiar with the STM32CubeMX tool, which might do some of this automatically.)

Typically within HAL_TIM_Base_MspInit() in stm32xxxx_hal_msp.c is where you will enable the timer and the timer interrupt. That code will look something like this:

    // Enable the peripheral clock.
    __HAL_RCC_TIM10_CLK_ENABLE();

    // NVIC configuration for the TIM10 interrupt.
    HAL_NVIC_SetPriority(TIM10_IRQn, 3, 0);
    HAL_NVIC_EnableIRQ(TIM10_IRQn);

Then you also need to provide an implementation for the timer interrupt handler. Typically this is done in a file called stm32xxxx_it.c. This is another file provided as a template with the HAL but you're expected to customize it in your project directory. (And again, STM32CubeMX may do some of this automatically.)

/**
* @brief  This function handles TIM10_IRQHandler interrupt request.
* @param  None
* @retval None
*/
void TIM10_IRQHandler(void)
{
    HAL_TIM_IRQHandler(&htim10);
}

It's HAL_TIM_IRQHandler() which then calls your HAL_TIM_PeriodElapsedCallback() function.

So make sure you've enabled the timer and the timer interrupt in HAL_TIM_Base_MspInit(). Then make sure you've provided an implementation for TIM10_IRQHandler() which calls HAL_TIM_IRQHandler(). Then use the debugger to step through the code. Set breakpoints in HAL_TIM_Base_MspInit() and TIM10_IRQHandler() and HAL_TIM_PeriodElapsedCallback() to figure out what is working and what is not working.

🌐
Embedded Lab
embedded-lab.com › blog › stm32-timers › 8
STM32 Timers | Embedded Lab | Page 8
December 1, 2015 - One pulse mode is a combination of both input capture and output compare modes. In this mode a timer behaves like a monostable multivibrator (A.K.A one shot timer). It will fire a pulse of a given width and then go to idle state.
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › using-tim3-ch1-to-generate-a-delayed-one-shot-pulse › td-p › 495907
Using TIM3_CH1 to generate a delayed one-shot puls... - STMicroelectronics Community
February 1, 2017 - My ideal solution would be to use the 'one pulse mode' but how to trigger that from software? ... Simply set TIMx_CR1.CEN as you would if you would want to run the trigger continuously. The difference is in setting TIMx_CR1.OPM. ... PWM Output on TIM3 Channel 1 Not Working for 4 kHz Buzzer on STM32L476 in STM32 MCUs Embedded software 2024-11-11
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › help-with-timer-in-retriggerable-one-pulse-mode › td-p › 130291
Solved: Help with timer in retriggerable one pulse mode - STMicroelectronics Community
March 10, 2022 - I am using the STM32L4S9AII6 clocked at 120MHz. I am trying to configure a simple (to me it should be simple) retriggerable one pulse mode timer. I was able to configure TIM6 in one-shot mode, but I had the following issues: The timer was not retriggerable MxCube did not allow me to eliminate the ...
🌐
DigiKey
digikey.com › en › maker › projects › getting-started-with-stm32-timers-and-timer-interrupts › d08e6493cefa486fb1e79c43c0b08cc6
Getting Started with STM32 - Timers and Timer Interrupts
Most will be connected to the microcontroller’s main CPU clock (others, like real time clocks, have their own clock sources). A timer will tick (increment by one) each time it receives a clock pulse. In this demo, we will be using an STM32 Nucleo-L476RG, which has a default main clock (HCLK) of 80 MHz.
🌐
EEVblog
eevblog.com › forum › microcontrollers › stm32-one-pulse
STM32 One Pulse
EEVblog Captcha · We have seen a lot of robot like traffic coming from your IP range, please confirm you're not a robot · This security check has been powered by · CrowdSec
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › how-to-use-lptim-timeout-for-a-simple-one-shot-delay › td-p › 83805
How to use LPTIM_TimeOut for a simple one-shot del... - STMicroelectronics Community
April 19, 2023 - Then this generates 2 interrupts : compareMatch and reload, but by adding only HAL_LPTIM_CompareMatchCallback() to handle the timer expire event, it works. The other interrupt (reload) is also firing but it calls an empty HAL_LPTIM_AutoReloadMatchCallback(). I think it could be disabled with some lower level calls, but the available HAL function enables both. ... one of the LPTIM_Timeout examples in STM32CubeL4 package like STM32CubeL4/Projects/NUCLEO-L432KC/Examples/LPTIM/LPTIM_Timeout