Go Down

Topic: print from flash memory broken on DUE? (Read 3019 times) previous topic - next topic

zachtos

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?


IR Combat laser tag developer/inventor

zachtos

#1
Apr 04, 2013, 02:54 am Last Edit: Apr 04, 2013, 03:02 am by zachtos Reason: 1
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: [Select]

#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
IR Combat laser tag developer/inventor

OutOfLine

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)

Markus_L811


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

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

zachtos


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: [Select]

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
}
IR Combat laser tag developer/inventor

OutOfLine



... and the RAM function I run will show FREE RAM go up alot when converting to flash memory storage.
Code: [Select]

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...

zachtos

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.
IR Combat laser tag developer/inventor

stimmer

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

Code: [Select]

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:

Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

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!

Arduino
via Egeo 16
Torino, 10131
Italy