maximum number of Mutex

fadillrezha wrote on Monday, February 03, 2014:

Hi all,

I’m sorry for this trivial question. I am using STM32f407 with STM32 standard peripheral drivers and Keil as development environment.I am currently having a weird problem related to mutex.

I am working based on FreeRTOS and LwIP project provided by ST in
http://www.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1743/PF257896?s_searchtype=keyword.

At first I didn’t have any problem, but when I need to add mutexes I found a problem where it seems like there are limit to number of mutex that I can create.

I simply create a mutex, both recursive (xSemaphoreCreateRecursiveMutex)and not(xSemaphoreCreateMutex), and when the number of mutex created is more than a certain number, my code behaves unexpectedly although the mutex is not used anywhere yet. But when I deleted the creation line of one of the mutexes, my code works well. So if I want to make a new mutex after I reach mutex threshold number, I have to delete another mutex, and I conclude that there is a maximum number of mutex that I can create, although I am not sure yet.

I have researched for similar case like mine but can’t seem to find one on the internet. If anyone here can confirm about this problem I would really appreciate it. And I wonder what is the physical resource on STM32F/cortex m-4 that is used when a mutex is created?

Thanks.

richard_damon wrote on Monday, February 03, 2014:

Sounds like you are running out of heap memory to create the mutexs. Are you checking the handle to make sure it isn’t zero? There is a hook you can define to call a function when you get a heap allocation error which is good for debugging.

fadillrezha wrote on Monday, February 03, 2014:

You are right! This is the answer that I’ve been looking for. I failed to recognize the fact that RTOS kernel allocates RAM each time a task, queue, mutex, software timer or semaphore is created.

I simply had to increase the configTOTAL_HEAP_SIZE to solve this problem.

Regards.