Just a thought

Code Blocks IDE for avr-gcc and avrdude (Ubuntu)

Posted by stringofthoughts on November 6, 2009

Code Blocks is very light weight, extensible and fully configurable C/C++ IDE. You can download code blocks from here. This post focuses on installation and configuration of code blocks on Ubuntu. Download the binary package codeblocks_8.02-0ubuntu1.deb.tar.gz. Inside the compressed file there is a folder with following packages.

codeblocks_8.02-0ubuntu1_i386.deb
codeblocks-contrib_8.02-0ubuntu1_i386.deb
codeblocks-dbg_8.02-0ubuntu1_i386.deb
codeblocks-dev_8.02-0ubuntu1_i386.deb
libcodeblocks0_8.02-0ubuntu1_i386.deb
libwxsmithlib0_8.02-0ubuntu1_i386.deb
libwxsmithlib0-dev_8.02-0ubuntu1_i386.deb

Install the packages in bold letters. In case you are wondering how to install, just double click on the packages (damn it’s easy to install softwares in Ubuntu :P ) After the installing you can access code blocks from menu Applications -> Programming -> Code::Blocks IDE.

Click on Create a new project in home window to create your new project. Code blocks automatically adds an AVR Project option. Select that and click next. Fill the required informations like project name, path, crystal frequency etc and click finish.

In the Project Tab of management window (left side of the screen) you ‘ve your workspace. Inside the sources you ‘ve main.c. you can of-course add more files. Now your project is ready. congratulations !!! . There is still one thing left to do. Open build options from menu: Project -> Build options and in compiler flags tab check flag “Optimize generated code (for size) [-Os]“. You might wonder why? well compiler won’t compile your code and you ‘ll be stuck with warning(s) :) ( I myself checked the flag after getting warnings )

# Make sure to switch to Release mode to generate hex file. Do all the debugging in debug mode and once it’s done switch to Release mode and build again to generate hex file. Project hex file is in <Project dir>/<bin>/<Release> and it’s the .elf.hex file you need.

Adding avrdude in code blocks tools. Follow the steps

Open the “User defined tools” window from menu: Tools -> configure tools.

Click on Add button to open Edit tool window.

edit_tool

Add the parameters for avrdude as shown in above image and you are done. After compiling in release mode just click on the avrdude option in tools menu and it will burn .elf.hex file in the microcontroller (Make sure the the target is powered on and programming cable is connected )

Have a nice time buring microcontrollers :P

About these ads

