Quality RTOS & Embedded Software

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


Loading

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

Damien



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.

Regards.

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.

damien








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