Quality RTOS & Embedded Software

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


75x GCC isr problems/STR71x port

Posted by DR1 on March 2, 2008

I'm working on a STR71X port for GCC/Rowley.

I started with the 75x/GCC port as a base. What I noticed is that the interrupt system does not work. I'm using the code in crt0_STR75x_FreeRTOS.s to manage context save/restore on entry/exit from interrupts. It seems that the portSAVE_CONTEXT macro leaves the user/system mode stack pointer pointing in an unsafe area (namely, into the area of the interrupted task's stack where it's register contents will be stored). Then, later, the IRQ_to_SYS macro switches the processor into system mode, and then calls the handler (C code) to do some work with an unsafe stack pointer (R13_usr).

Here is the chronology:
1) An IRQ interrupt occurs, processor goes to IRQ mode and uses SP_irq

2) The IRQ handler, first thing, calls portSAVE_CONTEXT which stores all of the user mode registers onto the system mode stack. You'll notice that R13_usr is the same before and after the call to portSAVE_CONTEXT, but the fucntion did in fact store necessary data on the user mode stack. This is where the stack pointer is corrupted.

3) The IRQ handler (and hardware) vectors the processor to a IRQ handler (there are 32 of these, like WAKUPIRQHandler)

4) This intermediate handler changes the mode to system mode, where the stack pointer is now R13_usr, which was left pointing at an unsafe memory area.

5) This intermediate handler then calls a c-code handler, which can do whatever. If this handler uses the stack at all (which it will) then the stored registers (stored durint portSAVE_CONTEXT) are corrupted.

As a quick fix, I added the following lines to the end of the portSAVE_CONTEXT macro:

/*; Correct sp_usr */

What I want to know is if anyone has used the 75x/GCC port, using the crt0_STR75x_FreeRTOS.s file from the demo. I'm wondering if I made some mistake or if that port really has this flaw.

Thanks in advance,


RE: 75x GCC isr problems/STR71x port

Posted by Richard on March 3, 2008
Please look at the UART0 handler which demonstrates how interrupts should be handled. UART0_ADDR points to the address of vSerialISR which is a standard C function - the macros that change between modes should not be used. If you want to use one of the other interrupts then simply replace the vectored to address with a standard C function to handle the interrupt.


RE: 75x GCC isr problems/STR71x port

Posted by DR1 on March 3, 2008

Thanks for the quick reply. I see now, ISRs are run in ISR mode on the ISR stack, no problem, simple and fast.

Have a good day,


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

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

Latest News

Version 10.1.0 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.


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


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