How to port FreeRTOS to AT91SAM9G20

brilliantdt wrote on Sunday, April 19, 2015:

Hi,
I am trying to port FreeRTOS to AT91SAM9G20. It is based on the integration of an ARM926EJ-S processor. I have managed the AT91SAM9G20 development board normally in the IAR without FreeRTOS, but how can I port FreeRTOS to AT91SAM9G20. Who can give me detailed instructions? Thanks a lot!!!

rtel wrote on Sunday, April 19, 2015:

I would suggest starting with the existing SAM9 IAR demo:
http://www.freertos.org/ARM9-AT91SAM9-RTOS-Demo.html

then re-targeting to your hardware:
http://www.freertos.org/porting-a-freertos-demo-to-different-hardware.html

Things to watch out for:

Make sure you install the FreeRTOS interrupt handlers, exactly as they are in the existing SAM9 board.

If the timer peripherals are different on your hardware to the existing SAM9 demo then you will have to update the prvSetupTimerInterrupt() function in port.c.

Regards.

brilliantdt wrote on Tuesday, April 21, 2015:

Hi,
Thanks for your reply. However, after I modified the demo and ported it to the AT91SAM9G20, I found some problems.
First,if I create two simple tasks as the following, only one task can be running(In the following example, only led1 is light). And the task can only run two times, then stops(Because “LED1” can only be printed two times).
/-----------------------------------------------------------/
xTaskCreate( vLED0Task, ( signed portCHAR * )“LED0”, configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
xTaskCreate( vLED1Task, ( signed portCHAR * )“LED1”, configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
vTaskStartScheduler();
/-----------------------------------------------------------/
static void vLED0Task( void *pvParameters )
{
for( ;; )
{
LED0_ON;
printf(“LED0\n”);
}
}

static void vLED1Task( void pvParameters )
{
for( ;; )
{
LED1_ON;
printf(“LED1\n”);
}
}
/
-----------------------------------------------------------*/

I do not think I have correctly modified the demo and ported it the AT91SAM9G20, but what is the problem with my codes? which codes should I modify? I hope for detailed instructions. Tnanks very much!

rtel wrote on Tuesday, April 21, 2015:

My first suggestion is to remove the calls to printf() - unless you are
100% sure they are thread safe and know how they are implemented (for
example, do they call malloc(), where is the output sent, which drivers
are used to perform the output, etc., is newlib being used which would
require specific settings in FreeRTOSConfig.h, etc.). You can add
printf() back in, which the necessary precautions, once you are sure the
RTOS port is running correctly.

Change the task implementation so it does nothing more than increment a
volatile variable that can be inspected in the debugger. Each of the
two tasks increments a different volatile variable - so if both tasks
are running the two variables will increment at a very fast rate.

If you then find only one of the two variables is incrementing it is
likely the tick interrupt is not executing. That can be checked by
placing a break point in the timer ISR, or by viewing the xTickCount
variable in the debugger (inside the FreeRTOS/Source/task.c file).

If the tick count is not incrementing then check the timer is being
initialised correctly and its IRQ handler installed correctly. That can
be done without the RTOS first just a main() function that does nothing
but initialise the timer, then sit in an infinite loop. The timer’s ISR
can then be set to just increment a variable, again so you can see if it
is executing at the expected frequency.

Regards.