Using ATmega323 port with ATmega16

joh4289 wrote on Monday, May 12, 2014:

Hi,

I’m trying to use the ATmega323 port with my ATmega16 controller. I’m using FreeRTOSv8.0.1 on Linux with avr-gcc and am following this guide:
http://www.freertos.org/porting-a-freertos-demo-to-different-hardware.html
The first two steps are working, I modified vParTestInitialise() however, since my LEDs are on PORTC and I set configTOTAL_HEAP_SIZE to 700 to fit the 1k SRAM.
I have problems with step three. This is working:

// Code goes here …
short main( void )
{
prvIncrementResetCount();

/* Setup the LED's for output. */
vParTestInitialise();

/* Create the standard demo tasks. */
/// works

// either these are working
//vStartIntegerMathTasks( tskIDLE_PRIORITY );
//vStartRegTestTasks();

// or this is working
//vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );

// or this
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );


/* Create the tasks defined within this file. */
xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );

/* Create the co-routines that flash the LED's. */
vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );

/* In this port, to use preemptive scheduler define configUSE_PREEMPTION
as 1 in portmacro.h.  To use the cooperative scheduler define
configUSE_PREEMPTION as 0. */
vTaskStartScheduler();

return 0;

}

As the comments indicate I can either use vStartIntegerMathTasks and vStartRegTestTasks or vStartPolledQueueTasks or vAltStartComTestTasks. If I use more at the same it doesn’t work, meaning no LEDs are flashing. I modified vErrorChecks for each case to check if the are operating correctly and they are fine except vAltStartComTestTasks. I don’t have a Com inteface so I didn’t expect that to work anyway.
Now what I don’t understand: If I comment out vStartFlashCoRoutines nothing works anymore. I expected to still have the LED flashing which is controlled by vErrorChecks but it just doesn’t.
Since I haven’t used coroutines before it’s hard for me to anaylze where this behavior comes from. I looked at the code, but I don’t see it doing anything concerning the LED controlled by vErrorChecks.

Another thing:
I want to check that my stuff fits int the RAM. With avr-size I get:
text data bss dec hex filename
9880 82 865 10827 2a4b rtosdemo.elf

Am I correct, that I should be fine if the sum of data and bss is smaller than 1000?
(my controller has 1kByte of SRAM)

Hope someone can help me. Thanks in advance!
(Sorry the code isn’t highlighted properly, I looked at the formatting help, but I couldn’t figure out how to wrap it)

rtel wrote on Monday, May 12, 2014:

1K of RAM is really a very small amount to use a multi tasking system where each task has its own stack.

If I use more at the same it doesn’t work, meaning no LEDs are flashing

So presumably you are running out of heap. Are you checking the return value of xTaskCreate() and do you have a malloc failed hook defined?

If I comment out vStartFlashCoRoutines nothing works anymore

If you have not created any co-routines did you also set configUSE_CO_ROUTINES to 0 in FreeRTOSConfig.h? I think it is necessary.

Am I correct, that I should be fine if the sum of data and bss is smaller than 1000?

If you are using heap_1.c, heap_2.c or heap_3.c then yes, I think that is correct.

Regards.

joh4289 wrote on Monday, May 12, 2014:

I think too, that I’m running out of heap, if I use more tasks.
Setting configUSE_CO_ROUTINES to 0 in FreeRTOSConfig.h pointed me in the right direction. Turned out I had vCoRoutineSchedule in vApplicationIdleHook. Commenting it out solved my problem.
I think I’ll set configUSE_IDLE_HOOK to 0 too.

Thx!

joh4289 wrote on Monday, May 12, 2014:

How to mark this as solved?

rtel wrote on Monday, May 12, 2014:

No need to mark it as solved - I don’t think that is possible.