Embedded Freaks..

February 10, 2009

FreeRTOS for ATMega128

Filed under: avr — Tags: — kunilkuda @ 12:01 pm

FreeRTOS is free open source RTOS that supports several architectures. You can get its source code here. This post is my port for my ATMega128 board. It may run on your board (or may not).My version is not much different from the original ATMega323 port. The things that I’ve changed are:

  • Makefile: User can include it, rather than built their own Makefile.
  • GCC flags: I added new CFLAGS and LDFLAGS to remove dead codes/unused functions. It’ll make your binaries smaller (and still works, I hope)
  • Using RTC osc as RTOS’ tick interrupt: I need precise resolution for timing. Therefore, I moved the interrupt from OCR1A to asynchronous OCR0.

Here’s some explanation about the Makefile. I’ve added main Makefile in the FreeRTOS source code, so user that’s needed to build new code just need simple Makefile, like this:

SRC = leds.c
include $(FREERTOS_DIR)/Makefile

You can compile, program, generate COFF, SREC, IHEX as usual (because I’m using the standard AVR Makefile from mfile) as long as you define the FREERTOS_DIR, like this:

$ make FREERTOS_DIR=../FreeRTOS_ATMega128 program

Take a look at the main Makefile to know which Makefile variables that you can override.

The RTOS’ tick is changed to OCR0 interrupt. My board has RTC xtal (32.768kHz) attached on it. So, I’m expecting better timing precision than the original port. Anyway, this also means that you cannot use my FreeRTOS port without RTC xtal in your board.

The settings of the OCR0 enables the RTOS running with max 512Hz tick rate. Don’t try to use it more than 512Hz. It won’t tick (it will hang on OCR0 interrupt handler).

Anyway, for the curious minds, here’s my FreeRTOS port and my sample hello world.


  1. i have just researched RTOS, exactly, im newbie. Let me ask you some question about it,
    we have many programs software to develop applications, so can you introduce me, some software which can make hex file from your source code and can easily develop RTOS application with atmega 128

    thank and best regard !

    Comment by thaidn — July 14, 2009 @ 4:44 pm

  2. its still myseft, i known to use avrstudio and winAvr. I read some doccument about freeRTOS using for atmega128. But i dont understand clearly RTOS principle. Can you tell me a simple example to know RTOS operation.
    RTOS used many pointer and complex file system. If i want develop application on other flatform, what files do i care to change?

    Comment by thaidn — July 25, 2009 @ 11:28 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: