Pages: [1]   Go Down
Author Topic: pgm_read_byte problems w Arduino v12 ?  (Read 1030 times)
0 Members and 1 Guest are viewing this topic.
SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6637
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6637
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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()
{
  Serial.begin(57600);
}

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

  delay(30000);
}

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:
prog_uchar PROGMEM myfont[40][5]
returns the program to a working state.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6637
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This appears to be specific to g++; gcc does more reasonable things.
I've started a thread on avr-freaks:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=515844#515844
Logged

Pages: [1]   Go Up
Jump to: