Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


IAR & static_cast<>

Posted by Thomas on June 4, 2008
I'm trying to use FreeRTOS together with C++.

I'm using IAR AVR compiler.

All of FreeRTOS source files are compiled using the C compiler and my own code using Extended Embedded C++ compiler. All the code are compiled and linked togther without errors.

Inspired by a richard_damon post I've made a Runable class, see below.

Running my code I get an RStack warning (JTAGICE mkII)
Wed Jun 04 11:49:06 2008: Target reset
Wed Jun 04 11:49:16 2008: Program exit reached.
Wed Jun 04 11:49:17 2008: The stack 'RStack' is filled to 100% (32 bytes used out of 32). The warning threshold is set to 90.%

I've traced it down to being this static_cast causing the trouble.


If I comment the static_cast and uncomment the loop causing a led to flash everything works fine.

I have tried the same code using winavr c++ compiler and it works. Using the winavr compiler I compile everything using the c++ compiler. Therefore I have to change some cast here and there in the FreeRTOS code in order to satisfy the c++ compiler. When using IAR I can compile a "clean" FreeRTOS (without changing anything) using C compiler and my own code using C++. My guess is that its the reason for my troubles.

Can someone give me an explanation or even a way to fix it?


// runable.c

#include "runable.h"

Runable::Runable(unsigned priority, unsigned stacksize)
#if INCLUDE_vTaskDelayUntil
lastWakeTime = NULL;
xTaskCreate(&run, "", stacksize, this, priority, &handle);

#if INCLUDE_vTaskDelete

#if INCLUDE_vTaskSuspend

void Runable::Suspend()

void Runable::Resume()


#if INCLUDE_vTaskDelay

void Runable::Sleep(portTickType delay)


#if INCLUDE_vTaskDelayUntil

void Runable::SleepUntil(portTickType increment)
if (lastWakeTime == NULL)
lastWakeTime = xTaskGetTickCount();
vTaskDelayUntil(&lastWakeTime, increment);


void Runable::run(void* parm)
PORTA = (PORTA & ~0x01) | (~PORTA & 0x01);

vTaskDelay( 100 );

RE: IAR & static_cast<>

Posted by Richard on June 5, 2008
So the problem seems to be when linking C with C++ code. Is this correct? Can you compile the whole thing as C++ as when using the WinAVR compiler?


RE: IAR & static_cast<>

Posted by Thomas on June 9, 2008
I managed to figure it out. I had some errors in my port causing the stack to be currupt.

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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner