[freertos - Open Discussion and Support] Starting a simple task

40 views
Skip to first unread message

SourceForge.net

unread,
Nov 27, 2011, 9:55:12 PM11/27/11
to SourceForge.net

Read and respond to this message at:
https://sourceforge.net/projects/freertos/forums/forum/382005/topic/4845683
By: lololabricole

Hello,

I'm currently discovering RTOS for a school project and I am trying to implement
a unique simple task printing a Hello word each 100 ms. Once I will be able
to do that, hope I will be able to begin my project...
Only PB : my task looks like beeing never starting.
I've set the heap size to 40000 ( it's useless but this is a way to be sure
it is not the PB).
My xTaskCreate function returns 1 and my code enter the scheduler without leaving
it - as expected.
I am using a freescale MCF5282 evaluation board and wodewarrior IDE.

Here is my code, I'm sure it is a stupid mistake, but I would be very glad if
someone could help me.

main.c
[code]
/* Standard includes. */
#include "support_common.h"
#include <stdio.h>

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

/*-----------------------------------------------------------*/
//prototypes
static void prvSetupHardware( void );
static void myTask1( void *pvParameters );

/*-----------------------------------------------------------*/

int main( void )
{
portBASE_TYPE creation_return;
xTaskHandle xHandleTask1;
printf("\r\nEntering main function ... \n\r");
/* Setup the hardware */
prvSetupHardware();

/* Start the reg test tasks - defined in this file. */
if(xTaskCreate( myTask1, ( signed portCHAR * ) "Task1", 50, NULL,
tskIDLE_PRIORITY+10, &xHandleTask1)==pdPASS)
printf("Task 1 was properly created\n\r");

/* Start the scheduler. */
printf("Starting scheduler...\n\r");
vTaskStartScheduler();

/* Should never get there */
printf("Error. Scheduler exited.\n\r");
for( ;; );
}


/*-----------------------------------------------------------*/

static void myTask1( void *pvParameters )
{
portTickType lastTimeRun;

for(;;)
{
vTaskDelayUntil( &lastTimeRun, 100 );
printf("Hello world !\n\r");
}


}
/*-----------------------------------------------------------*/

void prvSetupHardware( void )
{
extern void mcf5xxx_wr_cacr( unsigned portLONG );

portDISABLE_INTERRUPTS();

/* Enable the cache. */
//mcf5xxx_wr_cacr( MCF5XXX_CACR_CENB | MCF5XXX_CACR_CINV | MCF5XXX_CACR_DISD
| MCF5XXX_CACR_CEIB | MCF5XXX_CACR_CLNF_00 );
asm volatile( "NOP" ); /* As per errata. */

/* Multiply 8Mhz reference crystal by 8 to achieve system clock of 64Mhz. */
MCF_CLOCK_SYNCR = MCF_CLOCK_SYNCR_MFD( 2 );

/* Wait for PLL to lock. */
while( !( MCF_CLOCK_SYNSR & MCF_CLOCK_SYNSR_LOCK ) )
{
__asm__ volatile ( "NOP" );
}

}

/*-----------------------------------------------------------*/
[/code]

FreeRTOSconfig file

