xSemaphoreTake doesn't work as expected

Hello!
I am new to FreeRTOS and I have a problem.
This is part of the code and the problem is that my code gets stuck in mainThread just above the if(xSemaphoreTake(Event, SEMAPHORE_TIMEOUT_MS) == pdPASS). I have created the _error_pull_timer_handler especially so that I can release the semaphore.
The timer had the role of reinitializing the communication master slave in the I2C protocole in case it gets lost. There was a 500 miliseconds timer that had the role to do this.
Can you please help me so that I can unblock the semaphore?

static TimerHandle_t error_timer_handler = NULL;
#define ERROR_CHECKER_DELAY_MS 500
#define SEMAPHORE_TIMEOUT_MS pdMS_TO_TICKS(1000) /* 1sec */

static int _start_error_timer()
{
	if(error_timer_handler == NULL)
	{
		return -1;
	}

	if(xTimerReset(error_timer_handler, 0) != pdPASS)
	{
		return -2;
	}

	return 0;
}

static int _stop_scale_error_timer()
{
	if(error_timer_handler == NULL)
	{
		return -1;
	}

 	if (xTimerIsTimerActive(error_timer_handler) == pdFALSE)
    {
        return -3; // Timer is not active
    }

	if(xTimerStop(error_timer_handler, 0) != pdPASS)
	{
		return -2;
	}
	return 0;
}

// callback function for timer
static void _error_pull_timer_handler(TimerHandle_t xTimer)
{
	
	UNUSED_PARAM(xTimer);
	// Attempt to release (give) the semaphore
	if(xSemaphoreGive(Event) != pdPASS) {
		// add a log
	}
	 else {
		// add anoher log    
	}
}


bool init(void)
{
	
	//Create a binary semaphore : Do not take the first one, it will be used to acquire a previous IRQ if necessary
	vSemaphoreCreateBinary(Event);
	
	if(xTaskCreate(eventThread, THREAD_NAME, THREAD_STACK_SIZE, NULL, THREAD_PRIORITY, NULL) != pdPASS) {
		return FALSE;
	}

	// create timer for scale error check
	error_timer_handler = xTimerCreate("timer", pdMS_TO_TICKS(ERROR_CHECKER_DELAY_MS), pdTRUE, NULL, error_timer_handler);
	if(error_timer_handler == NULL)
	{
	// add a log
	}
	  else
    {
	// add another log    
	}
	
	return TRUE;
}


static void mainThread(void* param)
{
	
	UNUSED_PARAM(param);

	while(1)
	{
     
		if(xSemaphoreTake(Event, SEMAPHORE_TIMEOUT_MS) == pdPASS)
		{
			TRACE("Event received\n");

..

	}
_stop_scale_error_timer();
}

do you see the logs in your timer, iow is the control flow in itself sound? Did you check that the semaphore is being created ok?

Hello!
Yes, it is created ok. I have added logs.
I have added extra logs in the method mainThread() at the end:

 // Optionally stop the timer after operations
            if (_stop_error_timer() != 0)
            {
                TRACE("Failed to stop error timer\n");
            }
            else
            {
                TRACE("Error timer stopped\n");
            }

            // Optionally restart the timer after operations
            if (_start_error_timer() != 0)
            {
                TRACE("Failed to restart error timer\n");
            }
            else
            {
                TRACE("Error timer restarted\n");
            }
        }

I get the message: Failed to restart error timer.

it is unclear from your incomplete code whether the scheduler is already started when you call your init() function. You may want to create your timer before the event task. Obviusly your timer reset function does not work.

Can you put a breakpoint in the _error_pull_timer_handler function and see if it is getting invoked? What is the value of configTIMER_TASK_PRIORITY?