Go Down

Topic: pgm_read_byte problems w Arduino v12 ? (Read 1 time) previous topic - next topic


I have some font tables for an LED display stored in prog_mem, and the part of my demo that uses them isn't working right using 12, although it works fine with 11.  Has anyone else seen problems with progmem using the new arduino or new compiler ?


It looks like the prog_uchar is broken in Arduino 12 (or gcc4, or something.)  The typedef in hardware/tools/avr/avr-4/include/avr/pgmspace.gh looks ok, but for some reason it doesn't seem to propagate the PROGMEM attribute to data structures that use it.  In this test program:
Code: [Select]
#include <avr/pgmspace.h>
prog_uchar myfont[40][5] = {
 { 0, 0, 0, 0, 0  }  , // space!
 { 0x3f, 0x48, 0x48, 0x48, 0x3f  }  , // A
 { 0x7f, 0x49, 0x49, 0x49, 0x36  }  ,
 { 0x3e, 0x41, 0x41, 0x41, 0x22  }

void ht1632_putchar(byte x, byte y, char c)
 byte dots;

 for (char col=0; col< 5; col++) {
   dots = pgm_read_byte_near(&myfont[c][col]);
   Serial.print("pgmspace: ");
   Serial.print((long)&myfont[c][col], HEX);
   Serial.print(" = ");
   Serial.println(dots, HEX);

void setup()

void loop()
 ht1632_putchar(0, 0, 1);


Does not work correctly w Arduino 12 (DOES work with 11!), and examining with avr-size or looking at disassembly (avr-objdump -S) shows that it is putting the font in ram instead of in flash.
Changing the font declaration to:
Code: [Select]
prog_uchar PROGMEM myfont[40][5]
returns the program to a working state.


This appears to be specific to g++; gcc does more reasonable things.
I've started a thread on avr-freaks:

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131