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.

Sourceforge freeRTOS & libraries for AVR ATMEGA

That’s 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).
  • 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 and W5200 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.0.0 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: 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:

Updating Eclipse AVR Plugin to support avrdude 6.0.1

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

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 a Ubuntu 12.04 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. Fix avrdude chip erase delays.

Optional!

There is a long standing bug in avrdude configuration files, that prevents proper programming of the 324p, 644, 644p and 1284p devices. These are relevant to Sanguino, Pololu SVP, and Freetronics Goldilocks users. This issue been fixed in the avrdude 6.0.1 release, and the instruction for this is above, for reference following these instructions.

http://savannah.nongnu.org/bugs/?28344

The chip_erase delay for four AVRs in avrdude.conf is too short, so the chip erase command times out and avrdude prints an error message. The error is not fatal; it doesn’t prevent the user from programming the chip. This bug should be very easy to fix.

In avrdude.conf, change the chip_erase_delays to the following values:

part chip_erase_delay =

ATmega324P: 45000 (us)
ATmega644: 55000
ATmega644P: 55000
ATmega1284P: 55000

Currently they are all 9000, which is too short. So in your favourite editor, open the avrdude.conf file, and make the changes to the chip definitions.

sudo gedit /etc/avrdude.conf

Or do this by updating the Eclipse AVR Plugin to support avrdude 6.0.1.

Step 4. 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 5a. 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 http://download.eclipse.org/tools/cdt/releases/indigo

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

Step 5b. 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 http://avr-eclipse.sourceforge.net/updatesite/

Updated AVR Plugin Updating Eclipse AVR Plugin to support avrdude 6.0.1

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

Other…>>C/C++

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 freeRTOS800).

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

Project>>Properties

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: Symbols: Define Syms (-D): Add… GCC_MEGA_AVR

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 the freeRTOS files, from the freeRTOS800_All_Files.zip 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. That should import the entire file system. Spend some time browsing, if you like.

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…”: freeRTOS800/include

“${workspace_loc:/${ProjName}/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.

./MemMang/heap_1.c

./MemMang/heap_3.c

./MemMang/heap_4.c

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

Project>>Properties

AVR:AVRDUDE:Programmer:New…

Configuration name: Arduino or Freetronics 2010

Programmer Hardware: Atmel STK500 Version 1.x firmware

Override default port: /dev/ttyUSB0

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:/freeRTOS800/include}”

C/C++ Build: Settings: AVR Compiler: Symbols: Define Syms (-D): Add… GCC_MEGA_AVR

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:/freeRTOS800/Release/libfreeRTOS800.a}”

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

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

Project References: freeRTOS800 ticked.

Now we are going to add the MegaBlink (or retrograde) files, from the MegaBlink.zip (or retrograde.zip) file that you have downloaded from sourceforge, and extracted somewhere sensible. If you downloaded the freeRTOSxxx_All_Files.zip, 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.

34 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. */
        KEEP(*(.task))

        http://sourceforge.net/projects/avrfreertos/files/freeRTOS/avr6.x/download

        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
    http://sourceforge.net/projects/avrfreertos/files/freeRTOS/avr6.x/download

    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:
    http://feilipu.me/2012/01/15/ethermega-arduino-mega-2560-and-freertos/

  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?

    Thanks!

    • 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\3.4.2.876\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.

      Goodluck

    • 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.

        Goodluck.

  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 http://pastebin.com/k8SEa37K
    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`
    linux-gate.so.1 => (0xb77b4000)
    libusb-1.0.so.0 => /lib/i386-linux-gnu/libusb-1.0.so.0 (0xb7783000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb7768000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7724000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7570000)
    libudev.so.1 => /lib/i386-linux-gnu/libudev.so.1 (0xb755d000)
    /lib/ld-linux.so.2 (0xb77b5000)
    librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (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.

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 )

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