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

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