Page 1 of 1
cpp template using freertos and external cpp libraries
Posted: Sun Mar 26, 2017 3:01 pm
by DL88AI88
Hi there,
I noticed that there are some cpp skeletons out there like these:
e.g.
https://github.com/nkolban/esp32-snippe ... letons/cpp
in conjunction with these
(works fine for me)
e.g.
https://github.com/pcbreflux/espressif/ ... _cpp_hello
(haven't tested yet by myself)
I want to include already existing cpp libraries from arduino in my cpp project running on freertos.
Now I have 2 questions:
How do I run freertos in a cpp environment?
Can I add cpp libraries from arduino (written for an esp32 basis) as simple as I can with c-files?
I know these questions are a bit shady, but above all I am looking for an esp32 cpp/freertos template in an eclipse environment.
Any kind of hint is welcome.
best regards
DL88AI88
Re: cpp template using freertos and external cpp libraries
Posted: Sun Mar 26, 2017 7:32 pm
by kolban
Howdy,
Think of any application you write as running "within" a FreeRTOS environment by default. When the ESP32 loads (with the standard bootloader), FreeRTOS is started including the scheduler. All the FreeRTOS libraries are available to your application.
By default, user code (i.e. code you write) is given control through the function you export called "app_main()". Within your code you can use all the FreeRTOS functions you like. The same story is true for both C and C++.
When you compile your application, you are statically linking all the libraries that the code needs to run including FreeRTOS ... but specially, any libraries that you may get from elsewhere also have to be statically linked with your application. When you flash your ESP32 with the app, this also pulls in the libraries that were link-edited with your code.
The ESP32 provides an Arduino environment which is no more and no less than C code that implements the Arduino framework. Instead of YOU having to code "app_main()", that has been coded into the Arduino libraries. Those libraries expect to find two function called "loop" and "setup" (if memory serves me) and it is your responsibility to code those. If you wish to use additional Arduino libraries, you simply link them into your application.
Re: cpp template using freertos and external cpp libraries
Posted: Tue Mar 28, 2017 4:53 am
by rsimpsonbusa
I struggled with this myself.
Your main.c should now be called main.cpp.
For C libraries you now need a extern C envelope (look at the beginning of the file).
All esp-libraries are "extern C " protected so no need to put them inside this section BUT must put app_main(), ei your start routine, inside the extern c envelope.
When adding pure C code, like ds18b20.h, put it inside the Extern C includes. ALl other cpp (c++) libraries OUTSIDE of the extern C envelope or you´ll get a lot of compiler errors.
Attach a template I used for testing several features of the ESP32.
There are some Arduino C libraries and some C++ libraries. I put the ESP32 components inside the extern c envelope even though its not required.
Hope it gives you some guidance.
RSN
Re: cpp template using freertos and external cpp libraries
Posted: Tue Mar 28, 2017 8:42 am
by DL88AI88
Hi RSN,
wow, that is really helpful.
Thumbs up!
Thank you.
Best regards
DL88AI88