cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop and then re-start one-shot timer?

MFolk.1
Senior

I am working on the STM32L4S9AII6 MCU. I have timer 6 configured in 1 shot count up mode. Interrupt is enabled. How do I stop a one-shot timer that is already running? I've tried a bunch of things but no matter what I do I can't get the timer to work again once I've made any sort of attempt to stop it. Once I try to stop the timer it is broken. Below is my code. I have tried using the start/stop APIs provided by ST, but I have long abandoned those as they never seem to work for me. I prefer an answer that involves manually manipulating the timer registers.

0693W00000WLMEFQA5.png 

I manually enable interrupt for timer 6 at the end of the timer 6 init function.

0693W00000WLMFwQAP.png0693W00000WLMGQQA5.png 

0693W00000WLMGfQAP.png 

Thanks,

Marshall

2 REPLIES 2
RomainR.
ST Employee

Hello MFolk.1 (Community Member)

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:

HAL_TIM_OnePulse_Start_IT()

HAL_TIM_OnePulse_Stop_IT()

I see HAL_TIM_PeriodElapsedCallback() implementation in your code.

But do you have TIM6_IRQHandler() implemented in stm32l4xx_it.c ?

Best regards,

Romain

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

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.

I do have the TIM6 ISR enabled within CubeMX (version 6.5.0). I've been using other one-shot timers within this application for a while and have had issues getting these start/stop API calls to work. I've only been able to get them to work as I showed before. I am not ready to update to a later version of CubeMX as this will require many hours of work for me and I'm not convinced it will fix the issue. I haven't had any issues with the timers working this way until now when I need to be able to stop one of them.

CubeMX seems to at least be setting the IRQ handler for TIM6 up correctly as the timer does work, just not after I stop it.

0693W00000WLTAAQA5.png 

Any other ideas?