Quality RTOS & Embedded Software

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


Loading

Stability bug in avr32_uc3 port?!

Posted by Mike on December 18, 2012

I believe there is a bug in the avr23_uc3 gcc port. I am running on AT32UC3A0512 (evk1100).

The following is the exception handler for the "scall" instruction which is issued to perform a context switch:

__attribute__((__naked__)) void SCALLYield( void );
__attribute__((__naked__)) void SCALLYield( void )
{
/* Save the context of the interrupted task. */
portSAVE_CONTEXT_SCALL();
vTaskSwitchContext();
portRESTORE_CONTEXT_SCALL();
}

The problem, I believe, is that the AVR "scall" instruction/exception does not automatically disable interrupts as other exceptions/interrupts do. This means that interrupts are enabled during this critical context switch code. A poorly timed interrupt can potentially mess up FreeRTOS internal data structures. I fixed it as follows, and my problem went away:

__attribute__((__naked__)) void SCALLYield( void );
__attribute__((__naked__)) void SCALLYield( void )
{
/* Save the context of the interrupted task. */
vPortEnterCritical();
portSAVE_CONTEXT_SCALL();
vTaskSwitchContext();
portRESTORE_CONTEXT_SCALL();
vPortExitCritical();
}

Can someone please verify that this is correct?

Thanks!

-Mike

RE: Stability bug in avr32_uc3 port?!

Posted by Richard on December 19, 2012
A few comments:

1:
Note that, as mentioned on the FreeRTOS website, the UC3 port in the FreeRTOS download targets the older first issue UC3 chips. If you are using production chips now you can get the code from Atmel which is in their ASF package (http://asf.atmel.com).

2:
Calling the enter critical function (as in your code snippet above) will change the MCU context *before* you have saved the context, which in nearly all cases is going to cause issues.

3:
Having looked at the code I'm note sure there is an issue because the portSAVE_CONTEXT_SCALL(); itself enters a critical section (but after the context has been saved).

Regards.

RE: Stability bug in avr32_uc3 port?!

Posted by Mike on December 20, 2012

Hi Richard, thanks you for your reply... I am much obliged!

1. Just FYI, I downloaded the latest ASF package before posting here. (I figured this might be the best place to get an answer and it looks like I was right. ;-)

2. I'm not sure what you mean about enter critical function changing the MCU context. All it does is disable interrupts and increment the nesting count

3. I had not noticed the enter critical section in portSAVE_CONTEXT_SCALL(), so I was wrong in my assessment. Thank you for pointing that out!

There is still a mystery, however:

It so happens that I had an interrupt that wasn't being cleared properly and was interrupting almost constantly. The result, was an overflow of the idle task stack. The bigger I made the stack, the longer it would run, but it would always eventually overflow.

My *fix*, however misguided, did resolve the stack overflow problem. I have been running without issue for more than a week now.

Fixing the interrupt issue hides the stack problem, but I believe it still exists. It is rare for an interrupt to occur at precisely the right time but it seems, based on my experience, that it must still be possible. I have not been able to discover why, however, and I wonder if you might have any insight.

Thank you so much for your time and attention!

-Mike


[ 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.


Careers

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

Renesas

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