I created a timer with a 5s period. But I want to stop it within less than that period. I tried the below code but it seems xTimerStop() doesn’t work as I expected. I moved it into callback function and it works well.
So how can I fix this problem?
Here my code:
The problem with this code is that the call to vTaskStartScheduler never returns as tasks start running after that point. As a result, xTimerStop is never called.
I see. But I dont know why vTaskStartScheduler never returns. I checked the document and it said " vTaskStartScheduler() will only return if there is insufficient RTOS heap available to create the idle or timer daemon tasks.". But the daemon task is created, because callback function is called.
As documented including commented example code
… vTaskStartScheduler is not like a simple C-library function - it starts the FreeRTOS application !
The comment clearly tells that ONLY IN CASE OF A FATAL PROBLEM (not enough heap memory) vTaskStartScheduler returns and your FreeRTOS application isn’t started at all.
So don’t add code after the vTaskStartScheduler call and simply assume that it’s executed. It’s not ! In the normal case that there is no fatal problem with not enough heap memory.
That should be easy to find out yourself, isn’t it.