My setup: The GCC/Eclipse-Demo running on AT91SAM7X259
My aim: Using C++ within my tasks
My approach:
1. Rename main.c in main.cpp
2. add manual typecasting für the task-name in xTaskCreate by (const signed char*)
3. add extern “C” in front of vApplicationTickHook and the includes of my own header-files, which declare the task I’ve created
4. alter makefile to compile main.cpp with g++, the rest with gcc and link both with g++
So far so good, this compiles and runs as fine as before. My problems begin when trying to transform those files containing the tasks (used by by xTaskCreate in main.cpp) into C++ by moving the in the makefile from gcc to g++. The header-file (sandbox.h) looks like this.
That’s all I did. Compiling works fine without warnings or errors, but the code just doesn’t run (no blinking LED ;-(. To get it working again I just move sandbox.cpp in my makefile back to gcc (though there are warnings about the file ending).
So apparently xTaskCreate has trouble digesting my task-functions when those are compiled with g++. I’m afraid I once again missed something obvious about making my C+±functions available to othe C-code. Can someone please give me a kick into the right direction.
And while we’re at it: Why don’t I get any hints from the compiler that something is wrong?
I have to add, that after including the ifdef __cplusplus to my headers I removed the aforementioned extern “C” in front of the includes. This reduces my changes to the makefile and the header-file. Creating the task looks like this btw:
xTaskCreate(vTaskLED, (const signed char*)"SvenLED", 50, NULL, 1, NULL);
But the way I understand those threads I’m already doing what’s required to resolve this by using extern “C”. The wrappers shouldn’t be neccessary, also in those threads everbody gets nice compiler errors helping to identify the issue.
Since I don’t want to mess my project with all those wrappers (doubling the amount of files), I’d be really thankful for some hints on how to resolve this. I also refreshed my knowledge about void-pointers in C++, but don’t see what should be causing issues there.
Technically, to pass a function pointer to a C function, the function should be declared extern “C”, note that does NOT require the wrapper header that you have been describing, but you can just declare the function like:
Hi Richard, many thanks for your reply.
Unfortunately it didn’t get me any further. Basically I had already done what you proposed but with separate declaration and definition. Now I’ve also merged those the way you suggested resulting in thise very bare example code which still doesn’t work.
Keep in mind that this compiles fine but just doesn’t run on the target. Unfortunately I’m not able to get my debugger running (which certainly isn’t related to this specific problem) but with the help of some LEDs I could figure out, that everything’s fine until vTaskStartScheduler() is called. From then on even interrupts aren’t working. That’s either because the global interrupts enable fails (within StartScheduler) or the target goes into some very deep limbo.
I’d still appreciate every help, those wrappers I’m using in the meantime are rather ugly.
Sorry for reviving an old thread, but it seems I have exactly the same problem. I am trying to weld together FreeRTOS, C++ and NXP Arm Cortex-M3 LPC1768 — with no success so far. I’ve got LPCXpresso4 IDE (so that’s GCC) and LPC-Link debugger.
FreeRTOS in a C project works just fine. Classes and other OO stuff in a C++ project also work just fine. However, FreeRTOs in a C++ project compiles succesfully, but simply does not work. Since I am a happy owner of the LPC-Link debugger, I was able to track the problem to:
void vPortStartFirstTask( void )
{
__asm volatile(
" ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
" ldr r0, [r0] \n"
" ldr r0, [r0] \n"
" msr msp, r0 \n" /* Set the msp back to the start of the stack. */
" svc 0 \n" /* System call to start first task. */
);
}
After that I immediately end up in SVCall_Handler exception handler. Any ideas?..
I’ve been seaching the internet for a few days now, but all I find is usually “I know a few guys using FreeRTOs in their C++ projects” or “In theory, it should work”. Not very helpful
After that I immediately end up in SVCall_Handler exception handler. Any ideas?..
Well, that is exactly what is supposed to happen after you call SVC 0, question is, is it the FreeRTOS exception handler or the default one? If it is not the FreeRTOS one, then it sounds like you have not populated the vector table. If it is the FreeRTOS one, then what happens from there?
Well, that is exactly what is supposed to happen after you call SVC 0, question is, is it the FreeRTOS exception handler or the default one? If it is not the FreeRTOS one, then it sounds like you have not populated the vector table. If it is the FreeRTOS one, then what happens from there?
It was the default one. I just changed default SVCall, PendSV and SysTick handlers to vPortSVCHandler, xPortPendSVHandler and xPortSysTickHandler and now it works! No wrappers, no workarounds, just FreeRTOs in C++ project.
That was such a trivial problem and solution. How did I missed it in documentation? It should be emphasized somehow…
I am also trying to make FreeRTOS with main.cpp file.
First step where I stuck is how to compile FreeRTOS using gcc and main.cpp using g++ with Makefile. It would be of great help if someone has already made makefile which does this task.