Description
Hardware:
Board: NodeMCU-32S (ESP32)
Core Installation version: 1.0.4
IDE name: Arduino IDE
Computer OS: Windows 10
Description:
Attempting to use xSemaphoreCreateRecursiveMutexStatic
in a sketch throws a linker error:
\Temp\arduino_build_484718\sketch\horus.ino.cpp.o:(.literal._Z5setupv+0x48): undefined reference to `xQueueCreateMutexStatic'
\Temp\arduino_build_484718\sketch\horus.ino.cpp.o: In function `setup()':
\Temp\arduino_build_484718\sketch/configurable.h:183: undefined reference to `xQueueCreateMutexStatic'
collect2.exe: error: ld returned 1 exit status
exit status 1
The configurable.h
script has no code at line 183; it's the end of the file. I checked this in the actual file in the temp folder. This appears to be a red herring. The issue is called when attempting to use the xSemaphoreCreateRecursiveMutexStatic
function.
Support for this FreeRTOS feature is supposed to be enabled by setting configSUPPORT_STATIC_ALLOCATION
and configUSE_RECURSIVE_MUTEXES
in the build flags. I did this via platform.local.txt
, along with some other flags I needed:
extras.defines=-DCONFIG_SUPPORT_STATIC_ALLOCATION=1 -DconfigSUPPORT_STATIC_ALLOCATION=1 -DconfigUSE_MUTEXES=1 -DconfigUSE_RECURSIVE_MUTEXES=1 -DconfigUSE_COUNTING_SEMAPHORES=1
build.defines={extras.defines}
compiler.cpp.extra_flags={extras.defines}
compiler.c.elf.extra_flags={extras.defines}
compiler.c.extra_flags={extras.defines}
compiler.S.extra_flags={extras.defines}
This should enable both static and recursive semaphores, and all FreeRTOS reference states that this should work. I can see that the flags are passed as part of the compilation output.
Looking into the code here, the actual implementation of xQueueCreateMutexStatic
seems to be missing. There's a forward declaration in queue.h but nothing else. The main FreeRTOS code branch includes the actual implementation.
Note that the dynamic recursive version of the function, xSemaphoreCreateRecursiveMutex
, does appear to be present and working when these config flags are set. It's just the static ones that are missing.
Sketch:
#include <Arduino.h>
#include <freertos/freertos.h>
#include <freertos/queue.h>
#include <freertos/semphr.h>
SemaphoreHandle_t mutexHandle;
StaticSemaphore_t mutexStatic;
void setup() {
mutexHandle = xSemaphoreCreateRecursiveMutexStatic(&mutexStatic);
}
void loop() {
}