freeRTOS and libraries for AVR ATmega with Eclipse IDE

I’ve created a Sourceforge project as a place to host all my current tools and working environment. The Sourceforge site is now 4 years old, and there’s a GitHub site too, which is now the most up to date repository

Preferred: Github freeRTOS & libraries for AVR ATMEGA

Secondary: Sourceforge freeRTOS & libraries for AVR ATMEGA

The Sourceforge repository has become so complex, with so many libraries, I thought that it was about time to make a simple version, which has the minimum implementation to get started. No additional libraries included. One timer option, using the watchdog timer. One heap option, using avr-libc malloc. One example application, just a blink with two tasks, for Uno, Mega, and Goldilocks boards.

Github minimum AVRfreeRTOS

The thing about open source. Sometime you have to give back.

Things I’m really happy about:

  • Arduino Uno family ATmega328p, Freetronics EtherMega (Arduino Mega2560), and Goldilocks ATmega1284p, scheduling and IO works.
  • Being able to use any Timer on the AVR as the system Tick. In practice this means Timer0 on 328p (Arduino Uno), Timer3 on 2560 (Arduino Mega) and 1284p (Pololu SVP) and Timer2 on 1284p with 32.768kHz watch crystal (Freetronics Goldilocks). The watchdog timer has also been implemented, and if there is no critical need for accurate timing, this is the lowest resource impact system tick.
  • Converting all of the relevant libraries to be friendly to a RTOS system. No delay busy-wait loops etc. Everything defers to (is interruptible by) the scheduler when waiting, or is driven from interrupts.
  • Having many finished projects, that are good demonstrations of lots of AVR and freeRTOS capabilities.
  • Having the Sparkfun LCD Shield working properly, with printf string formatting.
  • Having the Rugged Circuits QuadRAM 512kByte and MegaRAM 128kByte RAM extensions working on ATmega2560.
  • Porting ChaN FatF microSD card support for a variety of uSD shield cages.
  • Porting Wiznet W5100, W5200, and W5500 drivers for Arduino Ethernet shields.
  • Porting Wiznet and uIP DHCP and HTTP applications, creating options for implementing a basic web server.
  • Properly implementing semaphores for access to resources (ports, interfaces, ADC, LCD).
  • Properly implementing queues for transferring data between tasks (threads).

The repository of files on Sourceforge freeRTOS & libraries for AVR ATMEGA is a working collection for a freeRTOS based platform using the AVR-GCC and AVRDUDE platform. The development environment used was Eclipse IDE.

With the Eclipse IDE the C Development Environment (CDE), and the AVR plug-in are both needed. It is assumed that the AVR avr-libc libraries are installed.

The freeRTOS folder contains the most recent version 8.2.3 of freeRTOS, but it has been abridged down to only those files relevant for AVR GCC. The port.c file has been extensively modified to allow the use of either of the 328p Timer0 or Timer1 timers. And, the use of Timer3 on the Pololu SVP which has uses a 1284p. Timer 3 for Arduino Mega using a 2560 also works. Timer2 support has been added for the Freetronics Goldilocks and its 32,768kHz crystal. A Real Time system_tick is added using time.h functionality added to the system libraries described below.

The freeRTOSBoardDefs.h file contains most of the variables that you’ll need to change regularly.

There are some relevant and often used libraries added to the basic freeRTOS capabilities.

  • lib_io: contains often used I/O digital and ADC routines borrowed from Pololu.
  • lib_io: contains the tools to use the TWI (non-trademarked I2C) bus. It contains integrated interrupt driven master and slave routines
  • lib_io: contains the tools to use the SPI bus.
  • lib_io: contains routines to drive the serial interface. there are three versions; avrSerial for use before the freeRTOS scheduler has been enabled, and xSerial for use during normal operations. xSerial is interrupt driven and uses an optimised ring buffer. xSerialN is further generalised to allow multiple simultaneous serial ports.
  • lib_ext_ram: contains routines to drive the Rugged Circuits QuadRam on Arduino Mega2560, or Freetronics EtherMega.
  • lib_util: Optimised CRC calculations.
  • lib_util: Extended alpha (string) to integer (binary, octal, decimal, hexdecimal) conversion.
  • lib_time: Real time calculations, from avr-libc upstream, providing esoteric time and date calculations.
  • lib_rtc: drivers for the DS1307 RTC using I2C.
  • lib_fatf: contains ChaN’s FatF FAT32 libraries for driving the microSD card.
  • lib_iinchip: contains the W5100 drivers and the W5200 drivers from Wiznet.
  • lib_inet: contains a DHCP, and HTTP implementation.
  • lib-uIP: contains the uIP implementation derived from Contiki2.7, implemented on MACRAW mode of W5100/W5200, and extensible.
  • lib_ft800: contains optimised drivers for the Gameduino2, a FTDI FT800 implementation, with LCD and touch screen support.

Some more recent posts are here:

Arduino AVRfreeRTOS

Goldilocks Analogue Synthesiser

Goldilocks Analogue Prototyping 4

Melding freeRTOS with ChaN’s FatF & HD44780 LCD on Freetronics EtherMega

Rugged Circuits QuadRAM on Freetronics EtherMega

Quick review of Freetronics EtherMega

Description of the AVR Pong multi-processor game.

Additional steps to use the Mega2560

EtherMega (Arduino Mega2560) and FreeRTOS

