Skip to content

xSemaphoreCreateRecursiveMutexStatic cannot be used due to missing xQueueCreateMutexStatic #4851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gsuberland opened this issue Feb 23, 2021 · 7 comments
Labels
Type: Feature request Feature request for Arduino ESP32

Comments

@gsuberland
Copy link

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() {
}
@MarkusFelix
Copy link

MarkusFelix commented Mar 9, 2021

I've been hitting the same problems, albeit with xQueueCreateStatic
Did you find a way to get configSUPPORT_STATIC_ALLOCATION to work with the Arduino-ESP32 or do you recon the only way forward is to switch to IDF?

@phantomkingx
Copy link

phantomkingx commented Mar 11, 2021

Seems to me that there is no way to build freertos based on configuration since the assemblies are pre-built as /tools/sdk/lib/libfreertos.a and there is no freertos source code provided anywhere except for the header files in /tools/sdk/include/freertos/freertos/. Or am I missing something?

Edit:
I found this repo which I believe is used to build those assemblies
https://github.com/espressif/esp32-arduino-lib-builder

@igrr
Copy link
Member

igrr commented Mar 11, 2021

This can probably be fixed next time Arduino libraries are built, by enabling CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION in sdkconfig used by esp32-arduino-lib-builder. @me-no-dev WDYT?

@igrr igrr added the Type: Feature request Feature request for Arduino ESP32 label Mar 11, 2021
@me-no-dev
Copy link
Member

yup. on my to-do list

@me-no-dev
Copy link
Member

the flag has been enabled in the lib builder and we are waiting for IDF v3.3.5 to be released, so the builder can pick it up and send the update to #4936 for merging :) When that happens, Arduino 1.0.6 will be released as well

@me-no-dev
Copy link
Member

Change is now in the idf-release/v3.3 branch of this repository. Could you please test and confirm that everything is OK?

@me-no-dev
Copy link
Member

https://github.com/espressif/arduino-esp32/releases/tag/1.0.6 includes CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature request Feature request for Arduino ESP32
Projects
None yet
Development

No branches or pull requests

5 participants