Page 1 of 1
Convert F4 Discovery Demo to C++
Posted: Tue Jul 31, 2012 4:52 am
by razed4
Hi,
I cloned ChibiOS from Github, built it, and flashed it using IAR. Thanks for supporting IAR and Git!
I like to work in C++ so I switched the IAR project to C++ and got some build errors. Most of them where strong-type checks with pointers and I started to simply edit these before I realized there is a C++ wrapper. I also didn't want to edit the core C files, for instance those in the kernel directory.
Is it a big job to convert the project to C++? What things should I keep in mind? Can someone provide a couple of examples with this project and I'll try to do the rest?
Thanks,
Kenny
Re: Convert F4 Discovery Demo to C++
Posted: Tue Jul 31, 2012 7:17 am
by Giovanni
Hi,
Among demos there is already a C++ (G++) demo using the wrapper for the STM32, you may use that as example.
Note that the wrapper is a bit old and does not support all kernel features, a developer volunteered for updating it but the effort is apparently stalled, the idea was to create a C++ standard API around the kernel.
The discussion about the effort is here:
viewtopic.php?f=3&t=367Giovanni
Re: Convert F4 Discovery Demo to C++
Posted: Tue Jul 31, 2012 7:27 pm
by razed4
Hi Giovanni,
I am considering this for a commercial application which we will happily pay for. It doesn't sound like the C++ wrapper has support that I can rely upon. I am fine with a C API so long as it can be built/linked with a C++ compiler (In my case IAR). When I build everything with C++ I get pointer type issues. When I set to auto/extension based and change main.c to main.cpp it does seem to build OK. It looks like all the #ifdef __cplusplus stuff is in the header files so that name mangling is not an issue so I think I'll be fine.
Forgetting the C++ template for the moment would you say that plenty of folks are using the C API from C++?
Best,
Kenny
Re: Convert F4 Discovery Demo to C++
Posted: Tue Jul 31, 2012 7:40 pm
by Giovanni
Hi Kenny,
When using the makefiles the C files are compiled using the GCC and the C++ files are compiled using G++, everything is then linked together, that is the currently supported scenario.
Giovanni
razed4 wrote:Forgetting the C++ template for the moment would you say that plenty of folks are using the C API from C++?
The wrapper uses the C API from C++ so everybody using the wrapper does that, also the HAL is not wrapped at all so it is always used as C, is this what you mean?
Anyway if you need support for a specific scenario we can discuss it. You could also send me a little IAR project for me to test.
Giovanni
Re: Convert F4 Discovery Demo to C++
Posted: Tue Jul 31, 2012 8:05 pm
by razed4
Thanks Giovanni,
I'm doing a small internal project to evaluate the RTOS where I'll be integrating C++ classes. Let's see how this goes. If there was some red flag like "no one really has used C++ with this" then I would be concerned but it looks to me like use with C++ has been considered. In fact more so relative to other RTOS providers because you (or the community) actually attempted a C++ wrapper.
I appreciate your timely responses.
Kenny
Re: Convert F4 Discovery Demo to C++
Posted: Fri Aug 10, 2012 11:57 pm
by hazelnusse
Kenny,
I'm using ChibiOS with C++. I'm using GCC instead of IAR, so I don't know how the setup will vary, but at least in the GCC case, you can make all your application code as .cpp files and there are no problems. Interrupt handlers need the extern "C" { } business but other than that, I run into no issues using C++ with ChibiOS. My github project is here:
https://github.com/hazelnusse/robot.bicycle.
Luke
Re: Convert F4 Discovery Demo to C++
Posted: Sat Aug 11, 2012 10:40 pm
by Badger
I have used C++ with chibios extensively and it mostly works fine. I think there are two things you should be aware of if using the ExtendedThread class: the ld script needs to be altered to increase the stack size as you add more threads, and secondly the thread is launched within the constructor with some abuse of c++ convention, by possibly calling a virtual method before the constructor has returned. I spent a while looking at ways around this, but I became busy. If your intention is to use the Chibios C api with your own C++ classes I don't think you'll have a problem.
Re: Convert F4 Discovery Demo to C++
Posted: Sun Aug 12, 2012 8:16 am
by mabl
I'm also using C++ and ChibiOS. I guess it does not make too much sense to use the wrapper in it's current state. Regarding the wrapper threads, it's true that they are started from the constructor. That is why you cannot define them as static objects. But it's easy to adapt the wrapper code to have a dedicated Run() method.