vTaskDeleteOK, vTaskSuspend Causes Hang

Hello: Under what state would a call to vTaskDelete( taskHandle) function good, vs vTaskSuspend (taskHandle), which seems to cause the code to hang when it is called? I used the exact same code before on a STM32F4 controller, and it worked just fine. This STM32L4 has got a few odd quirks to it! Thanks for any suggestion on this issue.

vTaskDeleteOK, vTaskSuspend Causes Hang

Forgot to mention, define vTaskSuspend is set to 1.

vTaskDeleteOK, vTaskSuspend Causes Hang

Ok, found the issue, but does not make much sense. I checked my other FreeRTOSConfig and found it had a fair amount more memory allocation, so I tried adjusting that and it now functions without hanging. Why would that be the case?

vTaskDeleteOK, vTaskSuspend Causes Hang

VTaskDelete will terminate the task and free the memory allocated for the TCB and Stack. vTaskSuspend will just stop the task, so you can call vTaskResume to continue it from where it was stopped (personally, I only use vTaskDelete(0), i.e, delete myself, as knowing when it is safe to delete another task can be tricky, as delete only frees the TCB/Stack and not other resources that the task might have). If you do a vTaskSuspend and then restart the task by creating it again, you will eventually run out of memory. (One question, when it hangs where does it hang? Can you stop it with a debugger to see where it is). There are lots of other program errors that could cause FreeRTOS to hang, but seeing where it is hung is the first step to figuring out what the issue is.

vTaskDeleteOK, vTaskSuspend Causes Hang

Hi Richard, It was hanging after the first call to suspend. As I mentioned, bumping the memory changed the behavior, but, I am doubtful that was the issue. I did not trace it to see where it was breaking. Agreed that it is probably better and safer to use vTaskDelete, and that’s what I changed it to. In this application, starting in one mode resulted in 2 tasks being suspended, or in another mode, one task being suspended. Since the system had to be power-down restarted in either case, it makes sense to use delete over suspend! Thanks!