Sign in

username:

password:



Not a member?

Search lpc2000



Search tips

Subscribe to lpc2000



lpc2000 by Keywords

2106 | ADC | ARM7 | Atmel | Bootloader | CAN | CrossStudio | CrossWorks | DDS | ECos | Ethernet | ETM | FIFO | FLASH | FPGA | GCC | GDB | GNU | GNUARM | GPIO | I2C | IAP | IAR | JTAG | Kickstart | LCD | Linux | LPC | LPC-E2294 | LPC2000 | LPC2100 | LPC2104 | Lpc2106 | Lpc210x | LPC2114 | LPC2119 | LPC2124 | LPC2129 | Lpc2138 | LPC213x | LPC21xx | LPC2210 | LPC2212 | LPC2214 | LPC2292 | LPC2294 | LPC2xxx | LPC3128 | MCB2100 | Olimex | Philips | PWM | Rowley | RTC | RTOS | SPI | SSP | UART | UART0 | UART1 | ULINK | USB | Watchdog | Wiggler

Ads

Discussion Groups

Discussion Groups | LPC2000 | Re: FreeRTOS + LPC2368: Can i use C++?

Discussion group dedicated to the Philips LPC2000 family of ARM MCUs

FreeRTOS + LPC2368: Can i use C++? - "Jorge S." - Oct 27 16:51:43 2008

Hi all,

After a few days of testing FreeRTOS on my LPC2368 board... i'm in
love with this increible piece of software.

Since i'm only doing some tests for learning purposes, i would like to
know if it is possible to use C++ source with
FreeRTOS.

I don't need exception handling or any other complex resources, I was
just planning to use a few basic
classes and some inheritance. C++ is not a MUST on my projects, but i
just feel confortable using it.

Thanks in advance,
Regards, Jorge.

Pd: Maybe this question is a little off-topic here, sorry if i'm
offending somebody.

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )


Re: FreeRTOS + LPC2368: Can i use C++? - thirdshoedrops - Oct 27 19:31:13 2008

--- In l...@yahoogroups.com, "Jorge S." wrote:
> i would like to know if it is possible to use C++ source with
> FreeRTOS.

I use GNU C++ with FreeRTOS on an LPC2148, and have used C++ with
several other ARM processors as well. There is no difference between
C and C++ from the perspective of the RTOS. You may have to write a
new startup routine that calls global constructors and destructors as
appropriate, but this is a simple task (once you figure out where the
linker stores the constructor/destructor tables).

I haven't needed exceptions or virtual functions yet, but I don't
believe they'll be terribly difficult to get working.

If your toolchain doesn't work with C++ right off the bat, all the
difficulty will be in figuring out exactly what your tools are doing
behind your back. How do code & data get laid out in memory? How is
initialization handled? And so on. This is important information to
know anyway, so you might as well dig in and learn it.
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: FreeRTOS + LPC2368: Can i use C++? - Serge Zloto - Oct 27 21:13:13 2008

You didn't mention which compiler toolchain you are using.
In my experience with GCC, then yes, C++ is not a problem.
I am using it without any library save for libgccc, so I am not using exceptions nor rtti
(and don't need to link with their associated runtime support cxa_xxx() and
xxx_personalityxxx).

But it's a pleasure to use templates for embedded software. Used judiciously, they can
make the source more readable, object code smaller and enhance reliability.

One thing: Global objects have to be constructed before used. so your startup code (or
even the first thing in main()) must call your global constructors if any. I adapted a linker
script to collect these as follows:

prog :
{
KEEP(*(.startup)); /* Prevents the startup code from being garbage collected */
*(.text)
*(.text.*) /* This is for the c++ vtables */ /* And -ffunction-sections */
*(.gcc_except_table) /* For c++ exceptions */
*(.gnu.linkonce.*) /* ??? */
*(.rodata)
*(.rodata*)
*(.glue_7)
*(.glue_7t)
} >flash

/* .ctors .dtors are used for c++ constructors/destructors */
/* added by Martin Thomas 4/2005 based on Anglia Design example */
.ctors :
{
PROVIDE(__ctors_start__ = .);
KEEP(*(SORT(.ctors.*)))
KEEP(*(.ctors))
PROVIDE(__ctors_end__ = .);
} >flash

.dtors :
{
PROVIDE(__dtors_start__ = .);
KEEP(*(SORT(.dtors.*)))
KEEP(*(.dtors))
PROVIDE(__dtors_end__ = .);
} >flash

and you startup can then call all there is between __ctors_start__ and __ctors_end__.
The destructors are optional, in embedded applications, unless you have a bios/os that
can restart whole applications. Not the case with the stock FreeRTOS.

Good luck
--
serge

--- In l...@yahoogroups.com, "Jorge S." wrote:
>
> Hi all,
>
> After a few days of testing FreeRTOS on my LPC2368 board... i'm in
> love with this increible piece of software.
>
> Since i'm only doing some tests for learning purposes, i would like to
> know if it is possible to use C++ source with
> FreeRTOS.
>
> I don't need exception handling or any other complex resources, I was
> just planning to use a few basic
> classes and some inheritance. C++ is not a MUST on my projects, but i
> just feel confortable using it.

> Thanks in advance,
> Regards, Jorge.
>
> Pd: Maybe this question is a little off-topic here, sorry if i'm
> offending somebody.
>
------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: FreeRTOS + LPC2368: Can i use C++? - mjames_doveridge - Oct 28 2:02:17 2008

