Problem w/ <avr/pgmspace.h> and 3pi

Hi,
I got the following warning when i try to use the print_from_program_space() function in a very simple program.

…/main.c:10: warning: ‘progmem’ attribute ignored

The program ===============================================================

#include <avr/pgmspace.h>
#include <pololu/3pi.h>

int main(void)
{
	const char smile[] PROGMEM = "Hello!";
	
	print_from_program_space(smile);

	while(1)
	;
	return 0;
}

==========================================================================

I use AVR studio 4 version 4.14 and WinAVR-20080610.

What might be wrong?

Best Regards, Gunnar

Hello.

You should declare your program-space data the way you would global variables. If you move your variable declaration outside of your main function, it should fix your problem:

#include <avr/pgmspace.h>
#include <pololu/3pi.h>

const char smile[] PROGMEM = “Hello!”;

int main(void)
{

print_from_program_space(smile);

while(1)
;
return 0;
}

- Ben

It would also work to make your variable “static”, as in the following code.

int main(void)
{
static const char smile[] PROGMEM = “Hello!”;
print_from_program_space(smile);
while(1) ;
return 0;
}

The point is that the PROGMEM attribute applies only to static variables, not to local variables, which are necessarily allocated on the stack, and thus cannot be put into program memory.

1 Like