Changes for ATMega128

rtel wrote on Friday, July 15, 2005:

[moved from older thread]

I am trying to run freeRTOS on the ATmega128 chip. I am using an ATmega128 Development Board from PRLLC ( I have previous microcontroller experience with a Motorola 68HC11 chip and a PIC18LF448. However, this is my first time working with an RTOS and trying to port it to a chip. 

I could use any help on setting up freeRTOS to run on this chip. I am using WinAVR v.20040404 for my development tools. I have perused the freeRTOS website, and should be able to find any reference made to it.

I have tried to make the demo program freeRTOS comes with using a make all command in Programmer’s Notepad, which comes as part of the WinAVR environment. Everything compiles fine except I receive errors concerning undeclared variables in relation to serial.c

In conclusion, any help or pointing in the right direction would be much appreciated. Thank you for the time and help,

Josh Wittmier

rtel wrote on Friday, July 15, 2005:

I know several people have FreeRTOS running on a 128, so this should not be a problem.

The compile error you see when attempting to compile for the ATMega128 is due to the fact that the ATMega128 has two serial ports so the #defined constants have slightly different names to distinguish between the two com ports.

Do you have a decent debug system that allows you to step through the code?

Here is my suggested approach:

1) Change the CPU definition at the top of the makefile  I suspect you have done this already.  As downloaded it is set for MCU = atmega323.

2) Take a look in FreeRTOSConfig.h (same directory as the makefile) to ensure the settings are correct for your board.  The clock frequency being the most likely thing that needs changing.  The heap size can also be increased on the ATMega128 but dont worry about that for now.

3) Im hoping your demo board has some LEDs? 

Take a look at the file Demo/AVR_ATMega323_WinAVR/partest/partest.c. 

This file has some simple code to set, clear and toggle LEDs.  The port to which the LEDs are attached is unlikely to be the same for your board as the STK500 for which this file is configured, so this will require updating.  Also for now comment out the lines vTaskSuspendAll() and xTaskResumeAll(), as these cannot be used without the scheduler running.

4) Comment out the lines in serial.c that are causing you the compile problems (alternatively find the correct constants to use to correct the error).

5) Write a very simple program that just turns LEDs on and off to ensure the functions in step (3) are working.   You can do this in the main.c file along the lines of:

portSHORT main( void ) // existing code
____prvIncrementResetCount(); // existing code

____/* Setup the LED’s for output. */
____vParTestInitialise(); // existing code

____/* Add a new infinite loop here so the rest of
____the main() code never gets reached. */
____for( ;; )
________unsigned long ul;

________vParTestToggleLED( 0 );
________for( ul = 0; ul < 0xfffff; ul++ );
____/* Rest of code will not get executed. */

6) When you are happy that the partest files are working, put back the lines that were commented out.

7) Now we want a very simple program that does nothing but flash leds using the kernel.  In a clean main.c file (i.e. remove any code added so it is as per the download), comment out every line that creates a task other than the line that creates the flash tasks.

//____vStartIntegerMathTasks( tskIDLE_PRIORITY );
//____vAltStartComTestTasks( mainCOM_TEST_PRIORITY, //____mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
____vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
//____vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );

//____xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );

The flash tasks should flash LEDs 0, 1 and 3 as described on the WEB site.

8) Compile the code, download, see what happens!  the flash tasks should run along with the idle task.

If you can step through the code then it is best to set for cooperative scheduling (set configUSE_PREEMPTION to 0 in FreeRTOSConfig.h).

Once this very simple system is running the application can be built up.


nobody wrote on Monday, July 18, 2005:

Thanks for the help.  All of that works great.

nobody wrote on Thursday, July 21, 2005:

Porting to Mega128 I’ve done following things:

- created new ATMega 128 directory under potable/gcc
- copied port.c and portmacro.h from Mega323 into it
- changed timer functions to my needs (reload), I think in 2.6 you also had to change timer to timer1 etc.
- changed portable.h to include the right portmacro.h if __AVR_ATmega128__ is defined (I think this is set by gcc if you set the correct MCU value in makefile)
- copied FreeRTOSConfig.h to my project directory and customized it

I think that was all…