I sell on Tindie

Step-by-step Instructions

Our Destination:

On completing these instructions you should have an Eclipse IDE (Integrated Development Environment) installed with all relevant libraries installed, to use the freeRTOS, and the libraries I’ve modified, to build projects (Eclipse term for a set of code) of your own.

We’re Assuming:

These instructions are based on an Ubuntu LTS install, but the path to the destination is not complex, and can be roughly followed for any installation platform.

Step 0. As usual on an Ubuntu (Debian) system, refresh the software sources.

sudo apt-get update

Step 1. Install the AVR Libraries.

Together, avr-binutils, avr-gcc, and avr-libc form the heart of the Free Software toolchain for the Atmel AVR microcontrollers. They are further accompanied by projects for in-system programming software (uisp, avrdude), simulation (simulavr) and debugging (avr-gdb, AVaRICE).
sudo aptitude install avr-libc avrdude binutils-avr gcc-avr gdb-avr

Step 2. Install the Arduino environment.

Doesn’t hurt to have the Arduino environment available. It can be used for programming boot-loaders (using AVR-ISP code), and generally for checking health of equipment, using known good example code.

This will pull in some extra libraries that the Arduino platform needs.

sudo aptitude install arduino


Step 3. Install the Eclipse IDE.

It is not necessary to use or install an IDE to develop with freeRTOS, or with any other system. It is easy to use makefiles and the command line with avr-gcc and avrdude. In fact, I didn’t use Eclipse for a long time. And, when I first started to use it, it felt very unnatural and clumsy.

However, now I’ve been using it for some time I highly recommend it, for the ability to see deeper into the code (definitions are detailed on mouse over), and to compare (live differences) and roll-back code to any step of your editing process.

Again, installation is easy with Ubuntu (Debian), but it can take a while. Lots of things get installed along with it.

sudo aptitude install eclipse

Step 4. Select the C & C++ development tools within Eclipse.

Eclipse is a Java based platform, but it works just as well with C, and C++, as it does with a wide variety of languages. Getting the C Development Tools (CDT) is the first step to a C environment that we’ll be using.

Open Eclipse, and lock it to your launcher. You’ll be using it frequently.

Using the Menus, click:

Help>>Install New Software…>>Add…

CDT Indigo

Select only “CDT Main Features”, and install these plugin development tools.

Step 5. Select the AVR development environment within Eclipse.

The AVR environment includes direct access to the avrdude downloading tool for one-click programming of your AVR devices.

Using the Menus, click:

Help>>Install New Software…>>Add…

AVR Plugin

Select “CDT Optional Features”, and install these plugin development tools.

Step 5c. Select C/C++ Perspective

First you need to select the right perspective, being C/C++. Top right there is a button showing “Java”. Just to the left is a button (like a window) for selecting perspective. Select


When that is finished, you should have Eclipse menu button containing a AVR* with a green down arrow. That is the button used to program the device.

Step 6. Define a freeRTOS static library project.

There are lots of short cuts, and alternative ways to achieve things using context sensitive menus in Eclipse. I’ll concentrate on the top menu bar options, though you can get most things from a context menu click in the right window.

File>>New>>C Project: AVR Cross Target Static Library: Empty Project

A static library project is never run by itself. It is always linked to by other projects, called AVR Cross Target Applications.

Give the project a name (perhaps freeRTOS82x).

Now a project will apear in the “Project Explorer” window. Select it. We are going to set some options relating to this project.

Project>>Build Configurations>>Set Active>>Release


AVR:Target Hardware: MCU Type: ATmega328p (or other depending on hardware)

AVR:Target Hardware: MCU Clock Frequency: 16000000 (for Arduino hardware or other depending on your hardware)

C/C++ Build: Configuration: [All Configurations] (make sure this is set for all following configurations)

C/C++ Build: Environment: AVRTARGETFCPU: 16000000

C/C++ Build: Environment: AVRTARGETMCU: atmega328p

C/C++ Build: Settings: AVR Compiler: Optimisation: Other Optimisation Flags: -ffunction-sections -fdata-sections -mcall-prologues -mrelax (and use -Os or -O2)

Now we are going to add just the freeRTOS files, from the subdirectory within the file that you have downloaded from Sourceforge, and extracted somewhere sensible.

File>>Import…>>General:File System

Select the “into folder” as the project name you just created, and “Select All” for the import on the freeRTOS subdirectory. That should import the entire freeRTOS system. Spend some time browsing, if you like.

NOTE. Do NOT import the entire contents of the file. At this stage just import contents of the freeRTOS subdirectory.

Now we define the include library for the build. Remember to select [All Configurations] first.

Project>>Properties>>C/C++ Build>>Settings: AVR Compiler: Directories 

Add the from the “Workspace…”: freeRTOS82x/include


Now there are fouralternative memory management routines, explained in the freeRTOS documentation. We are going to use the heap_2.c version, so we need to exclude the other three files from the build. In the project explorer RIGHT CLICK (context menu) each one then exclude them.




Resource Configurations>>Exclude from Build…: Select All

Following this step, it should be possible to compile the library.

Project>>Build All

If there are any ERRORS, then go back and check the configurations for the project. Sometimes they may be changed, forgotten, or otherwise different from what you expected.

There will be some WARNINGS, relating to the usage of different Timers. I added these warnings to keep these things front of mind, as depending on which hardware I’m using the ./include/FreeRTOSBoardDefs.h file needs to be managed to suit.