--- In l...@yahoogroups.com, "Jorge S." wrote:
>
> Hi all,
>
> After a few days of testing FreeRTOS on my LPC2368 board... i'm in
> love with this increible piece of software.
>
> Since i'm only doing some tests for learning purposes, i would like to
> know if it is possible to use C++ source with
> FreeRTOS.
>
> I don't need exception handling or any other complex resources, I was
> just planning to use a few basic
> classes and some inheritance. C++ is not a MUST on my projects, but i
> just feel confortable using it.
>

To back up what others have said, there is no huge problem with C++ on
the ARM processors - it's just a code generator, after all. I use
Crossworks/GNU C++ on the 2129 with the Rowley ctl OS - a multitasker
like FreeRTOS. It works very well. For example, I use
inheritance/poly. to allow classes to be streamed out to the
serial/CAN/SD card, and to let their properties be edited by a LCD
display/keyboard, so reducing the code for all this to 'interpreting'
a const class 'metadata' table. This is so much
easier/better-structured/more flexible than huge gobs of C code to
serialize lots of typedefs. It's also much easier to debug since any
class can be easily have its properties listed by the serial debugger.

As for the OS, I am not that familiar with FreeRTOS, but I guess it
provides all the usual stuff, threads, semaphores, interrupt
management etc, same as ctl. I use a message-passing model, creating
a pool of message buffers at startup, that can be used for
inter-thread comms. Since the messages are a C++ class with
overloaded push/pop methods, they can be kept small since most
messages are small, but can accept occasional larger amounts of data
by internally depooling and linking more messages as required. Since
this is C++, the threads loading/unloading the message do not need to
know that this is happening and can just push/pop bytes, integers,
strings or buffers as necessary.

I have been warned not to use C++ on small, embedded jobs, but I think
that the advantages outweigh the disadvantages, even with 16k RAM.

The Rowley startup code calls the initial static constructors without
any changes. There was a problem at one stage where this failed for
thumb constructors, but Rowley fixed that.

I have not used exception handling - I'm not sure it's even supported
on my little 2129 Rowley system. It would have been useful, but
exceptions are a stack-based mechanism and I have to be careful with
stack sizes on a multiThreaded system with many stacks. Also,
exceptions cannot help when returning errors from one thread to
another. I have had to resort to returning error codes, either in
messages or as conventional function results :(

I know what you means about feeling 'comfortable' - after using OO
languages, plain C just seems like a jumbled mess, (and often is )

Go for it!

Rgds,
Martin

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )

Re: Re: FreeRTOS + LPC2368: Can i use C++? - "Jorge S." - Oct 28 5:05:29 2008

On Tue, Oct 28, 2008 at 2:13 AM, Serge Zloto wrote:
> You didn't mention which compiler toolchain you are using.
> In my experience with GCC, then yes, C++ is not a problem.
> I am using it without any library save for libgccc, so I am not using
> exceptions nor rtti
> (and don't need to link with their associated runtime support cxa_xxx() and
> xxx_personalityxxx).

I'm using a GNU toolchain (devkitARM) known working with C++, i already have
several examples on C++ working fine but without using FreeRTOS.

>
> But it's a pleasure to use templates for embedded software. Used
> judiciously, they can
> make the source more readable, object code smaller and enhance reliability.
>
> One thing: Global objects have to be constructed before used. so your
> startup code (or
> even the first thing in main()) must call your global constructors if any. I
> adapted a linker
> script to collect these as follows:
>
> prog :
> {
> KEEP(*(.startup)); /* Prevents the startup code from being garbage collected
> */
> *(.text)
> *(.text.*) /* This is for the c++ vtables */ /* And -ffunction-sections */
> *(.gcc_except_table) /* For c++ exceptions */
> *(.gnu.linkonce.*) /* ??? */
> *(.rodata)
> *(.rodata*)
> *(.glue_7)
> *(.glue_7t)
> } >flash
>
> /* .ctors .dtors are used for c++ constructors/destructors */
> /* added by Martin Thomas 4/2005 based on Anglia Design example */
> .ctors :
> {
> PROVIDE(__ctors_start__ = .);
> KEEP(*(SORT(.ctors.*)))
> KEEP(*(.ctors))
> PROVIDE(__ctors_end__ = .);
> } >flash
>
> .dtors :
> {
> PROVIDE(__dtors_start__ = .);
> KEEP(*(SORT(.dtors.*)))
> KEEP(*(.dtors))
> PROVIDE(__dtors_end__ = .);
> } >flash
>
> and you startup can then call all there is between __ctors_start__ and
> __ctors_end__.
> The destructors are optional, in embedded applications, unless you have a
> bios/os that
> can restart whole applications. Not the case with the stock FreeRTOS.
>
> Good luck

Thank you, i'm totally newbie with linker scripts (i only know the
basics) so i think is time
to get a deep dive into the .LD files :)

> --
> serge
>
> --- In l...@yahoogroups.com, "Jorge S." wrote:
>>
>> Hi all,
>>
>> After a few days of testing FreeRTOS on my LPC2368 board... i'm in
>> love with this increible piece of software.
>>
>> Since i'm only doing some tests for learning purposes, i would like to
>> know if it is possible to use C++ source with
>> FreeRTOS.
>>
>> I don't need exception handling or any other complex resources, I was
>> just planning to use a few basic
>> classes and some inheritance. C++ is not a MUST on my projects, but i
>> just feel confortable using it.
>
>> Thanks in advance,
>> Regards, Jorge.
>>
>> Pd: Maybe this question is a little off-topic here, sorry if i'm
>> offending somebody.
>>

------------------------------------



(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )