Facing problem with Mutex

Hi all,

I am using ARM-CortexM7 and FreeRTOSv10.3.1.

I implemented mutex, but it is not working. Please see the code.

int main() {

	initializeSystem();

	LogDebugInt("----- Hello World -----\r\n", 5);
	LogDebugInt("CPU Clock %dMHz\r\n", bsp_getCPUClock()/1000000);
	LogDebugInt("Peripheral Clock %dMHz\r\n", bsp_getMasterClock()/1000000);

	m_handle = xSemaphoreCreateMutex();

	if(m_handle != NULL){
		xTaskCreate(task1, "TASK-1", configMINIMAL_STACK_SIZE, NULL, 2, &t_handle1);
		xTaskCreate(task2, "TASK-2", configMINIMAL_STACK_SIZE, NULL, 1, &t_handle2);
		vTaskStartScheduler();

	} else {
		LogDebugInt("Failed to create Mutex.\r\n", 0);
	}
}
void task1(void *param){
 for(;;){
	 if(xSemaphoreTake(m_handle, ( TickType_t ) 10)){

		 LogDebugInt("Demo Task(T1): Printing by Task-1\r\n", 0);
		 xSemaphoreGive(m_handle);
	 }
	 vTaskDelay(pdMS_TO_TICKS(200));
 }
}

void task2(void *param){
 for(;;){
	 if(xSemaphoreTake(m_handle, ( TickType_t ) 10)){
		 LogDebugInt("Demo Task(T2): Message from Task-2\r\n", 0);
		 xSemaphoreGive(m_handle);
	 }
	 vTaskDelay(pdMS_TO_TICKS(200));
 }
}

Please the output on console, after reboot.

ø----- Hello World -----
CPU Clock 300MHz
Peripheral Clock 150MHz
Demo Task(T1): Printing by Task-1

After that no msg on console, no msg from task-2. Can you help me to diagnose the problem?

Would you please break in debugger and see where is code is stuck?

You can try some of the debugging techniques (such as defining configASSERT, enabling stack overflow check) mentioned on this page: https://www.freertos.org/FAQHelp.html

Also, how is LogDebugInt implemented? Is it thread safe?

Thanks.

One question is can the LogDebugInt handle an unused parameter/zero parameter?

Also depending on the LogDebugInt implementation you should provide (much) more stack than just configMINIMAL_STACK_SIZE e.g. if LogDebugInt uses printf.
Did you enable diagnostics features like stack checking by
#define configCHECK_FOR_STACK_OVERFLOW 2
in FreeRTOSConfig.h ?
I‘d recommend to enable those features during development anyway.

Thanks to all of you for nice response.

I set the overflow flag (#define configCHECK_FOR_STACK_OVERFLOW 2) and implemented vApplicationStackOverflowHook(), it was showing Stack Overflow condition.

Then I increased the MINIMAL_STACK_SIZE to 250 (from 130) and problem solved.

Thanks for your support.