Pages: [1]   Go Down
Author Topic: print from flash memory broken on DUE?  (Read 2415 times)
0 Members and 1 Guest are viewing this topic.
Michigan
Offline Offline
Newbie
*
Karma: 1
Posts: 33
IR Combat
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

error: 'PSTR' was not declared in this scope

example:
  Serial.print(F("FAIL"));  //print the word 'FAIL' from flash memory, not RAM

vs.
  Serial.print("FAIL"); //print the word 'FAIL' from RAM, but this uses RAM very fast

Why am I getting this compile error in Aruino 1.52?  Do I need to add another library to be able to simply print from flash on the serial ports or using the LCD library?


Logged

IR Combat laser tag developer/inventor

Michigan
Offline Offline
Newbie
*
Karma: 1
Posts: 33
IR Combat
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/forum/index.php/topic,153761.0.html

I can't tell, but is the above thread a solution, or work in progress?

copying this into my header fixed it for me for now.


Code:
#if defined(__SAM3X8E__)
    #define PROGMEM
    #define pgm_read_byte(x)        (*((char *)x))
//  #define pgm_read_word(x)        (*((short *)(x & 0xfffffffe)))
    #define pgm_read_word(x)        ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
    #define pgm_read_byte_near(x)   (*((char *)x))
    #define pgm_read_byte_far(x)    (*((char *)x))
//  #define pgm_read_word_near(x)   (*((short *)(x & 0xfffffffe))
//  #define pgm_read_word_far(x)    (*((short *)(x & 0xfffffffe)))
    #define pgm_read_word_near(x)   ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
    #define pgm_read_word_far(x)    ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x))))
    #define PSTR(x)  x
  #if defined F
    #undef F
  #endif
  #define F(X) (X)
#endif
« Last Edit: April 03, 2013, 08:02:57 pm by zachtos » Logged

IR Combat laser tag developer/inventor

Offline Offline
Jr. Member
**
Karma: 1
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

cmaglie has done this already:
see https://github.com/arduino/Arduino/issues/1317

If you manage to run the version from github it should work,
*IF* you manage...
  (as I still don't)
Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

cmaglie has done this already:
see https://github.com/arduino/Arduino/issues/1317

If you manage to run the version from github it should work,
*IF* you manage...
  (as I still don't)

A howto to build an IDE from the git files is there
http://code.google.com/p/arduino/wiki/BuildingArduino
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8593
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you sure

Serial.print("FAIL");

Uses RAM on the Due. I would have thought on the ARM architecture constants are kept in flash anyway and the P macro is redundant.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Michigan
Offline Offline
Newbie
*
Karma: 1
Posts: 33
IR Combat
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you sure

Serial.print("FAIL");

Uses RAM on the Due. I would have thought on the ARM architecture constants are kept in flash anyway and the P macro is redundant.

_____
Rob

I'm pretty sure, unless they changed it in the last few versions.  My game has a lot of text and the RAM function I run will show FREE RAM go up alot when converting to flash memory storage.

Code:
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

/////called in the upgrade code/regen function like this
void RAM()
{
  clearLCD();
  mySerial.print(F("Free RAM: ")); //debug code
  mySerial.print(freeRam());   //debug code
}
Logged

IR Combat laser tag developer/inventor

Offline Offline
Jr. Member
**
Karma: 1
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


... and the RAM function I run will show FREE RAM go up alot when converting to flash memory storage.
Code:
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}
}

Had tried that a while ago. I could not figure out how to get __bss_end and __brkval defined...
Logged

Michigan
Offline Offline
Newbie
*
Karma: 1
Posts: 33
IR Combat
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just used the RAM(); function in my main loop to print the FREE ram to screen, I did not change anything else, copy paste was it.  I think that came from the WaveHC library files.
Logged

IR Combat laser tag developer/inventor

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I guess one way of testing it is to try printing a string over 96K long...

Code:
void setup() {
Serial.begin(1200);
}

void loop() {
  Serial.print(
"\n"
"ACT I\n"
"SCENE I. A desert place.\n"
"\n"
"    Thunder and lightning. Enter three Witches \n"
"\n"
"First Witch\n"
"\n"
"    When shall we three meet again\n"
"    In thunder, lightning, or in rain?\n"
"\n"
"Second Witch\n"
"\n"
"    When the hurlyburly's done,\n"
"    When the battle's lost and won.\n"
"\n"
"Third Witch\n"
"\n"
"    That will be ere the set of sun.\n"
"\n"

... over 100K later....

"MALCOLM\n"
"\n"
"    We shall not spend a large expense of time\n"
"    Before we reckon with your several loves,\n"
"    And make us even with you. My thanes and kinsmen,\n"
"    Henceforth be earls, the first that ever Scotland\n"
"    In such an honour named. What's more to do,\n"
"    Which would be planted newly with the time,\n"
"    As calling home our exiled friends abroad\n"
"    That fled the snares of watchful tyranny;\n"
"    Producing forth the cruel ministers\n"
"    Of this dead butcher and his fiend-like queen,\n"
"    Who, as 'tis thought, by self and violent hands\n"
"    Took off her life; this, and what needful else\n"
"    That calls upon us, by the grace of Grace,\n"
"    We will perform in measure, time and place:\n"
"    So, thanks to all at once and to each one,\n"
"    Whom we invite to see us crown'd at Scone.\n"
"\n"
"    Flourish. Exeunt\n"

  );
}

Believe it or not, it works  smiley-mr-green


* macbeth.ino (127.62 KB - downloaded 16 times.)
Logged


Pages: [1]   Go Up
Jump to: