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

How does the cooky stack ptr get there?

Posted by JohnnyBosc on October 22, 2008
Facing what probably is a real noob problem. Posting it here in the hope that it'll be such an ordinary thing that the guys in the know will just click on it. If not, well I be slogging on...

I'm working with a Microchip PIC32 MCU, using the FreeRTOS port available on the site.

The problem is that my app will crash with a stack overflow for no good reason that I can discern.

The application has a serial port handler, for RX and TX both.

The interrupt routine (copied from the FreeRTOS demo example) is a simple wrapper, looks like this:

vU2InterruptWrapper:
portSAVE_CONTEXT
jal vU2InterruptHandler
nop
portRESTORE_CONTEXT

i.e. context should be properly saved and restored upon entry/exit to this routine.

The vU2InterruptHandler() function calls RX and TX handlers.

The RX handler posts the received character into a queue, performing a TaskYIELD() if a higher priority tasks has been woken by the post.

The TX handler reads a global circular buffer and xmits any characters it finds there. No TaskYIELD() is performed from the TX handler, on the theory that it isn't needed since FreeRTOS is never called from it.

Mostly it works, but once in while (rather too often, really) the application crashes from the vTaskSwitchContext() kernel function into the stack overflow hook routine. Examining the current TCB it is clear that the top-of-stack is much smaller than the stack base -- a stack overflow condition *does* prevail.

However, the top-of-stack value recorded in the current TCB appears to belongs to another task altogether.

Examining the stack memory for the crashed task one can see that most of it has never been in use -- out of a 256 item stack I'd get a high water mark of 150 or so, yet the top of stack is 100 items or so *below* the stack base.

Clearly the wrong top-of-stack value is being written into the current PCB, for whatever reason. The usual suspect is --of course-- some interrupt routine, more than likely the serial TX one since the program does copious amounts of 115 kbaud RS-232 output during its processing.

Is this a familiar scenario to you folks?

RE: How does the cooky stack ptr get there?

Posted by JohnnyBosc on October 22, 2008
I should maybe add that more than ample stack space has been provided for all the tasks and interrupt routines involved.


[ 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