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


ATMega2560 reset when exiting task

Posted by Jesper Matthiesen on June 17, 2008

i have 3 tasks running and a shutdown condition that causes every task to exit its main loop. if i after the main loop have each task enter an infinite loop, everything is fine; if *any* one of them exit out of the task function, the device reboots.. this also happens when only running 1 task and at any stack size.. watch dog is turned off...

since the kernel, according to the documentation, never exits vTaskStartScheduler unless vTaskEndScheduler is called, what happens to tasks that return? do they just end as one would expect with the scheduler continuing? maybe it's when the idle task tries to do post-task cleanup that the device crashes/reboots? im using heap_1.c by the way...

RE: ATMega2560 reset when exiting task

Posted by Dave on June 17, 2008
From the WEB "Task functions should never return so are typically implemented as a continuous loop".

If you want to leave a task then you have to write something like this -

void TaskFunction(void *pv)
// task code that contains a break to jump out of the loop.

// Must not run off end of function so delete ourselves.

RE: ATMega2560 reset when exiting task

Posted by JMR on June 17, 2008
Further to davedoors' comment:
The tasks are simply functions when you create a task at start-up all you do is put a pointer to the functions entry point in the TCB list of the scheduler.
When the function then terminates, unless you explicitely call vTaskDelete(NULL) the function exit will cause a stack underflow, that is items that hadn't been pushed on the stack get popped and the program counter made to point somewhere in oblivion. Resulting in the reset that you observed.

RE: ATMega2560 reset when exiting task

Posted by Jesper Matthiesen on June 17, 2008
great advice...

since vTaskDelete can be omitted from the build to save space, i probably will put a "for ( ;; );" at the end of the tasks in question instead..


RE: ATMega2560 reset when exiting task

Posted by Dave on June 17, 2008
If you never want the task to run again and don't want to free the memory it is using you can instead use vTaskSuspend(NULL); This will prevent the task using CPU time, unlike the for(;;) solution.

RE: ATMega2560 reset when exiting task

Posted by Jesper Matthiesen on June 17, 2008
it's not that important if the tasks use cpu or not when entering shutdown.. i tried the vTaskSuspend ( NULL) option anyway (since i have it included in the build already), but this trigs a spontaneous device reboot in about 50% of cases also, which i find very strange...

[ 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