9 Responses to “Code Blocks IDE for avr-gcc and avrdude (Ubuntu)”

  1. [...] Code Blocks IDE for avr-gcc and avrdude (Ubuntu) [...]

    • Bhaumik Shah said

      Sir

      i have downloaded it. It shows error.
      For codeblocks_8.02-0ubuntu1_i386.deb Error: Dependency is not satisfiable: codeblocks (= 8.02-0ubuntu1)
      For libwxsmithlib0_8.02-0ubuntu1_i386.deb Error: Dependency is not satisfiable: libcodeblocks0 (= 8.02-0ubuntu1)
      please help to eradicte it

      i am using ubuntu 10.4 LTS

  2. Bhaumik Shah said

    i have done it

    thanks

    my mistake

    awesome tutorial

    please install flies in this order

    1) libcodeblocks0_8.02-0ubuntu1_i386.deb
    2) libwxsmithlib0_8.02-0ubuntu1_i386.deb
    3) codeblocks_8.02-0ubuntu1_i386.deb

  3. Eric Apperley said

    If I manually invoke avrdude from the command line using sudo as per the following I can connect to the AVRISPMKII programmer OK:

    sudo avrdude -p m8 -c avrispmkII -P usb -v

    However, if I don’t use root privileges (via sudo) I can’t find the USB port?

    avrdude: usb_open(): cannot read serial number “error sending control message: Operation not permitted”
    avrdude: usb_open(): cannot read product name “error sending control message: Operation not permitted”
    avrdude: usbdev_open(): Found [unnamed product], serno: [unknown]
    avrdude: usbdev_open(): error setting configuration 1: could not set config 1: Operation not permitted
    avrdude: usbdev_open(): did not find any USB device “usb”

    Is this something to do with libusb or do I always need to use sudo?

    Eric

    • stringofthoughts said

      Hi,

      This seems like a simple permissions problem. Try the following steps

      1) Connect the programmer to USB port.
      2) Open terminal and run command “dmesg”
      3) Find out where your device is connected. look for /dev/ttyUSBx or something like that starting with “/dev/. Find out where your programmer is connected. let’s assume it’s connected to /dev/ttyUSB0.
      4) Change the permissions of the device.
      $sudo chmod 777 /dev/ttyUSB0
      5) After this you will not need to do sudo every time you use avrdude.

      you can see the permissions of the device using ls command
      $ ls -l /dev/ttyUSB0

      Good Luck !!!
      Hope this helps :)

      • Eric Apperley said

        I’m using Ubuntu 10.04 with kernel 2.6.32-26-generic.

        This kernel uses the udev system for dynamically creating and removing device files on demand. There is no “/devices” directory. As a consequence the device files aren’t permanent. So, unless I’m missing the plot, one can’t set permissions on device files.

        Here is the output from udevadm after removing then re-inserting the USB plug for the AVR ISPII device.

        /dev$ udevadm monitor
        monitor will print the received events for:
        UDEV – the event which udev sends out after rule processing
        KERNEL – the kernel uevent

        KERNEL[1291405551.058015] remove /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4/1-1.4:1.0 (usb)
        KERNEL[1291405551.058143] remove /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4 (usb)
        UDEV [1291405551.059111] remove /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4/1-1.4:1.0 (usb)
        UDEV [1291405551.059742] remove /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4 (usb)
        KERNEL[1291405560.312076] add /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4 (usb)
        KERNEL[1291405560.312371] add /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4/1-1.4:1.0 (usb)
        UDEV [1291405560.317283] add /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4 (usb)
        UDEV [1291405560.320449] add /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4/1-1.4:1.0 (usb)

      • stringofthoughts said

        Here in our Lab we use serial and Parallel port based ISP programmer for AVR. Serial port is /dev/ttyS0 and Parallel port is /dev/parport0 and we need to change it’s permissions before using it (without sudo) and it works fine. (OS is Ubuntu 10.04)

        What’s the output of dmesg | tail command after you insert AVR ISP II device

      • Eric Apperley said

        $ dmesg | tail
        [ 148.503390] wlan1: authenticated
        [ 148.503481] wlan1: associate with AP 00:13:f7:09:ad:a7 (try 1)
        [ 148.513218] wlan1: RX AssocResp from 00:13:f7:09:ad:a7 (capab=0x421 status=0 aid=31)
        [ 148.513234] wlan1: associated
        [ 148.567428] ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
        [ 148.591466] type=1503 audit(1291544369.709:16): operation=”open” pid=1614 parent=1572 profile=”/sbin/dhclient3″ requested_mask=”r::” denied_mask=”r::” fsuid=0 ouid=0 name=”/var/lib/wicd/dhclient.conf”
        [ 158.732053] wlan1: no IPv6 routers present
        [ 166.731689] lo: Disabled Privacy Extensions
        [ 1282.072087] usb 1-1: new full speed USB device using uhci_hcd and address 3
        [ 1282.291841] usb 1-1: configuration #1 chosen from 1 choice

  4. Eric Apperley said

    Here is the solution.

    You need a rule for udev that assigns a persistent usb device for the AVRISP Mk II programmer. Create a file such as “avr.rules” in the custom rules directory for udev, “/etc/udev/rules.d”.

    For a discussion on writing udev rules see the article :

    http://hackaday.com/2009/09/18/how-to-write-udev-rules/

    Here is the content of the rule file. Note that you can add other devices like the JTAG programmer/emulator etc. in addition to the AVRRISP device if you want to alternate with different programmers.

    # This file maintains persistent names for ATMEL Programmer/Debugger type devices.
    # See udev(7) for syntax.
    #
    SUBSYSTEM!=”usb_device”, ACTION!=”add”, GOTO=”avr_end”

    # Atmel Corp. AVRISP mkII
    SYSFS{idVendor}==”03eb”, SYSFS{idProduct}==”2104″, MODE=”660″, GROUP=”dialout”

    LABEL=”avr_end”

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

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: