Quality RTOS & Embedded Software

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


return to main() for ARM ports

Posted by Glen B. on December 13, 2005
I thought I would share the following Idle Task hook that returns to main() when all tasks die. Feedback is welcome.

You could turn off the Tick ISR here or when back in main().

This assumes all allocated queues have been freed by the tasks themselves before they are deleted (or delete themselves) with vTaskDelete().

Also assumes this function is compiled as ARM code (say in portISR.c). Untested for return to Thumb code although I think it is correct.

void vApplicationIdleHook(void)
__static bool die = false;

_// when only the idle task remains, we may need one last pass of the idle
_// task to free resources of last application task, and then we quit

__if (die)
__{ // return to old context at end of vPortISRStartFirstTask()

____die = false;
____asm volatile ( "msr cpsr_c,#0xD3"); // back to supervisor state
____asm volatile ( "ldmia sp, {r11,sp,lr}"); // restore regs for return
____asm volatile ( "bx lr"); // and return

__else if (uxTaskGetNumberOfTasks()==1)
__{ // only the idle task remains. so
____// die on next pass after all deleted task TCBs are sure to be freed

____die = true;

RE: return to main() for ARM ports

Posted by Nobody/Anonymous on December 13, 2005
Neat....maybe this should be the default behaviour for vPortEndScheduler() in port.c, which is at the moment "not implemented for the arm".

RE: return to main() for ARM ports

Posted by RaceMouse on July 10, 2007

I quess it's time to revive this old thread...

We use FreeRTOS in a bootloader. When the bootloader's job is finished we need to stop the scheduler and jump to a different location where the main application starts. When trying to compile the "new" vPortEndScheduler (which I moved to portISR.c for compilation in ARM Mode) I get the following junk thrown at me:

/cygdrive/c/DOCUME~1/RFI~1.LOD/LOCALS~1/Temp/cczKqAza.s: Assembler messages:
/cygdrive/c/DOCUME~1/RFI~1.LOD/LOCALS~1/Temp/cczKqAza.s:12: Error: flag for {c}psr instruction expected -- `msr CPSR_C,#0xD3'
/cygdrive/c/DOCUME~1/RFI~1.LOD/LOCALS~1/Temp/cczKqAza.s:14: Error: bad instruction `sbx LR'
make[1]: *** [Source/portable/GCC/ARM7_AT91SAM7/portISR.o] Error 1

I have no idea what this means. Can someone help me here ?


RE: return to main() for ARM ports

Posted by RaceMouse on July 10, 2007
Hmmm... My fault. One spelling error and one letter that should not be versal but was...
Works now :-)


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

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

Latest News

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

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

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

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