Eclipse AVR – installation of u8glib library

Recently, one of my readers requested me to write an instruction how to run graphic library  U8glib for Eclipse IDE with AVR plugin. Installation of the library is very similar to installing Atmel Studio plugin.
 

 

 

1. Download and unzip the archive with our library which can be downloaded HERE 

 

2. Run Eclipse and create a New C Project.

 

New_Project

  • Select AVR Cross Target Static Library
  • and give name to the project, ex. ‘u8glib’.

Static_Library

  • Click 2x Next and select your microcontroller type and frequency.
  • I chose ATmega16 on which I am testing this library and set my frequency to 1MHz.

MCU_Type

3. Adding library files

 

  • Right click our project in Project Explorer
  • and choose Import from the list.

Import

  • A window will pop up in which you choose the import source.
  • Expand General branch and select File System.

File_System

  • On the next window click Browse
  • and choose the path where library files are located. On my computer it was C:\u8glib\src
  • Select all files and click Finish.

Import_SRC

  • Project Explorer should look like this:

Project_Explorer

4. Editing project properties

 

  • Right click our project in Project Explorer and choose Properties from the bottom of the list.

Properties

  • Choose C/C++ Build -> Settings from the new window.
  • Then, choose All configurations from Configuration listbox at the top of the window.
  • Then, select Tool Settings -> AVR Compiler -> Symbols and define new symbol F_CPU=1000000UL which is responsible for our microcontroller clock frequency. As I mentioned earlier, I used 1MHz. This value is dependent on what frequency we plan to use in our project.

Symbols

  • After that, choose Optimization from the tree on the left.
  • Select Size Optimizations (-Os) from the Optimization Level listbox.
  • We also need to add additional flags. In Other Optimization Flags type in: -ffunction-sections -fdata-sections

Optimization

5. Building a library

 

  • Now we have to build our library, so we can use it.
  • Click on a hammer icon and wait. It should compile in about 30 seconds.

Build

6. Creating a project

 

  • We create the project in the same way we did at the beginning of the tutorial, the only difference is Project Type, this time it is AVR Cross Target Application.

Test

7. Editing a project settings

 

  • As we did before, define a symbol F_CPU=1000000UL

Test_Properties

  • Now change the optimization options, once again select Size Optimizations (-Os) from the Optimization Level listboxand add additional flags.
  • In Other Optimization Flags type in: -ffunction-sections -fdata-sections

Test_Optimization

  • Then go to AVR C Linker -> Libraries and in Other Arguments type in: -Wl,--gc-sections

Test_Linker

  • Go to AVR Compiler -> Directories and add a directory ..\..\u8glib by clicking on a green plus icon.

Test_Directories

  • After that click AVR C Linker -> Libraries and add a name of the library which is u8glib. u8glib
  • In Libraries Path add a directory for the library ..\..\u8glib\Debug

Test_Patch

  • All of the given directories are relative paths and points to the folder in which our u8glib library files are located.
8. Creating a sample program

 

  • There’s nothing left for us than to add a new file with .c extension to our project.
  • We can now copy and paste a sample code there, like a classic “Hello world”.
/*
 *  Na podstawie https://code.google.com/p/u8glib/wiki/thelloworld
 *  Testowane na ATmega16
 *  Autor: Gembcior
 *  https://gembcior.pl
 */

#include "u8g.h"
#include <avr/interrupt.h>
#include <avr/io.h>

u8g_t u8g;

void draw(void)
{
  u8g_SetFont(&u8g, u8g_font_6x10);
  u8g_DrawStr(&u8g, 10, 20, "Hello World!");
}

int main(void)
{
  /*
    CS: PORTB, Bit 4 --> PN(1,4)
    A0: PORTB, Bit 3 --> PN(1,3)
    SCK: PORTB, Bit 7--> PN(1,7)
    MOSI: PORTB, Bit 5 --> PN(1,5)
  */
	u8g_InitSPI(&u8g, &u8g_dev_st7565_dogm128_sw_spi, PN(1, 7), PN(1, 5), PN(1, 4), PN(1, 3), U8G_PIN_NONE);
	u8g_SetContrast(&u8g,55); // Ustawienie kontrastu

	for(;;)
	{
		u8g_FirstPage(&u8g);
		do
		{
			draw();
		} while ( u8g_NextPage(&u8g) );
		u8g_Delay(100);
	}
}
  • Compile it and program the microcontroller.

Test_Build

 

In this tutorial I was using Eclipse Kepler in 32bit version with AVR plugin in 2.4 Version and Atmel Toolchain 3.4.2.1573

Eclipse AVR – installation of u8glib library
Ocena: 5 (1 głosów)

No Comments

Leave a Reply

*

*

Ile jest * Time limit is exhausted. Please reload CAPTCHA.

banner

This site uses cookies to store information on your computer. Click for more details

Our site uses cookies to personalise site content and advertisement, to offer social network functions and to analyse traffic on our website. Information we gather about using our website are shared with our social media, advertisement and analytical partners. You can find more info on How Google uses data when you use our partners' sites or apps.

Close