I’m using FreeRTOS kernel V10.4.5 on a Teensy 4.1 development board.
In main.cpp, I have defined two semaphores, semaphore_a and semaphore_b. I also have an initialization function ctrl_init(), which is the first function called from main(), and is intended to initialize and take these semaphores.
SemaphoreHandle_t semaphore_a = NULL;
SemaphoreHandle_t semaphore_b = NULL;
static void ctrl_init(void) {
semaphore_a = xSemaphoreCreateMutex();
xSemaphoreTake(semaphore_a, portMAX_DELAY);
semaphore_b = xSemaphoreCreateMutex();
xSemaphoreTake(semaphore_b, portMAX_DELAY);
}
This has worked without issue. However, if I attempt to convert these semaphores to binary semaphores instead of mutexes, like so:
static void ctrl_init(void) {
semaphore_a = xSemaphoreCreateBinary();
xSemaphoreTake(semaphore_a, portMAX_DELAY);
semaphore_b = xSemaphoreCreateBinary();
xSemaphoreTake(semaphore_b, portMAX_DELAY);
}
then I get the following error message over my serial connection to the Teensy board:
ASSERT in [.pio/libdeps/teensy41/freertos-teensy/src/list.c:127] vListInsert(): ( ( pxNewListItem )->xListItemIntegrityValue1 == 0x5a5a5a5aUL ) && ( ( pxNewListItem )->xListItemIntegrityValue2 == 0x5a5a5a5aUL )
The referenced ASSERT seems to be the macro listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); in vListInsert().
I do not see this behavior (everything behaves as expected) if I comment out either of the xSemaphoreTake lines from my initialization function, or if either or both of the semaphores are created with xSemaphoreCreateMutex.
I do not have a debugger on hand, so unfortunately cannot see the whole stack trace. I also understand that there are other ways to accomplish what I am trying to do here. All the same, I would like to understand, why is this crash happening? What is different between binary semaphores and mutexes which may account for this difference in behavior?
Appreciate any help I can get!