Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

FreeRTOS and C++ STL compatability

Posted by sinakahnemouyi1 on September 16, 2014

Hi,

I was wondering if FreeRTOS is compatible with C++ STL (containers such as list, vector). FreeRTOS tasks use thread safe allocators, however STLs use simple malloc, and free functions. Is there anyway to make this work?

Thanks


FreeRTOS and C++ STL compatability

Posted by edwards3 on September 17, 2014

If you can redirect the compiler to a different malloc and free implementation (common with compilers, check the command options) then use heap_3.c and redirect malloc() to pvPortMalloc() and free() to vPortFree(). That will take care of the memory allocation, not sure about the rest.


FreeRTOS and C++ STL compatability

Posted by sinakahnemouyi1 on September 18, 2014

Thank you MEdwards. I am using Kinetis Design Studio which is an Eclipse based IDE and I was able to enable multiple definitions in the compiler by adding the following flag to the C/C++ linker: -z muldefs

This allowed me to override the malloc and free functions for FreeRTOS and solved the problem. This can be done in the main.c file:

extern void malloc(size_t size); extern void free (void ptr);

void *malloc(size_t size) { void *result;

result = FRTOS1_pvPortMalloc(size);

return result;

}

void free (void* ptr){ FRTOS1_vPortFree(ptr); }

Best, Sina


FreeRTOS and C++ STL compatability

Posted by rtel on September 18, 2014

Maybe just where you have types the code in here, but note the prototype of the malloc() function you posted is not correct. It needs to return a void *, not just a void. I imagine this is correct in your real code otherwise the compiler would complain.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists