avr-gcc, error: unknown type name 'prog_char'

ArticleCategory: [Choose a category, do not translate this]


AuthorImage:[Here we need a little image from you]

[Photo of the Author]

TranslationInfo:[Author + translation history. mailto: or http://homepage]

original in en Guido Socher

AboutTheAuthor:[A small biography about the author]

Guido likes Linux because it is a really good system to develop your own hardware.

Abstract:[Here you write a little summary]

Avr-libc has removed in version 1.8 the datatype prog_char. That is: as of atmel avrtoolchain-3.2.4 you will not be able to compile a lot of older code. Almost all tuxgraphics code is affected by this and we will update the code over time but it will take several month to do that.

This article explains how to compile old code with the new avr-libc without updating the code. It explains as well how the access to data in program memory should now be used with the new avr-libc.

ArticleIllustration:[This is the title picture for your article]


ArticleBody:[The article body]

How to compile old tuxgraphics code ?

Obviously one solution is to simply use the older compiler with the old code and it will work with no problem. You can find a link to the older avrtoolchain-3.2.3 further down.

The other solution is to add an option to the variable CFLAGS in the Makefile. This will enable the old behavior of the avr library and you will be able to compile the old code with the new compiler.
Look for a line starting with CFLAGS in the file Makefile and add "-Wno-deprecated-declarations -D__PROG_TYPES_COMPAT__" at the end.

Like this:
Change this line:
CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues

CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues -Wno-deprecated-declarations -D__PROG_TYPES_COMPAT__

That's it! Just run "make" and you will be able to compile the code with no error or warning.

How to use the new "prog_char" when writing your own code?

The data type prog_char has disappeared! You use now the compiler directive PROGMEM to declare a variable that shell reside in program memory. Like this:
#include <avr/io.h>
#include <avr/pgmspace.h>
const char str_pstr[] PROGMEM = "FLASH STRING";
A function that takes such a datatype would the need to look like this:
void lcd_puts_p(const char *progstr ) 
        char c;
        while ((c = pgm_read_byte(progstr++))) {
It is a good convention to call such a function that takes a string from program memory "_p" in its name.

You would call the function from your code as follows:
There is as well the possibility to use a macro (the macro is part of the avr-libc) that will create a program memory string on the spot without the need to declare an own variable at the top of your code: