Page 1 of 1

[solved] crazyflie firmware and c++

Posted: Sun Mar 29, 2020 7:58 pm
by stefanovic
Hello,

I'm trying to embed c++ code into the freertos-based firmware of the crazyflie drone, with the "app" framework and the push-demo as a basis.

I succeeded in compiling, linking, launching, but dynamic_cast<> always returns nullptr, and exceptions raised are not caught. I enabled flags such as -fexceptions, -rtti, and removed --specs=nano.specs to no avail. Something to know: it's the app task that eventually calls a c++ function which in turn does c++ stuff.

Does anybody know if the specific flags of the crazyflie firmware compilation process prevent c++ to behave correctly wrt to dynamic_cast?

(and I’m aware rtti and exceptions are not recommended in embedded apps, but I still want to try)

Best,
Stéphane

Re: crazyflie firmware and c++

Posted: Mon Mar 30, 2020 11:51 am
by kristoffer
Hi!

I know Arnaud looked at C++ at some point, but as far as I remember he ran into some kind of problem, not sure what though. We did not have the app layer at that time, it might be possible to get that to work?

I found this thread that might help you?
https://www.freertos.org/FreeRTOS_Suppo ... a047j.html

Please keep us posted on your work!

Re: crazyflie firmware and c++

Posted: Mon Mar 30, 2020 3:23 pm
by stefanovic
Thank you.
Unfortunately the various discussions on this on the net do not bring solutions to my problems, including the one you mention.

I opened up another discussion over at https://forums.freertos.org/t/freertos-and-c-rtti/9372

Everything happen as if the std library was not initialized somehow: dynamic_cast returns nullptr, stl containers are faulty, no initialization of c++ global objects etc.

still trying to no avail...

Re: crazyflie firmware and c++

Posted: Wed Jul 15, 2020 5:18 pm
by stefanovic
I had some free time to go back to this problem.
It turned out that it was entirely my fault, as expected.
I figured that c++ code in headers was working as intended, but not the code in object files that I was compiling externally.
This led me to the insight that I was not compiling them correctly.
Using this small command (*), I could figure out that some files were compiled with -fpic, and some were not, which made the c++ code behave incorrectly.

Case closed, sorry for the noise, and thanks for your help.

(*) echo $(CXXFLAGS) | tr " " "\n" | sort ;

Re: [solved] crazyflie firmware and c++

Posted: Thu Jul 16, 2020 8:06 am
by kimberly
thanks for the update and happy you found the solution!