freertos/Mutex.hpp: No such file or directory
Hello, I'm trying to use this library in platformio with my ESP32 WROOM.
I tried to create a minimum repro. Here is my platform.ini:
[env:sparkfun_thing_bluetooth]
platform = espressif32
board = sparkfun_esp32s2_thing_plus_c
framework = arduino
lib_deps =
igor-krechetov/hsmcpp@^1.0.1
custom_hsm_files=./blink.scxml:BlinkHsm:Base
custom_hsm_gendir=./src
Other than the platform and board, I believe this is identical to the example.
It generated the BlinkHsmBase cpp and header files (very cool!) but fails to compile:
Compiling .pio\build\sparkfun_thing_bluetooth\liba67\hsmcpp\HsmEventDispatcherArduino.cpp.o
Compiling .pio\build\sparkfun_thing_bluetooth\liba67\hsmcpp\HsmEventDispatcherBase.cpp.o
In file included from .pio/libdeps/sparkfun_thing_bluetooth/hsmcpp/include/hsmcpp/HsmEventDispatcherBase.hpp:13,
from .pio/libdeps/sparkfun_thing_bluetooth/hsmcpp/include/hsmcpp/HsmEventDispatcherArduino.hpp:10,
from .pio/libdeps/sparkfun_thing_bluetooth/hsmcpp/include/hsmcpp.hpp:8,
from src/main.cpp:5:
.pio/libdeps/sparkfun_thing_bluetooth/hsmcpp/include/hsmcpp/os/Mutex.hpp:9:11: fatal error: freertos/Mutex.hpp: No such file or directory
#include "freertos/Mutex.hpp"
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\sparkfun_thing_bluetooth\src\main.cpp.o] Error 1
https://github.com/igor-krechetov/hsmcpp/blob/91b791de43c263a9ce2025267506e9c41ddba555/include/hsmcpp/os/Mutex.hpp#L8
I tried digging into this error and found that INC_FREERTOS_H is being defined here:
~.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\include\freertos\include\freertos\FreeRTOS.h:
Apparentl this board is using freeRTOS under the hood. But like the error message suggests, I'm not able to find any associated file freertos/Mutex.hpp.
Any ideas what I should try? Thanks!
So spent some more time digging into this and didn't realize that the freertos part of this library isn't included in the platformio library, so the compiler gets confused on microcontrollers that use freertos.
I tried putting the full hsmcpp library into my platformio's lib folder, but after scratching my head a bit with all the errors that popped up I reverted to making this change to the .pio\libdeps\sparkfun_thing_bluetooth\hsmcpp\include\hsmcpp\os\os.hpp file:
#if defined(PLATFORM_FREERTOS) // || defined(INC_FREERTOS_H)
Which makes it use the arduino implementation of Mutex.hpp instead of looking for the missing freertos file. Then it compiles fine.
My project doesn't really need freertos, I just wanted to clean up some of the state management. Given that, do you see any issues with me stubbing out the Mutex class like this? I'm using HsmEventDispatcherArduino as the dispatcher.
One more observation here, the blink example didn't work because this line was evaluating to false
https://github.com/igor-krechetov/hsmcpp/blob/91b791de43c263a9ce2025267506e9c41ddba555/src/HsmEventDispatcherArduino.cpp#L108
Changing it to
if (handleTimerEvent(it->first)) {
made it start working for me.
EDIT: seems like somewhere this is being set
#define true 1
maybe by the compiler? I miss my native language of c# 😥
I ran into the same issue and it looks like a problem with the PlatformIO lib-registry to me.
Tagged 1.0.1 state contains this "freertos" subfolder: include/hsmcpp/os @ 1.0.1
But it seems to be missing in the platformio package:
I also failed including the tagged 1.0.1 version as submodule. The FreeRTOS implementation contained an ARM-specific call (xPortIsInsideInterrupt). After hacky-redirect using #define the compilation stopped on Qt-Dependencies.
I ended up switching back to the PlatformIO package (without all these things) and force the system to use the arduino implementation by undefining the INC_FREERTOS_H constant:
#undef INC_FREERTOS_H
#include <hsmcpp.hpp>
#include "BusMcuHSMBase.hpp"
#define INC_FREERTOS_H
Providing solutions for all combinations is not easy to build nor to test. But I would be happy if there would be a native switch to force the lib to use a specifc implementation. Something like HSMCPP_USE_ARDUINO as buildflag?