Pikir dan Rasa

cogito ergo sum

Geany untuk pemrograman Atmel AVR di GNU Linux (Ubuntu)

with 7 comments

Bekerja dengan IDE Eclipse (tentu dengan plugin avr-eclipse) terkadang terasa cukup berat, apalagi kalau mempergunakan mesin yang processing power-nya tidak kuat. Salah satu alternatifnya adalah dengan menggunakan Geany. Agar lebih mudah dipergunakan, berikut ada opsi kompilasi yang sering dipakai.

Untuk memasukkan baris perintah, klik pada “Set Build Commands”


Silahkan copy & paste contoh command pada kotak masukkan.


[Command, alternative 1]


avr-gcc -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-alh,-L -o %e.elf -c "%f"


avr-objcopy -j .text -O ihex %e.elf %e.hex

[Command, alternative 2]


avr-gcc -mmcu=atmega8 -DF_CPU=8000000 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -std=gnu99 -Wa,-adhlns=%e.lst %e.c -o %e.o


avr-gcc -mmcu=atmega8 -DF_CPU=8000000 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -std=gnu99 -Wa,-adhlns=%e.o --output %e.elf -Wl,-Map=%.map,--cref -c "%f"


Buat file hex untuk flashing:

avr-objcopy -O ihex -R .eeprom %e.elf %e.hex

Optional compiler flags.

-g:        generate debugging information (for GDB, or for COFF conversion)

-O*:       optimization level

-f…:     tuning, see gcc manual and avr-libc documentation

-Wall…:  warning level

-Wa,…:   tell GCC to pass this to the assembler.

-ahlms:  create assembler listing

CFLAGS = -g -O$(OPT) \

-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \

-Wall -Wstrict-prototypes \

-Wa,-adhlns=$(<:.c=.lst) \

$(patsubst %,-I%,$(EXTRAINCDIRS))

sumber: contoh makefile


Catatan opsi:

-I.    => With ‘-I.’ you can specify searching the directory which was current when the compiler was invoked. That is not exactly the same as what the preprocessor does by default, but it is often satisfactory. [Dari manual GCC] 


-Os    => Optimize for size. ‘-Os’ enables all ‘-O2’ optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
‘-Os’ disables the following optimization flags:
-falign-functions -falign-jumps -falign-loops
-falign-labels -freorder-blocks -freorder-blocks-and-partition
-fprefetch-loop-arrays -ftree-vect-loop-version
-g    => On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but will probably make other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms (see).
-Wall    => This enables all the warnings about constructions that some users
consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.
-Wstrict-prototypes    => Warn if a function is declared or defined without specifying the argument types. (An old-style function definition is permitted without a warning if preceded by a declaration which specifies the argument types.)

Catatan mengenai opsi  -Wa,-adhlns

If you are invoking as via the gnu C compiler (version 2), you can use the ‘-Wa’ option to pass arguments through to the assembler. The assembler arguments must be separated from each other (and the ‘-Wa’) by commas. For example:

gcc -c -g -O -Wa,-alh,-L file.c

This passes two options to the assembler: ‘-alh’ (emit a listing to standard output with with high-level and assembly source) and ‘-L’ (retain local symbols in the symbol table).

Usually you do not need to use this ‘-Wa’ mechanism, since many compiler command-line options are automatically passed to the assembler by the compiler. (You can call the gnu compiler driver with the ‘-v’ option to see precisely what options it passes to each compilation pass, including the assembler.)

2.1 Enable Listings: -a[cdhlns]

These options enable listing output from the assembler. By itself, ‘-a’ requests high-level, assembly, and symbols listing.

You can use other letters to select specific options for the list: ‘-ah’ requests a high-level language listing, ‘-al’ requests an output-program assembly listing, and ‘-as’ requests a symbol table listing. High-level listings require that a compiler debugging option like ‘-g’ be used, and that assembly listings (‘-al’) be requested also.

Use the ‘-ac’ option to omit false conditionals from a listing. Any lines which are not assembled because of a false .if (or .ifdef, or any other conditional), or a true .if followed by an .else, will be omitted from the listing.

Use the ‘-ad’ option to omit debugging directives from the listing. Once you have specified one of these options, you can further control listing output and its appearance using the directives .list, .nolist, .psize, .eject, .title, and .sbttl.

The ‘-an’ option turns off all forms processing. If you do not request listing output with one of the ‘-a’ options, the listing-control directives have no effect.

The letters after ‘-a’ may be combined into one option, e.g., ‘-aln’.

Note if the assembler source is coming from the standard input (eg because it is being created by gcc and the ‘-pipe’ command line switch is being used) then the listing will not contain any comments or preprocessor directives. This is because the listing code buffers input source lines from stdin only after they have been preprocessed by the assembler. This reduces memory usage and makes the code more efficient.

sumber: Documentation for binutils

Untuk option (pilihan) lain pada baris perintah dapat dilihat pada dokumentasi GCC. Berikut adalah link (tautan) untuk dokumen-dokumen GCC dan AVR LIBC (avr-gcc), silahkan memilih dengan menyesuaikan versi dari software yang dipergunakan.

sunu@sunu-HP-Mini-110-1000:~/projects/test$ gcc --version

  1. GCC online documentation
  2. http://download.savannah.gnu.org/releases/avr-libc/
  3. http://www.nongnu.org/avr-libc/
  4. http://www.nongnu.org/avr-libc/user-manual/index.html

Written by sunupradana

August 28, 2011 at 4:58 pm

Posted in Embedded Systems

Tagged with , , ,

7 Responses

Subscribe to comments with RSS.

  1. Terima kasih, Kang. Saya butuh cara konfigurasi build di IDE. Geany ini contoh yang sangat baik.

    Ade Malsasa Akbar

    January 10, 2014 at 10:51 am

  2. Posting yang bagus mas, saya mau mencobanya tetapi ada keraguan.

    C untuk avr di compile oleh avr-gcc, sedangkan C untuk komputer di compile oleh gcc dan sepertinya menggunakan parameter yang berbeda juga. Bisakah kita mengantisipasi agar geany dapat mengetahui, saya membuat program ini untuk avr atau komputer?

    terima kasih


    April 12, 2014 at 9:36 am

    • AFAIK, kan sudah menggunakan avr-gcc untuk avr.


      April 26, 2014 at 12:15 pm

      • Maksud saya, adakah cara agar geany tau kita ingin men-compile dengan gcc atau avr-gcc.

        saya memiliki ide jika kita ingin menggunakan avr-gcc (ngoding avr) kita gunakan ekstensi yang berbeda misalnya *.cavr. Lalu pada proses compilenya geany diberikan perintah : cp namafile.cavr namafile.c && avr-gcc bla bla bla. Sedangkan saat kita ingin compile dengan gcc, kita cukup memberikan ekstensi .c dan compile dilakukan dengan gcc namafile -o namafile.

        maaf jika hal tersebut tidak memungkinkan


        April 27, 2014 at 8:01 am

      • Ide bagus. Saya belum tahu jawabnya🙂 . Karena sejauh ini saya hanya pernah mencoba khusus untuk avr. Dulu saya menggunakan IDE yang berbeda untuk masing-masing.


        April 27, 2014 at 9:22 am

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

%d bloggers like this: