<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Problem with external PROGMEM data.</title>
		<link>http://forums.leaflabs.com/topic.php?id=1481</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:16:28 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1481" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Problem with external PROGMEM data."</title>
			<link>http://forums.leaflabs.com/topic.php?id=1481#post-9820</link>
			<pubDate>Sun, 18 Mar 2012 15:58:56 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">9820@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;RichardE - you can define a macro which converts PROGMEN to nothing, so you can keep some level of source code compatibility with Arduino. But as I wrote elsewhere, you will be losing a lot of benefits of using a Maple.&#60;/p&#62;
&#60;p&#62;You might want to create two macros, one to be used as a storage class of the data you want to store in Flash, and the other as the storage qualifier of pointers. Then you could move back and forth between Arduino and Maple more easily. The data storage class for Maple could be __FLASH__, and the qualifier on pointers would be empty. The data storage class and pointer qualifier for Arduino would be PROGMEM.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;is __FLASH__ the only way to put data in program memory?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Under the covers, there are several types of memory segment, or section, which get stored in Flash. If you look at the definition:&#60;br /&#62;
&#60;code&#62;#define __FLASH__ __attr_flash&#60;/code&#62;&#60;br /&#62;
which leads to&#60;br /&#62;
&#60;code&#62;#define __attr_flash __attribute__((section (&#38;quot;.USER_FLASH&#38;quot;)))&#60;/code&#62;&#60;br /&#62;
You can see one, but there is also &#60;code&#62;.text&#60;/code&#62; which contains all of the program code, usually &#60;code&#62;.ro_data&#60;/code&#62;, etc. &#60;/p&#62;
&#60;p&#62;The link scripts, startup code, and running program make assumptions about each one. I'd recommend using __FLASH__ for now because the support is in place. But you could go look at the stuff inside the Maple IDE.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;If you declare data as const will that not do it?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;In general &#60;code&#62;const&#60;/code&#62; does not &#60;strong&#62;guarantee&#60;/strong&#62; that values are stored in Flash.&#60;br /&#62;
I think a combination of compiler flags and linker scripts will do it for processors like ARM, where there is a single address space. By default, &#60;code&#62;const&#60;/code&#62; is interpreted by the compiler as an instruction to it to check that code doesn't try to change a value, and a hint which may allow it to optimise generated code more effectively.&#60;/p&#62;
&#60;p&#62;Further, on the Arduino's AVR processor, the compiler can't attempt to put 'const' in flash because (as I explained elsewhere) the instructions which read data from program memory are different from the ones that read data from RAM. So to put &#60;code&#62;const&#60;/code&#62; into Flash on an AVR processor could be a disaster because pointers to it couldn't be handed to functions which would be expecting to get data from data memory (RAM).&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of leafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>RichardE on "Problem with external PROGMEM data."</title>
			<link>http://forums.leaflabs.com/topic.php?id=1481#post-9116</link>
			<pubDate>Sat, 17 Mar 2012 06:01:26 +0000</pubDate>
			<dc:creator>RichardE</dc:creator>
			<guid isPermaLink="false">9116@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I thought about using __FLASH__ and I may do it that way later. I just wanted (as far as possible) to keep the code the same as the Arduino version for now.&#60;/p&#62;
&#60;p&#62;Incidentally, is __FLASH__ the only way to put data in program memory? If you declare data as const will that not do it? The GD.h file has this line in it :&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#define PROGMEM const&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;and I assumed that put all data declared as PROGMEM in flash.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "Problem with external PROGMEM data."</title>
			<link>http://forums.leaflabs.com/topic.php?id=1481#post-9101</link>
			<pubDate>Sat, 17 Mar 2012 05:49:02 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">9101@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You probably have enough RAM to get rid of PROGMEM ... but here's the info from the FAQ&#60;br /&#62;
  &#60;a href=&#34;http://leaflabs.com/docs/arm-gcc.html#arm-gcc-attribute-flash&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/arm-gcc.html#arm-gcc-attribute-flash&#60;/a&#62;&#60;br /&#62;
Lots of earlier discussions on forum regarding PROGRMEM ...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>RichardE on "Problem with external PROGMEM data."</title>
			<link>http://forums.leaflabs.com/topic.php?id=1481#post-9077</link>
			<pubDate>Sat, 17 Mar 2012 05:33:10 +0000</pubDate>
			<dc:creator>RichardE</dc:creator>
			<guid isPermaLink="false">9077@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Update: If I wrap the character set data up as static members of a class like this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;/*
 * SOURCE FILE : RobotRicCharacterSet.h
 *
 * Contains character set data for RobotRic game.
 *
 */

#ifndef RobotRicCharacterSetIncluded

  #define RobotRicCharacterSetIncluded

  #include &#38;lt;GD.h&#38;gt;

  class RobotRicCharacterSet {

  public :

    static PROGMEM prog_uchar PixelData[];
    static PROGMEM prog_uchar PaletteData[];

  };

#endif

