How tasks/Timer could wok on ARM-CM3/4

Hi all,
I am new one to poring FreeRTOS on ARM Cortex-M3/4.
Now I has already porting FreeRTOS source code to ARM Cortex-M3 without compiler error. And also I can re-target the print() to UART.
I also create one timer and one task on my main function but they seem not work. I assume that there are some features on CM4 without being enabled or set correct.
Here is I want to confirm and I am grateful if anyone could give me some suggestion.

  1. I want to know, does any doc describe what’s steps to make tasks/timer of freeRTOS work ?
  2. What’s features of CM4 need be included when running FreeRTOS system ?
    For example, for print() to UART, we need include the UART feature to CM4.
    Such kind of feature we need when make task/timer work. (ex. Systick )
  3. Or does any example code we can reference for ?

There are lots of examples in the web documentations and the [free to download] book that show how to create tasks and timers. Additionally lots of the examples in the FreeRTOS download include a ‘blinky’ style demo that does not do much other than create tasks and queues. For example https://github.com/FreeRTOS/FreeRTOS/blob/master/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_IAR/blinky_demo/main_blinky.c . This simple demo also creates a timer https://github.com/FreeRTOS/FreeRTOS/blob/master/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c

There should be no porting necessary to run the kernel on a Cortex-M, but it is necessary to create a project if we don’t already provide one. These links will help with that:


The simplest way is to get a non FreeRTOS application running on your hardware to make sure you have the linker script and start up code correct, then add in the FreeRTOS source code. It is also best to start with configASSERT() defined and stack overflow detection on. See https://www.freertos.org/FAQHelp.html

Can you say more about what your code is doing? When you the task and timer do not work, how far do you get? Does the scheduler start? You can test that by stepping through the code in the debugger, or putting a break point at the start of the highest priority task (which may be the timer task if configTIMER_TASK_PRIORITY is set to the highest possible priority, which is (configMAX_PRIORITIES - 1).

Is the tick interrupt executing? You can tell that by putting a break point in xTaskIncrementTick(), or checking the value of xTickCount in the debugger.

Thanks Richard,
I follow your suggestion to check xPortSysTickHandler(), the handler has been triggered by every 1ms after I configure the Systick.
But task/time still not work, my example is very simple as below.


=============================================================
tatic void vTestTask(void *pvParameters)
{
    while (1) {
        vTaskDelay(1000);
	printf("1s for tasks delay !!!\r\n");
	//print something for every 1 second
    }
}
void vTimerCallback( TimerHandle_t xTimer )
{
    //print something in here
    printf("20s for timer timeout !!!\r\n");
}
=============================================================
 {
    xReturn = xTaskCreate(vTestTask, FREERTOS_EXAMPLE_TASK_NAME, 
                                            FREERTOS_EXAMPLE_TASK_STACKSIZE / 
                                            sizeof(portSTACK_TYPE), (void *)NULL, 
                                            FREERTOS_EXAMPLE_TASK_PRIO, NULL);
    if ( xReturn != pdPASS )
        printf("Create Task Fail, result=%d!!!\r\n", xReturn);
    else
        printf("Create Task Sus !!!\r\n");

    //create timer
    xTimers_test = xTimerCreate
                   ( /* Just a text name, not used by the RTOS
                     kernel. */
                     "Timer",
                     /* The timer period in ticks, must be
                     greater than 0. */
                     20000, //20 second
                     /* The timers will auto-reload themselves
                     when they expire. */
                     pdTRUE,
                     /* The ID is used to store a count of the
                     number of times the timer has expired, which
                     is initialised to 0. */
                     ( void * ) 0,
                     /* Each timer calls the same callback when
                     it expires. */
                     vTimerCallback
                   );
    if ( xTimers_test != NULL )
    {   
        xTimerStart(xTimers_test,0);
        printf("Create Timer Sus !!!\r\n");
    }
    else
        printf("Create Timer Fail !!!\r\n");
}
=============================================================

I has already trace the source of FreeRTOS to look at “xTaskIncrementTick()” function, it seems the return is always pdFALSE.
Could you have any suggestion then I could verify it ? Thanks.

If you put a break point in the task, does it get hit? Likewise in the timer?

Is your printf() tread safe as your are calling it from two different tasks. The first thing I would suggest is replacing the two calls to printf (the one in the task and the one in the timer callback) with a simple increment of global variables - just to test - one variable incremented by the timer callback and the other incremented by the task. Then see if the variables get incremented.

xTaskIncrementTick() will rarely return pdTRUE because both your task and the timer task spend the vast majority of their time in the blocked state.

Hi,as a user of kernel not a developer of kernel,
excuse me for my abrupt questions ,
have you check the FreeRTOSConfig.h’s macro defines. Is there enought task stack allocated. As my experiece, if you use printf() at one task, then at least 180 words stack should be allocated to the task to guarantee no stack overflow happen.
here 1word = 4bytes.
Best Regards,
JH

Thanks Richard/JH,
After adding the assert() macro, we can fix the problem step by step when assert() happens. But I think it is not best way to do this and also all tests I do is basic of FreeRTOS. I am worried I have incorrect setting or configuration from freertosconifg.h and also have incorrect memory setting.
Any suggestion is welcome. Thanks

Using configASSERT is strongly recommended during development along with additional crucial checks like stack overflow checking.
Regarding basic FreeRTOS and build configuration the demos here


should be a good staring point. There are also plenty other examples in the net.
Good luck !

Thanks Hartmut.
Because we develop the FreeRTOS with CM3 on FPGA and use GCC to develop, that becomes more difficult for us. Now we are planing change to use KEIL MDK.
Maybe we can run the FreeRTOS on simulator with KEIL first.