[code]
/*
FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.


***************************************************************************
* *
* FreeRTOS tutorial books are available in pdf and paperback. *
* Complete, revised, and edited pdf reference manuals are also *
* available. *
* *
* Purchasing FreeRTOS documentation will not only help you, by *
* ensuring you get running as quickly as possible and with an *
* in-depth knowledge of how to use FreeRTOS, it will also help *
* the FreeRTOS project to continue with its mission of providing *
* professional grade, cross platform, de facto standard solutions *
* for microcontrollers - completely free of charge! *
* *
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
* *
* Thank you for using FreeRTOS, and thank you for your support! *
* *
***************************************************************************


This file is part of the FreeRTOS distribution.

FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
>>>NOTE<<< The modification to the GPL is included to allow you to
distribute a combined work that includes FreeRTOS without being obliged to
provide the source code for proprietary components outside of the FreeRTOS
kernel. FreeRTOS is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for
more details. You should have received a

_____________________________________________________________________________________
You are receiving this email because you elected to monitor this topic or entire forum.
To stop monitoring this topic visit:
https://sourceforge.net/projects/freertos/forums/forum/382005/topic/4845683/unmonitor
To stop monitoring this forum visit:
https://sourceforge.net/projects/freertos/forums/forum/382005/unmonitor

SourceForge.net

unread,
Nov 28, 2011, 12:59:07 AM11/28/11
to SourceForge.net
By: xz8987f

Hello,
you are using a stack size of 50 in

xTaskCreate( myTask1, ( signed portCHAR * ) "Task1", 50, NULL, tskIDLE_PRIORITY+10,
&xHandleTask1)==pdPASS

which sounds very low to me, especially as you are using printf() which usually
uses a lot of stack.

Better use
xTaskCreate( myTask1, ( signed portCHAR * ) "Task1", configMINIMAL_STACK_SIZE+50,
NULL, tskIDLE_PRIORITY+10, &xHandleTask1)==pdPASS

SourceForge.net

unread,
Nov 28, 2011, 7:16:24 AM11/28/11
to SourceForge.net
By: lololabricole

Hi,

Thank you for your answer.

I've just tried with a stack size of [i]configMINIMAL_STACK_SIZE+50[/i] and[i]
configMINIMAL_STACK_SIZE+300[/i], but it still doesn't work.
I keep looking for what could be wrong but I still don't get it...

When setting a breakpoint into my task, the debugger never stops at the infinite
loop. I believe the program never enter the task. The question is why ?
Moreover, as this is my only task for test, I don't have any way to resume it
manually.

I' will tryto display a trace this afternoon, hoping this will help finding
what goes wrong.

Cheers !

SourceForge.net

unread,
Nov 28, 2011, 7:48:58 AM11/28/11
to SourceForge.net
By: richardbarry

I am told that the later versions of CodeWarrior have changed their stack frame
usage, and that that has introduced an incompatibility into the port.

I have some new code, but this is not tested by me, so I have no way of verifying
it:

In portasm.S, change the function ulPortSetIP:

[code]
ulPortSetIPL:
_ulPortSetIPL:
link A6,#-8
movem.l D6-D7,(SP)

move.w SR,D7 /* current sr */
move.w D7,D6 /* prepare return value */
andi.l #0x0700,D6 /* mask out IPL */
lsr.l #8,D6 /* IPL */

andi.l #0x07,D0 /* least significant three bits */
lsl.l #8,D0 /* move over to make mask */

andi.l #0x0000F8FF,D7 /* zero out current IPL */
or.l D0,D7 /* place new IPL in sr */
move.w D7,SR

move.l D6, D0
movem.l (SP),D6-D7
unlk A6
rts
[/code]

In port.c change the function pxPortInitialiseStack():

[code]
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE
pxCode, void *pvParameters )
{
*pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
pxTopOfStack--;

*pxTopOfStack = (portSTACK_TYPE) 0xDEADBEEF;
pxTopOfStack--;

/* Exception stack frame starts with the return address. */
*pxTopOfStack = ( portSTACK_TYPE ) pxCode;
pxTopOfStack--;

*pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) |
( portINITIAL_STATUS_REGISTER );
pxTopOfStack--;

*pxTopOfStack = ( portSTACK_TYPE ) 0x0; /*FP*/
pxTopOfStack--;
*pxTopOfStack = ( portSTACK_TYPE ) _SDA_BASE; /* For compatibility with
A5 relative addressing. */
pxTopOfStack -= 5; /* A5 to A1. */
*pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
pxTopOfStack -= 8; /* D7 to D0. */
return pxTopOfStack;
}
[/code]


Please let me know (through this thread) if these changes allow your task to
be started.

Regards.

SourceForge.net

unread,
Nov 28, 2011, 8:52:52 AM11/28/11
to SourceForge.net
By: lololabricole

Thanks, it works !

Just a thing, your code doesn't compile because [i]_SDA_BASE[/i] is not defined.
It works by adding this declaration at the beginning of
the [i]pxPortInitialiseStack[/i] function :

[code] extern unsigned long far _SDA_BASE;[/code]

To finish, i've just another question, unrelated to my problem.
Is there an easy way to calculate the size of the stack I need for my tasks ?
Right now, I see 2 ways to do it. The first is adjusting it aproximatively,
so my tasks run.
I could also do it manually when using functions I developped, calculating the
size of each argument passed through every function encapsulated in one another,
but when I'm using libraries (for instance stdio), that becomes much harder...

Again, thanks a lot for your answer. Your support was incredibly quick and efficient
!

Reply all
Reply to author
Forward
0 new messages