Task Not Launching / LED Not Flashing

groufosse wrote on Wednesday, December 19, 2012:


I’ve managed to modify this example program to compile:

I have also added CMSIS library files that I require and everything seems to compile OK. One of the files added is
“debug_frmwrk.h” that allows me to add debug statements to output on the UART0 port of the device. This too is working.

I have removed any of the code associated with the web server and USB, just leaving in the code for the LED flashing task.
I’ve palced DBG statements in the code so I can see how far it’s getting. The code gets into the function “vTaskStartScheduler”, up to line AFTER this function call:


It executes that function, and that’s the end of it. The LED’s do not flash. In the function “vParTestInitialise”, I can enable the LED’s on my board to be ON or OFF to start, but they stay in the initialized state. Below is the code from “main” if it helps

Can someone please advise on what to try next.

Thank you, regards,

/* Scheduler includes. */
#include “FreeRTOS.h”
#include “task.h”
/* Demo app includes. */
#include “BlockQ.h”
#include “integer.h”
#include “blocktim.h”
#include “flash.h”
#include “partest.h”
#include “semtest.h”
#include “PollQ.h”
#include “GenQTest.h”
#include “QPeek.h”
#include “recmutex.h”

//gr includes
#include “debug_frmwrk.h”
#include “lpc17xx.h”


/* The time between cycles of the ‘check’ functionality (defined within the
tick hook). */
#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )

/* The toggle rate for the LED. */
#define mainLED_TOGGLE_RATE ( ( portTickType ) 1000 / portTICK_RATE_MS )

/* Task priorities. */
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainUIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )

/* The WEB server has a larger stack as it utilises stack hungry string
handling library calls. */

/* The message displayed by the WEB server when all tasks are executing
without an error being reported. */
#define mainPASS_STATUS_MESSAGE “All tasks are executing without error.”


* Configure the hardware for the demo.
static void prvSetupHardware( void );

* Very basic task that does nothing but use delays to flash an LED.
static void prvFlashTask( void *pvParameters );


int main( void )
/* Configure the hardware for use by this demo. */

/* Start the standard demo tasks.  These are just here to exercise the
kernel port and provide examples of how the FreeRTOS API can be used. */
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
    vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
    vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
    vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
    vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
    _DBG_(“Demo tasks started.”); 

/* Create the simple LED flash task. */
xTaskCreate( prvFlashTask, ( signed char * ) “Flash”, configMINIMAL_STACK_SIZE, ( void * ) NULL, mainFLASH_TASK_PRIORITY, NULL );
    _DBG_(“xTask created.”); 

    /* Start the scheduler. */

    /* Will only get here if there was insufficient memory to create the idle
    task.  The idle task is created within vTaskStartScheduler(). */
for( ;; );

void vApplicationTickHook( void )
    static unsigned long ulTicksSinceLastDisplay = 0;
    _DBG_(“In vApplicationTickHook.”); 

/* Called from every tick interrupt as described in the comments at the top
of this file.
Have enough ticks passed to make it time to perform our health status
check again? */
if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
/* Reset the counter so these checks run again in mainCHECK_DELAY
ticks time. */
ulTicksSinceLastDisplay = 0;

/* Has an error been found in any task? */
if( xAreGenericQueueTasksStillRunning() != pdTRUE )
_DBG_(“An error has been detected in the Generic Queue test/demo.”);
else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
_DBG_(“An error has been detected in the Peek Queue test/demo.”);
else if( xAreBlockingQueuesStillRunning() != pdTRUE )
_DBG_(“An error has been detected in the Block Queue test/demo.”);
else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
_DBG_(“An error has been detected in the Block Time test/demo.”);
    else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
        _DBG_(“An error has been detected in the Semaphore test/demo.”);
    else if( xArePollingQueuesStillRunning() != pdTRUE )
        _DBG_(“An error has been detected in the Poll Queue test/demo.”);
    else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
        _DBG_(“An error has been detected in the Int Math test/demo.”);
    else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
    _DBG_(“An error has been detected in the Mutex test/demo.”);