Step 7. Define an Application Project.

An Application will generate the final hex code that you upload to the AVR with avrdude. This final code is created from the freeRTOS static library code generated above, together with code contained in the avr-libc, and any other linked projects.

We are going to import the UnoBlink or MegaBlink project as it makes a good example. Without a display, or real-time-clock module, it will only flash a LED. But, least we know it is alive.

To get started create a new project as below.

 File>>New>>C Project: AVR Cross Target Application: Empty Project

Give the project a name (perhaps MegaBlink or retrograde).

Now a project will appear in the “Project Explorer” window. Select it. We are going to set some options relating to this project.

Project>>Build Configurations>>Set Active>>Release



Configuration name: Arduino or Freetronics 2010

Programmer Hardware: Atmel STK500 Version 1.x firmware

Override default port: /dev/ttyUSB0 (FTDI USB) OR /dev/ttyACM0 (AVR USB)

Override default baudrate: as or if required.

AVR:Target Hardware: MCU Type: ATmega328p (or other depending on hardware)

AVR:Target Hardware: MCU Clock Frequency: 16000000 (or other depending on hardware)

C/C++ Build: Configuration: [All Configurations] (make sure this is set for all following configurations)

C/C++ Build: Environment: AVRTARGETFCPU: 16000000

C/C++ Build: Environment: AVRTARGETMCU: atmega328p

C/C++ Build: Settings: AVR Compiler: Directories: “${workspace_loc:/freeRTOS82x/include}”

C/C++ Build: Settings: AVR Compiler: Optimisation: Other Optimisation Flags: -mcall-prologues -mrelax (and use -Os or -O2)

C/C++ Build: Settings: AVR C Linker: General: Other Arguments -Wl,–gc-sections

C/C++ Build: Settings: AVR C Linker: Libraries: Add “m” without quotes. m is the standard math library, which should be included in most projects.

C/C++ Build: Settings: AVR C Linker: Objects: Other Objects Here you need to add the compiled freeRTOS library. And this is the only place where the Debug and Release builds are different.

With Release Build selected, paste “${workspace_loc:/freeRTOS82x/Release/libfreeRTOS82x.a}”

With Debug Build selected, paste “${workspace_loc:/freeRTOS82x/Debug/libfreeRTOS82x.a}”

Or select the Workspace option to navigate to the actual assembler files to be linked into the project.

Project References: freeRTOS82x ticked.

