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


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) 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