Quality RTOS & Embedded Software

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


Task seems to stop at 2nd call

Posted by Wildcard on December 31, 2007
i finally got the RTOS Code running on my SAM7S256 using gcc-tools. I tried a simple test, by having 2 processes writing to the UART.

printf("Task a creation %d \r", xTaskCreate(( void * ) test_taskA, ( signed portCHAR * ) "Task A", 500, NULL, 3, NULL ));
printf("Task b creation %d \r", xTaskCreate(( void * ) test_taskB, ( signed portCHAR * ) "Task B", 500, NULL, 3, NULL ));


static void test_taskA(void)
int i;
// taskENTER_CRITICAL(); // no solution :/


static void test_taskB(void)
int i;


The output is as follows:

Task a creation 1
Task b creation 1

The MCU hangs now and is in an "Prefetch Abort exception" endless loop.
I tried different startup codes (for Mode stack init ...) with the same result.

What could be the Problem?
Thank you very much!

RE: Task seems to stop at 2nd call

Posted by Wildcard on December 31, 2007
finally i got the command which causes the prefetch abort. It's in the portRESTORE_CONTEXT() macro in portmacro.h.

#define portRESTORE_CONTEXT()\
extern volatile void * volatile pxCurrentTCB;\
extern volatile unsigned portLONG ulCriticalNesting;\
/* Set the LR to the task stack. */\
asm volatile (\
"LDRR0, =pxCurrentTCB\n\t"\
"LDRR0, [R0]\n\t"\
"LDRLR, [R0]\n\t"\
/* The critical nesting depth is the first item on the stack. */\
/* Load it into the ulCriticalNesting variable. */\
"LDRR0, =ulCriticalNesting\n\t"\
"LDMFDLR!, {R1}\n\t"\
"STRR1, [R0]\n\t"\
/* Get the SPSR from the stack. */\
"LDMFDLR!, {R0}\n\t"\
"MSRSPSR, R0\n\t"\
/* Restore all system mode registers for the task. */\
"LDMFDLR, {R0-R14}^\n\t"\
/* Restore the return address. */\
"LDRLR, [LR, #+60]\n\t"\
/* And return - correcting the offset in the LR to obtain the */\
/* correct address. */\
"SUBSPC, LR, #4\n\t"\
( void ) ulCriticalNesting;\
( void ) pxCurrentTCB;\

Here the prefetchabort occours:

Can anyone help me now?
Thank you!

RE: Task seems to stop at 2nd call

Posted by Wildcard on December 31, 2007
Okey i found a SOLUTION :) I used the startup and linker file from the SAM7X - Eclipse Sample Projekt.
I think the Problem is, that my old startup code did support nested interrupts.

But can someone help me with an explanation what could go wrong if the startupcode supports nested interrupts?

RE: Task seems to stop at 2nd call

Posted by Richard on December 31, 2007
The startup code must either configure the IRQ handler to vector directly to the interrupt handler or vector to a common entry point that contains the context saving code. Examples are provided of both methods. In either case the first code executed after the jump must be the FreeRTOS.org context save code, not any compiler provided intermediary code. This is to ensure that the task finds the stack in exactly the state it expects when exiting an ISR.

The main reason for this is that a task can be placed into the blocked state from a call to Yield at the task level, but start executing again after being moved out of the blocked state within an ISR. In both cases it needs to have the stack popped back into the registers in exactly the same way.

You can implement nesting of interrupts by modifying the code after the saving of the context only. It is unlikely that nesting of interrupts would be required though. See http://www.freertos.org/FAQISR.html#Nest for more info.


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

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

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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