Now we are going to add the MegaBlink (or retrograde) files, from the (or file that you have downloaded from sourceforge, and extracted somewhere sensible. If you downloaded the, you have all the sources.

File>>Import…>>General:File System

Select the “into folder” as the project name you just created, and “Select All” for the import. That should import the 2 files shown inro the project file system. Spend some time browsing, if you like.

Following this step, it should be possible to compile and link the project.

Project>>Build All

If this step completes successfully, with no additional ERRORS, then the final step is to upload the new application into your Arduino or Freetronics device.

Make sure that you have your device plugged into the USB port, then simply hit the AVR* button in the row of buttons. You will see some green text showing the status of the upload, finishing with the words

avrdude done. Thank you.

Now, you should have a flashing LED.

Now you can import any additional projects, in the same way.

Step 8. Things to watch.

Turn on the serial port by removing the comments around the serial port definitions, and watch to see aspects of the program in action.

Expect to manage the amount of heap allocated in the ./include/FreeRTOSBoardDefs.h file, to ensure that the total SRAM utilised (as noted in the final linker stage when using heap_1.c, heap_2.c or heap_4.c) remains less than 100% or for ATmega328p 2048 bytes.

Expect to manage the amount of stack space allocated to each task during the set up, to ensure you’re not wasting space, nor (worse) you’re over writing another task’s stack.

For the Arduino Uno, keep the total number of tasks to below 4, otherwise too much SRAM is consumed in stack allocations.

60 thoughts on “freeRTOS and libraries for AVR ATmega with Eclipse IDE

  1. I just got back to this today, and figured out what was killing me :)Though I disabled the extended RAM options, the heap size setting was still configured for extended RAM! It was making it to the first xTaskCreate and going away, so I added a call to check the heap size and it returned -1 .. that sent me to the heap code where I realized what was going on.thanks for the help, now onward to the task(s) at hand (my plan is to rewrite the firmware for my Makerbot ToM under FreeRTOS on the 2560, followed by a pprt to one of the 32-bit parts)

  2. In the Mega Blink example project I get Symbol ‘portSERIAL_BUFFER’ could not be resolved, Symbol ‘portTICK_RATE_MS’ could not be resolved, Type ‘portTICK_TYPE’ could not be resolved and Type ‘xComPortHandle’ could not be resolved. Any suggestions?

    • If you’re using Eclipse, you should be able to highlight the Symbol, right click, and then Open Definition which shows whether the correct file and symbol is being referenced.

      In Step 7 you need to link the Project Reference from the Megablink project back to the freeRTOS project, and make sure this include directory link is added for All Builds: “${workspace_loc:/freeRTOS730/include}”

      That should fix these issues.

      • Thanks for these tips. I’ve fixed those issues but now I’m getting ‘section .task [0000294a -> 00002957] overlaps section .data [0000294a -> 0000295b]’

      • I have exactly the same problem as James (overlapping sections).
        Compiling with avr-gcc of version 4.7.2

        Has someone find a solution?

      • The solution is to add the avr6.x file into /usr/lib/ldscripts
        IF you are using the AVRmega2560 (Arduino Mega, or ADK devices). This is mandatory.
        Really it is just two lines that need to be added, to ensure that tasks are put in lower memory than functions.

        *(.task) /* A RTOS task should be in low memory. */

        Please confirm the above, and if it is still not working, then more detail.

        Edit in January 2014. From avrlibc 1.8.0 there is a .lowtext section that was implemented in avr6.x. When I did the mods for freeRTOS800, I changed to use this section rather than .task. This means that the avr6.x modification referred to here is obsolete. In other words, it should just work automagically.

      • Thank you very much Feilipu!

        After adding avr6.x to the /usr/lib/ldscripts I can compile and run my app.

  3. I think you may not have added the avr6.x file (with the .task definition) into the right place in /usr/lib/ldscripts

    This post was designed to be basic, for ATmega328p (Uno style) devices, so didn’t cover the additional items for ATmega2560 hardware. Check out the additional items you need to consider here:

  4. I am also having problems with overlapping sections. I copied the avr6.x to the proper place in ldscripts. I am compiling freeRtos using Eclipse, but would like to link the freeRtos library outside of Eclipse using AtmelStudio as my development environment. I assume I have to setup the memory sections in AtmelStudio for the “.task” sections to force them into low memory. I am lost as how to do this in AtmelStudio. Any suggestions?


    • Mark,

      I think your question relates to using the Mega here, rather than to to the ATmega328 described above.

      I don’t know too much about the Atmel Studio, but I’d suggest (as a trial) not using the .task section initially, and doing tests with small programs less than 64kByte. That way you can be sure that everything is working, before you use the expanded Flash capabilities of the ATmega2560.

      Also Stu_San at AVRFreaks (from whom I originally sourced the ATmega2560 port), may have some other wisdom at that site, or be open to a question.

      Good luck.

      • Feilipu,
        Yes, I am using a Arduino Mega board. I was able to get it to link properly. The solution was similar to that for Ecliplse. I just needed to copy the avr6.x you provided, replacing my avr6.x in AtmelStudio under:
        “C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\\avr8-gnu-toolchain\avr\lib\ldscripts”
        I prefer using AtmelStudio so that I can use my JTAGICE3 debugger, but will continue to do freeRtos builds under Eclipse.
        I now have the blinking LED task running! Thank you for this page!

  5. Everything checked several times. Still got the problem:

    include/lib_serial.h:172: error: expected ‘;’, ‘,’ or ‘)’ before ‘uxTxQueueLength’
    include/lib_serial.h:183: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xSerialGetChar’
    include/lib_serial.h:184: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘xSerialPutChar’
    ../lib_fatf/xmodem.c: In function ‘flushinput’:
    ../lib_fatf/xmodem.c:79: warning: implicit declaration of function ‘_inbyte’
    ../lib_fatf/xmodem.c: In function ‘xmodemReceive’:
    ../lib_fatf/xmodem.c:95: warning: implicit declaration of function ‘_outbyte’
    make: *** [lib_fatf/xmodem.o] Error 1

    Something must be wrong in your package. What other explanation?

    • Nico,

      ../lib_fatf/xmodem.c needs to be excluded from the build. It is not part of the standard build.
      Either use Eclipse to exclude it, or delete the file.

      I’d say that in lib_serial.h, portBASE_TYPE is not being found. It is defined in portmacro.h.
      Check that your portmacro.h is being included properly.

      Good luck.

  6. Better, but only semi resolved:

    make: *** [lib_fatf/xmodem.o] Error 1
    make: *** [lib_serial/lib_serial.o] Error 1
    make: *** [lib_w5100/socket_util.o] Error 1
    make: *** [portable/port.o] Error 1

    Trying to figure that out, I’ll keep trying..

    • That looks like a link error, which happens if the source and includes get out of sync with the object files. It can be resolved by doing a full clean, and then a full build. Sometimes, Eclipse get a little confused, and it is worth going in and deleting the contents of the Release and the Debug folders.

      Also, try removing all of the libraries (delete, exclude from build, etc) and just starting from the freeRTOS files. Just get blinky working first.


    • It is hard to provide sensible advice from that level of detail.
      Try to follow each step, and then note where it goes wrong.

      If you have never used a microcontroller before, then start with Nerdkits or Arduino.

      Good luck

      • Hey,

        So I installed it on Windows this time(I used Ubuntu 12.10 previously), and I’m getting a very similar error when I try to build the static library part.

        make: *** [portable/port.o] Error 258

        Can you please help me?

      • This is my console ouput:
        **** Build of configuration Release for project MaybeRTOS ****

        make all
        Building file: ../portable/port.c
        Invoking: AVR Compiler
        avr-gcc -I”C:\Users\Bhar\workspace\MaybeRTOS\include” -D GCC_MEGA_AVR -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -mcall-prologues -mrelax (and use -Os or -O2) -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega2560 -DF_CPU=16000000UL -MMD -MP -MF”portable/port.d” -MT”portable/port.d” -c -o “portable/port.o” “../portable/port.c”
        /usr/bin/sh: -c: line 1: syntax error near unexpected token `(a’
        /usr/bin/sh: -c: line 1: `avr-gcc -I”C:\Users\Bhar\workspace\MaybeRTOS\include” -D GCC_MEGA_AVR -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -mcall-prologues -mrelax (and use -Os or -O2) -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega2560 -DF_CPU=16000000UL -MMD -MP -MF”portable/port.d” -MT”portable/port.d” -c -o “portable/port.o” “../portable/port.c”‘
        make: *** [portable/port.o] Error 258

        **** Build Finished ****

      • Some quick notes.

        You seem to be compiling for the Mega2560. Have you read the additional instructions for this hardware?

        Can you check that there are not unreachable paths in the portable.h / .c files?

        It looks like the issue is with the make file generated by Eclipse that sh is complaining about with its unexpected token message.
        I’ve never seen this issue previously. Try googling the make Error 258 to see what it implies.

        Last night (19.9.2013) I uploaded some new code to Sourceforge. It might be worth trying again based on that codebase.
        Though the differences for the base platform are minor.


  7. how to use timer2 on atmega328p as timer scheduler? I added #elif defined( portUSE_TIMER2 )
    #define portUSE_TIMER1_PWM , it’s compiling but isn’t working … some hints please

    • You would need to set the correct ISR insertion. Currently there is no provision to set the Timer 2 interrupt for the 328p.

      Also, you would need to change the fuse bits to utilise the Calibrated Internal RC Oscillator for the system. This changes the use of the XTAL1 and XTAL2 to being TOSC1 and TOSC2 which are used for the Low Frequency Crystal Oscillator (32.768kHz).

      It is not possible to simultaneously have an external 16MHz system crystal driving the Full Swing Crystal Oscillator and an 32.768kHz crystal driving the Low Frequency Crystal Oscillator in an ATmega328p. The I/O pins are shared, therefore there is an “OR” choice.

  8. Thank you for all the hints. It’s working fine. I’ve got one question to you – I would like to know how I can write down a programme that prints an output with results after my request.

    MegaBlink example works. It prints through a serial “avrSerialPrint_P” command the diode status. I am able to send chars using the serial port to the Arduino and I wish to do something like “ping” and get a reply “pong”. Have you got any simple example of communicating with Arduino, anything like this? Of course, I found some example on the official forum, but it doesn’t seem to be working.. to complex as for me at the moment. No idea… Thank you 🙂

    • It is pretty easy to grab characters from the serial port. Have a look at lib_io serial.c to see which commands to use.

      If you want a full “monitor” there are examples in the MegaSDTest and in the MegaW5100Test main.c files. But these are a little more complex to understand. Worth it though. The monitor reads the input on the serial port, and does some action that you decide upon receipt of the command characters you programme.

      Good luck.

  9. hi feilipu, i just get started, i have tried a lot of options but i have not been able to solve this problem:

    avrdude: error: no libftdi or libusb support. Install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again.
    avrdude: programmer operation not supported

    here is complete trace
    i already did console suggestion i have libusb1 and libftdi1 installed,same result.
    Also when i install form source avrdude i got the following output

    Configuration summary:
    DON’T HAVE libelf
    DON’T HAVE libusb
    DO HAVE libusb_1_0
    DON’T HAVE libftdi1
    DON’T HAVE libftdi
    DON’T HAVE libhid
    DO HAVE pthread
    DISABLED doc
    ENABLED parport
    DISABLED linuxgpio
    make all-recursive

    i have seen, if it cant see ftdi libraries from the PATH in bashrc but is correct, i dont know what else t try, my environment is xubuntu, i had to install avrdude 6.0.1 from source because last stable package was 5.1.

    do you have any suggestions or ideas to try ?. i also tried the 3 different options for a ft232r but all of them give me same output.

    Thanks in advance

    • Looking at your pastebin everything went well until you got to avrdude. (You have the required hex files so you can upload them manually using avrdude).
      Your issue is with avrdude installation. From the compiler / freeRTOS / code point of view everything is done.

      You don’t mention what platform you’re using, or whether avrdude is working for you or not. Hard to see where the problem might be. Searching for avrdude references will help.

      Try avrdude from the command line, to see if it can find the programmer that you’ve connected.
      If you’re using an UNO then ftdi is not the right interface to use, because the UNO uses an avr U2 and usually appears on ttyACM0 (rather than ttyUSB0 typical for the FT232R found in the 2009 or other Arduino clones).

  10. digging a bit more i have with ldd `which avrdude` => (0xb77b4000) => /lib/i386-linux-gnu/ (0xb7783000) => /lib/i386-linux-gnu/ (0xb7768000) => /lib/i386-linux-gnu/ (0xb7724000) => /lib/i386-linux-gnu/ (0xb7570000) => /lib/i386-linux-gnu/ (0xb755d000)
    /lib/ (0xb77b5000) => /lib/i386-linux-gnu/ (0xb7554000)

    i also tried avrdude manually, outside eclipse with no luck, 😦
    same error related with libusb1 , also im a virtualbox machine (host:macosx mountainlion, guest:xubuntu), but i have isntalled all drivers and doing dmesg
    i got
    [ 56.600304] ftdi_sio 2-2:1.0: FTDI USB Serial Device converter detected
    [ 56.600375] usb 2-2: Detected FT232RL
    [ 56.600378] usb 2-2: Number of endpoints 2
    [ 56.600414] usb 2-2: Endpoint 1 MaxPacketSize 64
    [ 56.600416] usb 2-2: Endpoint 2 MaxPacketSize 64
    [ 56.600417] usb 2-2: Setting MaxPacketSize 64
    [ 56.612413] usb 2-2: FTDI USB Serial Device converter now attached to ttyUSB0

    which looks ok too, im really dont understand what im doing wrong. i think maybe i need to use the right driver that probably is libftdi1, but well, do you have any idea of how do you tell avrdude to see other than libusb1?

    • It looks like you have some kind of virtualbox or abstraction issue with avrdude.
      You are seeing the FTDI device being recognised and attached properly as ttyUSB0, as expected. So there is probably not a problem at the FTDI driver level.

      On the Eclipse side, if avrdude isn’t working off the command line, then it won’t work in Eclipse either. You need to fix avrdude before you go any further with Eclipse / freeRTOS / your code.

      I would search for similar issues using the error messages and your platform as the search text. It may be that avrdude doesn’t work with virtualisation, because it relies on something special about USB timing or packets that is not transferable across VMs. Or may be something more general with MacOS. You’ll need to dig into this point.

      • thanks for you help man,i just solved it :-), the error is that i was missing libftdi-devel, searching on avr freaks forums i found it, im very near now im just missing is
        avrdude -pm328p -cft232r -P/dev/ttyUSB0 -b115200 -Uflash:w:MegaBlink.hex:a
        apparently the port is wrong…
        invalid portname ‘/dev/ttyUSB0’: use ‘ft[0-9]+’

        im still searching., i have tried different options no success with it yet.

  11. Hi feilipu, after about 1.5 hours i solved all ‘trivial’ issues, the port problem was really strange apparently with this environment was only to use as port just ‘usb’, then i faced a permissons error so i sudo it (not good i know, this is how my command line looks like)

    sudo avrdude -pm328p -cft232r -P usb -b115200 -Uflash:w:MegaBlink.hex:a

    now my new error is this, reading on avr forums and on, this looks pretty hard, could be a lot of things, it could be also that i have bricked my device :P.

    avrdude: Device is not responding to program enable. Check connection.
    avrdude: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.

    its kind of funny the last output of avrdude, lol
    —>avrdude done. Thank you.

    pd: im just documenting details in my problem, you know ;-). if you have any ideas qny help is welcome, my next step will be to try on real linux machine.

    • You may need to trigger the Reset line manually, if you don’t use the “arduino” protocol. This is an adaption of the standard avr109 protocol that pulls DTR low before starting to upload, which is attached via a capacitor, to Reset the MCU.

      Similarly “wiring” is to stk500v2 protocol for Mega MCU and the 1284p MCU.

      Have a try using “arduino” protocol.

      • Hi feilipu i have started again 2 days ago, too much work at office you know, well i want to share my results still no sucess on this last issue i have read datasheets here:
        and also i tried these 2 ardude wirings, the one you suggested for arduino too but it gives same output.
        wirings: …
        # Note: pins are numbered from 1!
          id    = “arduino-ft232r”;
          desc  = “Arduino: FT232R connected to ISP”;
          type  = “ftdi_syncbb”;
          connection_type = usb;
          miso  = 3;  # CTS X3(1)
          sck   = 5;  # DSR X3(2)
          mosi  = 6;  # DCD X3(3)
          reset = 7;  # RI  X3(4)
        # website mentioned above uses this id
        programmer parent “arduino-ft232r”
          id    = “diecimila”;
          desc  = “alias for arduino-ft232r”;
          id    = “ft232r”;
          desc  = “FT232R Synchronous BitBang”;
          type  = “ftdi_syncbb”;
          connection_type = usb;
          miso  = 1;  # RxD
          sck   = 0;  # RTS
          mosi  = 2;  # TxD
          reset = 4;  # DTR
        also i have tried a config using xrd,rts,txd,dtr  according to pins numbers on ft232r datasheet but it gives same output 
        using cts, dsr, ctd and ri, i can only use ri, because the others pin numbers are above 7, and it only have 8 pins
        also well about your last advice i dont know to set avr109 protocol, in avrdude config for 328 there is 
        # ATmega328
            id = “m328″;
            desc = “ATmega328″;
            has_debugwire = yes;
            flash_instr = 0xB6, 0×01, 0×11;
            eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0×00,
          0xBE, 0×01, 0xB6, 0×01, 0xBC, 0×00, 0xBB, 0xBF,
          0×99, 0xF9, 0xBB, 0xAF;
            stk500_devcode = 0×86;
            # avr910_devcode = 0x;<— this line is commented i have also tried change to it, but i dont know what value to put in there.

      • Some questions to ask…

        Does Microduino have an “arduino” boot loader installed? I have looked at the schematic for microduino and it looks the same as Arduino 2009. But if there is no boot loader installed, avrdude will find nothing to talk to and will fail.

        If Microduino has a normal Optiboot boot loader installed, then using the “arduino” protocol is correct, and if it is not working then the problem lies elsewhere.

        Have you tried your avrdude setup with a standard arduino 2009 or other sparkfun device with FT232R interface? Try this too. This will isolate your issue into configuration or into IO problem. There may be a subtle bug using a virtual box in a Mac. Can’t say till you test standard supported hardware.

        Being able to programme your device is fundamental, irrespective of what code to be installed. I have wasted many hours of my life with serial boot loaders on Arduino, and they are cursed. Today I use an Atmel ICSP programmer and there are never issues. Life is too short.

  12. Hi feilipu, thanks for your answers and time its been pretty hard to catch, i also contact directly microduino guys, but the answer they give me was only to read this:
    after reading your answer i realize maybe there was a problem with that, as you said maybe there wasn’t a boot-loader to talk with, so i did this instructions with an arduino uno board, more exactly microduino uno board, here
    with these steps
    everything went fine i burn bootloader correctly, then back to avrdude same output :’-(
    and for your other question now im from Ubuntu 10.04, real hardware machine directly plus avrdude 6.1

  13. Hi feilipu, thanks for your answers and time its been pretty hard to catch, i also contact directly microduino guys, but the answer they give me was only to read this:
    after reading your answer i realize maybe there was a problem with that, as you said maybe there wasn’t a boot-loader to talk with, so i did this instructions with an arduino uno board, more exactly microduino uno board, here
    with these steps
    everything went fine i burn bootloader correctly, then back to avrdude same output :’-(
    and for your other question now im from Ubuntu 10.04, real hardware machine directly plus avrdude 6.1

    • also well, i know arduino programs works correctly with this ft232 and core, because i have already use wifi and 10dof shields with success, i have run freeimu for example on micrduino 10dof too.

  14. Hey feilipu!!
    finally i manage to make it work with arduino protocol here is proof and my command line

    sudo avrdude -pm328p -carduino -P /dev/ttyUSB0 -Uflash:w:MegaBlink.hex:a -b 115200
    \o/ 🙂
    i still dont understand how to make it work directly with ft232r protocol, it works directly with arduino protocol

    thanks again for your time.

    • Yes. The “arduino” protocol is correct, derived from avr109 protocol.
      I think the ft232r protocol is some kind of bit-bang method. I have never seen it used.

      Good luck with next steps!

  15. I’ve got a question related to your reply (#comment-1347) to my last problem. I used “MegaSDTest” to create a command like “dd”, by mixing it with my blinking diode code. I mean the “switch & case” part, the “get_line” function and required lines. I just wanted to receive a serial print ” you’ve just sent ‘dd’ “. But nothing happens, there is no error, as well as no reaction at all. Anything I enter, I receive a reply equal to my send chars. The algorithm seems not to work properly in this example (also MegaW5100Test). Maybe I miss something in project settings (using heap2, but changes don’t solve it)? I started with the MegaBlink example that you described on the website, then made the following changes. I’ve got no idea… Thanks for hints.

  16. I’m implying that the xSerialPrint functions are working correctly, because you mention you’re getting an echo of the characters you enter.

    Therefore, it would seem there’s something amiss in your implementation of the “switch & case” part of the input parsing. Perhaps you’re not digesting the first “d” correctly? Try the command with just one letter to see if you’re getting through the first switch & case level. Then try it with the second “switch & case” which is the second level (second character in the command).

    I’m afraid it will be up to you to debug your implementation of your code, as the “switch & case” code, driven by get_line and the letter parsing functions are working generally. I don’t know of any situation where they aren’t working. They originate from ChaN’s FatFS example code. You could also refer back there too for inspiration.

    Good luck.

  17. Thanks. There was, actually, no problem with my code. I tried with Realterm to send chars, that’s working! But my Qt app (made for serial communication) seems not to work properly this time. It seemed to work when I modified the code… Never mind, it’s a seperate problem, maybe with coding. Thanks.

  18. I am having an issue while compiling the code.

    workspace/avr/FreeRTOS820/include/inet.h:243:17: error: redefinition of typedef ‘SOCKET’
    /workspace/avr/FreeRTOS820/include/socket.h:17:17: note: previous declaration of ‘SOCKET’ was here
    make: *** [lib_inet/http.o] Error 1

    I am receiving the same error for dhcp.o as well…

      • The SOCKET is defined twice, once in socket.h and once in inet.h. Since it is the same definition my compiler set-up doesn’t complain.

        The simplest way to fix it is to remove the definition in inet.h, and replace an inclusion of socket.h

        i.e. in the inet.h file delete this line:

        typedef uint8_t SOCKET; // IINCHIP W5x00 Socket in use. < _WIZCHIP_MAX_SOC_NUM_ if not using uIP.

        and replace it with this line:

        #include "socket.h"

        That's all you need to do.

  19. Hi Phillip, I want to learn freeRTOS with my Arduino uno, searched for pointers (the cerebral ones) and landed here. Tried your procedure above with Eclipse Luna SR2 and CrossPack on a Mac. Tried it with AVR-plugin 2.4.1 and 2.4.2 and AVR-plugin 2.5.0 but can’t get it to run. Could you tell what’s the latest version of eclipse and the plugin that work? Thanks, Marcello.

    • Marcello,

      I am using the Eclipse being part of Ubuntu 14.04 currently. The most recent AVR tool chain (avrdude, binutils, libc, gcc) all come along with Ubuntu 14.04. I like to have my development environment stable. It is easy to waste weeks trying to work out how to get latest this or release candidate that working, when all I really want to do is make something.

      I selected the library update path for the avrdude 6.0.1 plug in as described in my post on the topic. avrdude 6.0.1 is a worthwhile update, because it fixed issues with my environment.

      Aside from that avrdude thing, there are no additional magic or special incantations that need to be done.

      The Eclipse version that comes with Ubuntu 14.04 is 3.8. The AVR tool chain in 14.04 is essentially the same one found on the debian Sid repository, which is their cutting edge. Things are very stable in the AVR world, so not much changes from year to year.

      You might end up having to write your own procedure, given the variations in platform (OSX vs Ubuntu, Eclipse 3.8 vs Luna).

      I just read this point on Eclipse 3.8. Perhaps its worth noting.

      Good luck.

  20. Hi Feilipu,
    I’m currently trying to use your avrfreertos library with a atmega2560 as many others are. I’m on windows using eclipse Neon and my toolchain is WinAVR, I followed the exact instructions on this page (except i configured the project properties for atmega2560) and I received the following error:

    12:48:48 **** Build of configuration Debug for project freeRTOS ****
    make all
    Building file: ../portable/port.c
    Invoking: AVR Compiler
    avr-gcc -I”C:\Users\Joe\workspace\freeRTOS\include” -Wall -g2 -gstabs -Os -ffunction-sections -fdata-sections -mcall-prologues -mrelax -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=16000000UL -MMD -MP -MF”portable/port.d” -MT”portable/port.o” -c -o “portable/port.o” “../portable/port.c”
    make: *** [portable/port.o] Error -1073741502

    I also receive this error when the device is atmega328p, so I don’t think that is the issue. I read your instructions about avr6.x linker script and modified that just to be sure as well. I’m sure my project structure is the exact same as yours. I’m thinking WinAVR is the issue, since it appears it hasn’t been updated since 2010.

    Should the portmacros.h header be in the same folder as port.c? (This is how the folder looks in the zip from the freeRTOS site itself).

    Has it ever been verified that this library can be built in windows with the winAVR toolchain? If this library doesn’t work I could go back to using the freertos demo and modify the port.c file myself, if you have any pointers there I’d greatly appreciate it.



    • Alex,

      Some points for consideration.

      First -mmcu=atmega328p is wrong for your Arduino Mega2560. If you’ve installed the avr plugin into Eclipse then you should set the machine type appropriately in the menu appropriately.

      The compiler option -mmcu=atmega2560 drives many compile time settings via pre-processor defines, so a setting wrong for the hardware will break many things.

      I’ve not tried WinAVR, so any success would be a happy coincidence. 🙂
      I’d guess that it is very similar to using GCC on Linux systems.
      You should not need to modify the port files if GCC is the background compiler.

      It is worth noting that the FreeRTOS source code contains a supported port for ATmega323 and WinAVR, so you can note any contained differences there.

  21. Hi Felipu,
    I tried creating the FreeRTOS Static library project using the files from freeRTOS9xx folder. I’ve followed all the instructions as mentioned but I get an error saying ” ‘M_SQRT1_2′ undeclared (first use in this function) DAC.h /freeRTOSv9/include line 374 C/C++ Problem’.” Do take a look as I can’t figure out the problem. My target device is atmega2560 and clock frequency is 16000000. I am using Eclipse Indigo for creating the projects.


  22. I am using a windows system, so I have WinAVR installed. The includes file in my eclipse project has /winavr/avr/include, /winavr/lib/gcc/avr/4.3.2/include and /winavr/lib/gcc/avr/4.3.2/include-fixed. I have AtmelStudio already installed in my PC so, the winavr path is from there. Also, does eclipse require any AVR library path settings to done while configuring the projects for the first time.


  23. I’m sorry, but I’ve no experience with WinAVR, and where the libraries are installed.

    From the error you described, it is clear that you have an issue with including the avr-libc header files. Perhaps look at the console window in Eclipse to see the compilation messages, so you can see which files are included, and whether the right files are listed.

    For Linux (Debian/Ubuntu) versions of Eclipse with the CDT and AVR Tools (as described in this post) there are no special requirements, beyond what I’ve mentioned. For Windows, I can’t say.

    • Hi Felipu,

      I got rid of earlier errors by cleaning and building the project but now I have new problems.
      Now I get the following errors\lib_fatf\ff.c file:
      1. ./lib_fatf/ff.c:3410: error: unable to find a register to spill in class ‘POINTER_REGS’
      2. ../lib_fatf/ff.c:3410: error: this is the insn:
      3. ../lib_fatf/ff.c:3410: confused by earlier errors, bailing out
      4. make: *** [lib_fatf/ff.o] Error 1

      I tried searching a bit on these problems and for the first and second error as mentioned in this link:
      It has got to do with compiler optimization, so I tried building with O1,O2, Os, nothing works.Also, some of the threads say that it is a gcc bug like this one :
      Any thoughts on this?

      Also, the lib_fatf looks like libraries for FAT file format. So can I exclude that folder from build?


      • Akhilesh,

        I have occasionally seen that error too. Generally it happens when lots of pointers are being maintained, or you have been “in-lining” lots of code by using the GCC FLATTEN attribute (which I do a lot).

        Almost everything in the repository is “optional” to the build of FreeRTOS. You can see what the minimum is by looking at this minimum AVRfreeRTOS repository or at the contents of the Arduino FreeRTOS Library.

        You can remove any capabilities you don’t need from the AVRfreeRTOS repository code, and still use the remainder as you see fit.

      • Thanks a ton for the help. The minimum freeRTOS is just freeRTOS port without the library. Is there any freeRTOS component which I’ll not be able to make use with minimum freeRTOS?

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s