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


Context Saving - Restoring with Cortex M3

Posted by damien on March 6, 2012
Hi all,

Recently , I started using the Cortex M3 GCC port.

My question is connected to the context saving - restoring during interrupt servicing :

According to the Cortex M3 architecture and my understanding: Only register from R4 until R11 has to be saved. Other registers are automatically stacked - unstacked by the processor and the NVIC before - after Interrupt routine execution.

I started my project using the Stellaris CORTEX_LM3Sxxxx_Eclipse demo :

I found the piece of code doing the job for the FreeRTOS kernel scheduling systick timer interrupt, but for other interrupt function used by the demo (void vT2InterruptHandler( void ) for example),

I have not been able to find the context saving - restoring code or any kind of key word which could tell to the compiler the present function is an interrupt function (__attribute__ ((interrupt)))

How this context saving - restoring has to be done for handling ISR with FreeRTOS - Cortex M3 or if not necessary, why ?

Thanks for any explaination


From my understanding,

RE: Context Saving - Restoring with Cortex M3

Posted by Richard on March 6, 2012
Context saving and restoring is only performed from the PendSV interrupt. If an application interrupt wants to force a context switch, it pends the PendSV interrupt (FreeRTOS provides macros to do this, the application does not have to write to the core directly), and the PendSV interrupt executes when all higher priority interrupts (potentially nested) have executed.

Look at the implementation of the PendSV interrupt in port.c.


RE: Context Saving - Restoring with Cortex M3

Posted by damien on March 6, 2012
Hi Richard,

Thanks for reply, and thanks for helping a no specialist of Cortex M3 architecture

You have right, PendSV interrupt is implemented with a "full" saving of register (R4-R11).

Now, supposing any different interrupt source (Tim2 and Tim3, as used in the demo CORTEX_LM3Sxxxx_Eclipse, I would like to add my interrupt for RS232 Comm) :

Do I have to take care about copy - restoring these register (R4-R11) when branching - leaving interrupt ?

I suppose Yes but I'm surprised to not find this code in the demo.
If I'm wrong, what is the reason ?

My previous experience with the STR91X port, from my memory -> was a piece of code in assembler doing this copy - restoration of all Register before branching - returning the interruption.

Thanks in advance.


RE: Context Saving - Restoring with Cortex M3

Posted by Dave on March 6, 2012
You don't have to do anything except write standard C code, the kernel takes care of everything. Context switched only ever happen in the PendSV handler, never anywhere else.

Look at the interrupt service routine section of a documentation page related to a Cortex demo.

[ 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