/* END of RobotRicCharacterSet.h */&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;then I don't get the errors. Weird.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>RichardE on "Problem with external PROGMEM data."</title>
			<link>http://forums.leaflabs.com/topic.php?id=1481#post-9059</link>
			<pubDate>Sat, 17 Mar 2012 05:21:19 +0000</pubDate>
			<dc:creator>RichardE</dc:creator>
			<guid isPermaLink="false">9059@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I just got my REV 5 Maple and have it plugged into a Gameduino and am trying to port a program that works fine on an Arduino.&#60;/p&#62;
&#60;p&#62;Seem to have hit a snag when referencing data declared as extern. Here's a test program I wrote:&#60;/p&#62;
&#60;p&#62;*** File TestCharset.pde ***&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;GD.h&#38;gt;
#include &#38;quot;RobotRicCharacterSet.h&#38;quot;

#define RAM_CHR_SIZE 4096        // size of character set pixel data RAM
#define RAM_PAL_SIZE 2048        // size of character set palette data RAM

void setup( void ) {
  PROGMEM prog_uchar *ptr;
  // Initialise Gameduino.
  GD.begin();
  // Initialise character set pixel data RAM.
  ptr = RobotRicCharacterSetPixelData;
  // GD.copy( RAM_CHR, ptr, RAM_CHR_SIZE );
  // Initialise character set pixel palette RAM.
  ptr = RobotRicCharacterSetPaletteData;
  // GD.copy( RAM_PAL, ptr, RAM_PAL_SIZE );
}

void loop( void ) {
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;*** File RobotRicCharacterSet.h ***&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;GD.h&#38;gt;
extern PROGMEM prog_uchar RobotRicCharacterSetPixelData[];
extern PROGMEM prog_uchar RobotRicCharacterSetPaletteData[];&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;*** File RobotRicCharacterSet.cpp (edited for brevity) ***&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;GD.h&#38;gt;
PROGMEM prog_uchar RobotRicCharacterSetPixelData[] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Character 0
0x00, 0x00, 0x15, 0x55, 0x1A, 0xAA, 0x1B, 0xFF, 0x1B, 0xFF, 0x1B, 0xEA, 0x1B, 0xE5, 0x1B, 0xE4, // Character 1
0x00, 0x00, 0x55, 0x55, 0xAA, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, 0x55, 0x55, 0x00, 0x00, // Character 2
0x00, 0x00, 0x55, 0x54, 0xAA, 0xA4, 0xFF, 0xE4, 0xFF, 0xE4, 0xAB, 0xE4, 0x5B, 0xE4, 0x1B, 0xE4, // Character 3

... and so on ...

0xBD, 0x7E, 0xC1, 0x43, 0xC6, 0x93, 0x5A, 0xA5, 0x5A, 0xA5, 0xC6, 0x93, 0xC1, 0x43, 0xBD, 0x7E, // Character 253 (ý)
0xBD, 0x7E, 0xC1, 0x43, 0xC6, 0x93, 0x5A, 0xA5, 0x5A, 0xA5, 0xC6, 0x93, 0xC1, 0x43, 0xBD, 0x7E, // Character 254 (þ)
0x3F, 0xFC, 0xFF, 0xFF, 0xFB, 0xEF, 0xFF, 0xFF, 0xFE, 0xBF, 0xDF, 0xF7, 0xF5, 0x5F, 0x3F, 0xFC, // Character 255 (ÿ)
};
PROGMEM prog_uchar RobotRicCharacterSetPaletteData[] = {
0xFF, 0x7F, 0xE0, 0x03, 0x1F, 0x7C, 0x00, 0x80, // Character 0
0x10, 0x00, 0x1F, 0x00, 0x1F, 0x42, 0x1F, 0x63, // Character 1
0x10, 0x00, 0x1F, 0x00, 0x1F, 0x42, 0x1F, 0x63, // Character 2
0x10, 0x00, 0x1F, 0x00, 0x1F, 0x42, 0x1F, 0x63, // Character 3

... and so on ...

0xFF, 0x7F, 0xE0, 0x03, 0x1F, 0x7C, 0x00, 0x00, // Character 253 (ý)
0xFF, 0x7F, 0xE0, 0x03, 0x1F, 0x7C, 0x00, 0x00, // Character 254 (þ)
0x00, 0x00, 0xE0, 0x03, 0xE0, 0x7F, 0x00, 0x7C, // Character 255 (ÿ)
};&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;As it stands the test program compiles OK. If I uncomment the lines calling GD.copy I get the message :&#60;/p&#62;
&#60;p&#62;&#38;lt;BUILD&#38;gt;/TestCharset.cpp:19: undefined reference to `RobotRicCharacterSetPixelData'&#60;br /&#62;
&#38;lt;BUILD&#38;gt;/TestCharset.cpp:19: undefined reference to `RobotRicCharacterSetPaletteData'&#60;/p&#62;
&#60;p&#62;What's going on? How come it can find them when I don't call GD.copy but it cannot when I do?&#60;/p&#62;
&#60;p&#62;Note: GD.h is James Bowman's work from here : &#60;a href=&#34;http://excamera.com/files/Gameduino_m.zip&#34; rel=&#34;nofollow&#34;&#62;http://excamera.com/files/Gameduino_m.zip&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The only clue I have is that the second parameter to copy is declared as prog_uchar *src rather than PROGMEM prog_uchar *src but I would not expect it to generate this error.&#60;/p&#62;
&#60;p&#62;Any help appreciated.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
