Hi all and thanks in advance,
For the past week I have been scouring the web and this site with great interest in trying to answer the perennial question - can you store an array in PROGMEM that is larger than 64k bytes on the Mega2560?
My application is that I want to store a dictionary of 10,000 words in PROGMEM statically through compilation in the usual way prescribed here and in other places:
#include <avr/pgmspace.h>
const char* a_dict PROGMEM = "a";
const char* aa_dict PROGMEM ="aa";
const char* aaa_dict PROGMEM ="aaa";
const char* aaron_dict PROGMEM ="aaron";
const char* ab_dict PROGMEM ="ab";
const char* abandoned_dict PROGMEM ="abandoned";
const char* abc_dict PROGMEM ="abc";
//.
//.
//.
//etc 10,000 lines of words. The total size of all the characters+null termination bytes in all the words is 75.5k. ...then...
const char* dictionary[] PROGMEM = {a_dict, aa_dict,aaa_dict,aaron_dict,ab_dict,abandoned_dict,abc_dict // 10000 char* vars worth
};
//then some way to access the dictionary yet to be decided
void setup(){}
void loop(){
char* x; //a place holder for a recovered string
int index; //some sort of index
//something like strcpy_PF(x, (char*)pgm_read_word_far(&(dictionary[index])));
// yadda yadda, do something with x
}
The problem I run into is the thing will not compile. I get an assembler error saying that "Error: value of 68731 is too large to fit into 2 bytes at xyz" which of course is true for any number bigger than 2^16
So I'm thinking there must be some secret incantation to get it to be understood that I need addressing to somehow be far/long/etc...somehow at least 1 bit more than 16 bits of addressing. It looks like by reading the various .h files and .cpp files in the avr libs that there is a register called RAMPZ that is used in the extension of the addressing to allow addressing more than 64K of flash. But how to get that to happen?
In all my reading I find a lot of info on how to access data placed above the 64k boundary - but nobody says how to get the compiler to put it up there in the first place. Is there a parameter? Is there a typedef I'm missing? Or - does the compiler just simply do it for you when you set things up correctly.
Should I divide up my dictionary of words into 2 pieces, each less than 64k? Then perhaps I could do something like attribute((section(".someothersection"))); to get it to go in some other place?
Any guidance would be muchly appreciated.
Quite humbly,
Joe