[SOLVED] Migrating a u8glib project to AVR Studio 4

Hello all,

I'm developing a project with Arduino Pro Mini 328 and an LCD screen. I'm using the u8glib library to drive the LCD. I've been using the standard Arduino IDE and everything worked fine, except for the fact that every time I change something in my code, the IDE recompiles everything including thousands of u8glib files, which takes about 5 minutes.

So I decided to start using a more advanced IDE, and I chose AVR Studio 4 and AVR-GCC. I've succeeded in compiling a simple "blink" program and uploading it to Arduino (via avrdude from the standard IDE). But I can't manage to compile a program which would use u8glib.

  • Is there a way to prevent the standard Arduino IDE from recompiling the code which did not change, and/or from recompiling external libraries?
  • When I compile the program in Arduino IDE, I can find many semi-compiled files in the temp folder. I've copied core.a to my AVR Studio project to enable standard Arduino functions such as digitalWrite. Is it possible to find analogous semi-compiled files for u8glib and take them as well, so that I would only have to link them?
  • On the u8glib site there are two categories of downloads: for Arduino and for AVR. The files inside are pretty much the same. Which library should I use? I ended up using the library for Arduino because the AVR library doesn't contain u8g.c with LCD-specific constructors. Is it correct?
  • The AVR-GCC compiler found many many errors in the u8glib code. I had to fix them manually until it finally got compiled. Are there serious language differences between AVR-GCC and the Arduino IDE compiler? Or maybe there are some compiler options I should set?

I can post error descriptions and project settings' screenshots, but at first I hope that there is some simpler solution...

Hi

Is there a way to prevent the standard Arduino IDE from recompiling the code which did not change, and/or from recompiling external libraries?

I might be wrong, but i thought that 1.5.2 or the latest AVR release 1.0.4 (?) was more smarter than previous release.

On the u8glib site there are two categories of downloads: for Arduino and for AVR. The files inside are pretty much the same. Which library should I use? I ended up using the library for Arduino because the AVR library doesn't contain u8g.c with LCD-specific constructors. Is it correct?

The AVR release of U8glib does not include the C++ wrapper. You need to use the C API.

The AVR-GCC compiler found many many errors in the u8glib code. I had to fix them manually until it finally got compiled. Are there serious language differences between AVR-GCC and the Arduino IDE compiler? Or maybe there are some compiler options I should set?

I have created a step by step tutorial for U8glib and AVR-Studio 6: Google Code Archive - Long-term storage for Google Code Project Hosting.
What kind of compiler errors did you find? I do use different versions of AVR-GCC with u8glib without problem.

The development of U8glib is done 100% on Ubuntu with a Makefile environment. Build time is much faster with a good makefile.

Oliver

olikraus:
I might be wrong, but i thought that 1.5.2 or the latest AVR release 1.0.4 (?) was more smarter than previous release.

I was using 1.0.3. Now I installed 1.5.2, it's a bit faster (3 minutes) but still recompiles everything.

olikraus:
What kind of compiler errors did you find? I do use different versions of AVR-GCC with u8glib without problem.

These are my project settings (I'm on Windows by the way):

Most errors were like this:
../../u8glib/src/u8g_com_arduino_std_sw_spi.c:108: error: invalid conversion from 'void*' to 'uint8_t*'
../../u8glib/src/u8g_com_io.c:142: error: expected primary-expression before 'volatile'

I made corrections to the source files, and now they apparently compile but don't link:
u8g_com_arduino_sw_spi.o: In function u8g_com_arduino_do_shift_out_msb_first': D:\My Documents\arduino\AVRStudio\test_lcd1\default/../../u8glib/src/u8g_com_arduino_sw_spi.c:73: multiple definition of u8g_bitData'
u8g_com_arduino_st7920_spi.o:D:\My Documents\arduino\AVRStudio\test_lcd1\default/../../u8glib/src/u8g_com_arduino_st7920_spi.c:74: first defined here
make: *** [test_lcd1.elf] Error 1

By the way, I was trying to compile using avr-g++.exe for some time, now I switched back to avr-gcc.exe in the project settings but apparently AVR Studio is still calling avr-g++.exe during compilation, I don't understand why.

For the link stage of U8glib it is also important to add -Wl,--gc-sections

See also Google Code Archive - Long-term storage for Google Code Project Hosting.

For the compile error. What has been the code around line 142? Did you apply the correct controller type?

Oliver

SOLVED! XD
I've compiled and uploaded the program. I noticed that all "multiple definition" conflicts were between u8g_com_arduino_sw_spi.c and u8g_com_arduino_st7920_spi.c. I removed u8g_com_arduino_st7920_spi.c from the project and it compiled and linked successfully. Also, after it got to the finish for the first time, subsequent compilations are done very quickly: if I change something in my code, the whole program is compiled in just a few seconds. The compiler is given all u8glib files but understands that they do not have to be compiled again. So, I'm absolutely happy and can now go on to actual programming :slight_smile:

Though, there are some questions left, just of curiosity:

  • Why is my AVR Studio still launching avr-g++ when I have selected avr-gcc in project settings? (I think that the compilation errors were caused by trying to compile C code by a C++ compiler.)
  • Is it normal that two files from the u8glib package are conflicting with each other? Can it also be caused by the C++ compiler not understanding some C-specific defines or something?

olikraus:
For the link stage of U8glib it is also important to add -Wl,--gc-sections

Yes, I have that in the [Linker Options] section.

olikraus:
See also Google Code Archive - Long-term storage for Google Code Project Hosting.

I have set up my project according to that tutorial, but I tried not to make significant changes to Arduino code and keep the C++ constructor... Probably that's why I switched to avr-g++...

olikraus:
For the compile error. What has been the code around line 142? Did you apply the correct controller type?

One type of errors was caused by lines like this:

register uint8_t *ptr = arg_ptr;

error: invalid conversion from 'void*' to 'uint8_t*'

So I added explicit casts everywhere. The error at line 142 was:

memcpy_P(&tmp, base, sizeof(volatile uint8_t * PROGMEM));

../../u8glib/src/u8g_com_io.c:142: error: expected primary-expression before 'volatile'
../../u8glib/src/u8g_com_io.c:142: error: expected `)' before 'volatile'

I've fixed it by removing PROGMEM. I don't fully understand what it is, but I hope that a pointer has the same size even if it's volatile and PROGMEM. Anyway it works :wink:

PROGMEM should be defined by the avr lib. I also have never observed conflicts in the source file (but there might be some).

But i am glad to hear that it's working now.

Oliver