static void prvFlashTask( void *pvParameters )
    _DBG_(“In prvFlashTask.”); 

    portTickType xLastFlashTime;

/* We need to initialise xLastFlashTime prior to the first call to
vTaskDelayUntil(). */
xLastFlashTime = xTaskGetTickCount();

/* Simply toggle the LED between delays. */
vTaskDelayUntil( &xLastFlashTime, mainLED_TOGGLE_RATE );
vParTestToggleLED( 0 );

void prvSetupHardware( void )
   _DBG_(“In prvSetupHardware.”); 
/* Configure the LEDs. */


void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
   _DBG_(“In vApplicationStackOverflowHook.”); 

/* This function will get called if a task overflows its stack. */

( void ) pxTask;
( void ) pcTaskName;

for( ;; );

void vConfigureTimerForRunTimeStats( void )
    const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;

    _DBG_(“In vConfigureTimerForRunTimeStats.”); 

/* This function configures a timer that is used as the time base when
collecting run time statistical information - basically the percentage
of CPU time that each task is utilising.  It is called automatically when
the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set
to 1). */

/* Power up and feed the timer. */
LPC_SC->PCONP |= 0x02UL;
LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);

/* Reset Timer 0 */

/* Just count up. */

/* Prescale to a frequency that is good enough to get a decent resolution,
but not too fast so as to overflow all the time. */
LPC_TIM0->PR =  ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;

/* Start the counter. */
  _DBG_(“Exiting vConfigureTimerForRunTimeStats.”); 


edwards3 wrote on Wednesday, December 19, 2012:

I don’t think you issue is FreeRTOS related (yet) because xPortStartScheduler is not called called after portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() is called.

If portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() is causing a problem then just remove the run time stats for now. Set configGENERATE_RUN_TIME_STATS to 0 and remove the definitions of portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE().

Do you get into xPortStartScheduler then?

Are any of the drivers  you are using making use of the heap?

groufosse wrote on Wednesday, December 19, 2012:

Thanks again!

I should mention that I have read the RTOS page on: http://www.freertos.org/RTOS-Cortex-M3-M4.html

I had modified the startup file to include a start-up reset handler that included a call to systemInit(), but now changed that back to the original “cstartup_M.s” and simply added a call in main to systemInit(). Now the program compiles, runs and is getting into the function “vApplicationTickHook”

The debug statement is telling me it gets to here:
/* Has an error been found in any task? */
if( xAreGenericQueueTasksStillRunning() != pdTRUE )
_DBG_(“An error has been detected in the Generic Queue test/demo.”);

Also, I do not use any drivers (unless that includes the UART); I’ve only included the header file “debug_frmwrk.h” that sends stuff out the UART.


      _DBG_(“Setting: xSchedulerRunning = pdTRUE”);

xSchedulerRunning = pdTRUE;
xTickCount = ( portTickType ) 0U;

/* If configGENERATE_RUN_TIME_STATS is defined then the following
macro must be defined to configure the timer/counter used to generate
the run time counter time base. */

/* Setting up the timer tick is hardware specific and thus in the
portable interface. */
if( xPortStartScheduler() != pdFALSE )
/* Should not reach here as if the scheduler is running the
function will not return. */
            _DBG_(“In: xPortStartScheduler() != pdFALSE”); 
/* Should only reach here if a task calls xTaskEndScheduler(). */
            _DBG_(“In: (else) xPortStartScheduler() != pdFALSE”);

    _DBG_(“Bailing out.”); 
I’ve set run_time_stats define to 0 so it won’t run.

groufosse wrote on Wednesday, December 19, 2012:

It’s working !!!!    8~)

Now I can continue reading Richard berry’s books:
“Using the FreeRTOS Real Time Kernel - A Practical Guide.pdf”
“FreeRTOS Reference Manual.pdf”

I will now be able to test code as I go through the book.

Thank you!