2025-05-16 6:54 AM
Hello Experts,
i am facing a similar issue on the STM32F407G discovery board. Is there any solution or a temporary fix for this iisue?
Changing the initial state of the semaphore to Depleted does nothing in the semaphore definition and creation:
In freertos.c, inside the function MX_FREERTOS_Init(). i think the second function parameter should be zero
I am trying a simple GPIO interrupt to task signaling, but the task always takes a semaphore without the GPIO interrupt the first time. I have attached the complete freertos.c file for context. This is the console screenshot to highlight the bug:
I tried to manually change:
myBinarySem01Handle = osSemaphoreCreate(osSemaphore(myBinarySem01), 1);
to
myBinarySem01Handle = osSemaphoreCreate(osSemaphore(myBinarySem01), 0);
Now the task does not take the semaphore during start up, but the moment the GPIO interrupt occurs(push-button), the whole system hangs in an asset failure:
Is there any solution to this problem? I have attached my freertos.c file as well.
2025-05-16 9:00 AM
If the 2nd parameter is 0, osSemaphoreCreate likely returned NULL handle (myBinarySem01Handle ), this is why you assert in xQueueGiveFromISR. Please see the source in cmsis_os.c and you will understand.
2025-05-16 12:40 PM
Yes, thanks for pointing it out. Looking at osSemaphoreCreate function i realized it was returning NULL.
This brings up the question how do we change the semaphores initial state to depleted/empty?
I also tried to use the native FreeRTOS APIs (xSemaphoreCreateBinary) which creates the semaphore in an 'empty' state, this worked for me, so i am pretty confident there is some issue in the cmsis implementation.
2025-05-16 1:16 PM - edited 2025-05-16 1:42 PM
Is config_USE_COUNTING_SEMAPHORES defined as 1 ?
Maybe, change osSemaphoreCreate like following:
...........
if (count == 1) {
return xSemaphoreCreateBinaryStatic( semaphore_def->controlblock );
}
else if (count == 0) {
sema = xSemaphoreCreateBinaryStatic( semaphore_def->controlblock );
if (!sema) return sema;
osSemaphoreWait(sema, 0); //immediately take it
return sema;
}
else {
..........