Behaviour of nested calls to xSemaphoreTake with mutex in same task
If a task has already obtained a mutex will a calling xSemphoreTake on the same mutex in the same task (for example, in a function being called) succeed or fail?
Behaviour of nested calls to xSemaphoreTake with mutex in same task
A standard mutex can only be taken once, so nested calls to attempt to take a standard mutex will fail. This is quite easy for you to test, or determine from the code.
If you want the possibility to obtain the same mutex twice (at once) then you will instead need to create a recursive mutex.
Behaviour of nested calls to xSemaphoreTake with mutex in same task
To be clear, do I need to give that mutex the same number of times I take it?
Behaviour of nested calls to xSemaphoreTake with mutex in same task
If it is a non-recursive mutex, if you already have it, you shouldn’t call take again.
If it is a recursive mutex, you need to give it as many times as you took it.
Note, recursive mutexes use xSemaphoreTakeRecursive/xSemaphoreGiveRecursive instead of the simple xSemaphoreTask and xSemaphoreGive.