Quality RTOS & Embedded Software

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




Loading

Hair-tearing time with a PI32 Stack Overflow.

Posted by Malcolm Cockcroft on June 20, 2011
I am attempting to transfer code from another RTOS (inhouse on a Renesas chip) to Freertos in the PIC32. All appears to work except that I get a random Stack Overflow exception.

When I examine the problem I find the following:
The crash occurs in the vTaskSwitchContext() called from the vPortYeildISR()
The current tcb is the IDLE task
The Top of stack is pointing into the xISRStack instead of it own stack.

Anybody with any ideas before I become bald?

RE: Hair-tearing time with a PI32 Stack Overflow.

Posted by Richard Damon on June 21, 2011
Sounds like something is corrupting your task info.

A few things to look at:
Interrupt that calls FromISR routine having too high of an interrupt priority
Interrupt that calls a non FromISR API routine
Improper nesting of interrrupts
A non-interrupt calling a FromISR routine
Idle Hook function blocks
You have a stack overflow in some task (try turning on overflow detection)

RE: Hair-tearing time with a PI32 Stack Overflow.

Posted by Malcolm Cockcroft on June 21, 2011
My first assumption was stack corruption so I run all interrupts at the same priority to avoid nesting, carefully checked the FromISR calls and use the default idle loop and disabled the pre-emption.
I run with the stack overflow turned on (2) which is how I found the problem.

The locations round the stack pointer in the TCB are OK except for the stack pointer value itself. The appearance is of the idle task calling an interrupt routine which returns without resetting the stack pointer!

RE: Hair-tearing time with a PI32 Stack Overflow.

Posted by Richard on June 21, 2011
From the two comments:

“All appears to work except that I get a random Stack Overflow exception.”


and

“I run with the stack overflow turned on (2) which is how I found the problem.”


Are you getting a stack overflow exception? If so, that is not coming from having the stack overflow protection turned on in FreeRTOS. The mechanism in FreeRTOS will cause vApplicationStackOverflow() to be called, not an exception to occur. I know some PIC architectures have stack limit registers catch stack overflows, but I'm not sure that applies to the MIPS based parts, and FreeRTOS does not use them anyway so that functionality should be off in the hardware.

“The Top of stack is pointing into the xISRStack instead of it own stack.”


Do you mean the top of stack used by the idle task? If so, then I agree that is wrong. Otherwise, in an interrupt that called vTaskSwitchContext() I would expect the stack pointer at the time the function was called to be in the ISR stack, as, after all, it is being called from an ISR.

“so I run all interrupts at the same priority”


Was that the lowest priority - so the same priority used by the kernel for its tick interrupt?
Are you using the assembly wrappers for your interrupts?

Regards.


RE: Hair-tearing time with a PI32 Stack Overflow.

Posted by Malcolm Cockcroft on June 21, 2011
OK - I was a little imprecise.

For Stack Overflow exception read vApplicationStackOverflow() call.

Th idle task pxTopOfStack points into the xISRStack area.

All interrupts are run at the configKERNEL_INTERRUPT_PRIORITY.

I am using the same interupt structure as used for the example :

........
.section .FreeRTOS, "ax", @progbits
.setnoreorder
.set noat
.entuart4Wrapper


uart4Wrapper:

portSAVE_CONTEXT
jal uart4Handler
nop
portRESTORE_CONTEXT

.enduart4Wrapper

........

As far as I am aware I do no context switching in the interrupt service routines unless they occur in xQueueSendFromISR or xSemaphoreGiveFromISR functions.


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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