<?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: Loading data to /  from flash</title>
		<link>http://forums.leaflabs.com/topic.php?id=1009</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:13:06 +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=1009" rel="self" type="application/rss+xml" />

		<item>
			<title>samtal on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6812</link>
			<pubDate>Mon, 10 Oct 2011 11:47:48 +0000</pubDate>
			<dc:creator>samtal</dc:creator>
			<guid isPermaLink="false">6812@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;As I wrote (and you agreed):&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Lets close this issue for now.&#60;br /&#62;
Thanks for your support that was overwhelming.&#60;br /&#62;
I am sure I will need more of it.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;samtal
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6810</link>
			<pubDate>Mon, 10 Oct 2011 08:57:14 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6810@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;samtal -&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;The issue was with ram to flash, which you gave initially the impression that can be solved (was it my impression only?), while now you insist it is impossible.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Yes it is only your impression.&#60;br /&#62;
I did not mean to suggest that &#60;code&#62;memcpy(flash_array, ram_array, sizeof(flash_array));&#60;/code&#62; could work.&#60;br /&#62;
I had thought I was very clear and explicit, but I must believe that was not the case for you.&#60;/p&#62;
&#60;p&#62;Please post links, and ideally quotes, to my posts which caused that misunderstanding.&#60;br /&#62;
I will endeavour to fix them so that no-one else will misunderstand.&#60;/p&#62;
&#60;p&#62;I did find sentences which might have been unclear, so I have edited them to try minimise the chances of anyone else misunderstanding.&#60;/p&#62;
&#60;p&#62;I believe that memcpy(flash, ram, ...) is not practical, and has never been practical &#60;/p&#62;
&#60;p&#62;(I think there is a special case, where it will work, but that has only caused confusion.)&#60;/p&#62;
&#60;p&#62;So I am going to be unambiguous and say memcpy(flash, ram, ...) WILL NEVER EVER WORK.&#60;br /&#62;
Even though I believe that is slightly inaccurate.&#60;/p&#62;
&#60;p&#62;Maybe this metaphor will help.&#60;br /&#62;
NEVER EVER jump (or fall) from an aeroplane, while it is in more than 1000 feet up the air, without a working parachute, you will die.&#60;/p&#62;
&#60;p&#62;Clearly, that isn't *always* true.&#60;br /&#62;
People have fall from an aeroplane without a parachute, and survived. Maybe badly injured, but not dead.&#60;br /&#62;
&#60;a href=&#34;http://www.topyaps.com/top-10-people-who-survived-against-all-odds/&#34; rel=&#34;nofollow&#34;&#62;http://www.topyaps.com/top-10-people-who-survived-against-all-odds/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Of course you can go try the experiment. Maybe you have an approach which I don't understand, and we will gain from your discovery.&#60;/p&#62;
&#60;p&#62;Nevertheless, IMHO both my statements are extremely good rules of thumb for most people.&#60;/p&#62;
&#60;p&#62;I did suggest writing a function&#60;br /&#62;
&#60;code&#62;int write_flash(byte flash_buffer[], byte ram_buffer[], uint num_bytes) {...}&#60;/code&#62;&#60;br /&#62;
to develop something like memcpy.&#60;br /&#62;
Specifically write_flash would contain all of the flash-controller code as well as the uint16 memory copy.&#60;/p&#62;
&#60;p&#62;I am not suggesting &#60;em&#62;you&#60;/em&#62; do not spend time on trying to make&#60;br /&#62;
&#60;code&#62;memcpy(flash_array, ram_array, sizeof(flash));&#60;/code&#62;&#60;br /&#62;
work. You are of course free to do whatever you wish.&#60;/p&#62;
&#60;p&#62;I think it might be possible to get memcpy to work for the special case of two bytes, unit16 aligned.&#60;br /&#62;
IMHO, that is merely an interesting engineering curiosity, with no practical value to the use case you described.&#60;br /&#62;
I am not going to spend another moment of time on it.&#60;br /&#62;
I am unlikely to try to answer any more questions on it because I seem unable to be clear enough.&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>samtal on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6809</link>
			<pubDate>Mon, 10 Oct 2011 00:23:05 +0000</pubDate>
			<dc:creator>samtal</dc:creator>
			<guid isPermaLink="false">6809@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;/p&#62;
&#60;p&#62;Thanks for your detailed reply, but I believe we are wasting unnecessary words and our precious time.&#60;/p&#62;
&#60;p&#62;There was no big issue with flash to ram.&#60;br /&#62;
The issue was with &#60;strong&#62;ram to flash&#60;/strong&#62;, which you gave initially the impression that can be solved (was it my impression only?), while now you insist it is impossible.&#60;/p&#62;
&#60;p&#62;I fully agree with the first statement, while with the other I would say 'never say never'.&#60;br /&#62;
We can not see a solution now, and probably it is not worth the bother, but &#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;memcpy(flash_array, ram_array, sizeof(flash));&#60;br /&#62;
will never work. &#60;strong&#62;It will never work no matter what you do &#60;/strong&#62;with the flash memory controller. It can not work.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62; seems too far to declare.&#60;br /&#62;
Lets close this issue for now.&#60;br /&#62;
Thanks for your support that was overwhelming.&#60;br /&#62;
I am sure I will need more of it.&#60;/p&#62;
&#60;p&#62;And, back to an older non-related question:&#60;br /&#62;
When compiling the IDE, I can see that the compiler builds a .cpp file, but I can not find that file.&#60;br /&#62;
Is this a virtual or ram file, or can it be accessed and edited?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6801</link>
			<pubDate>Sun, 09 Oct 2011 18:17:57 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6801@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;samtal - How can I make it any clearer?&#60;/p&#62;
&#60;p&#62;-------- case 1 ------&#60;br /&#62;
FLASH TO RAM&#60;br /&#62;
This case is extremely similar to RAM to RAM&#60;br /&#62;
memcpy(demo_array,flash_array,sizeof(demo_array))&#60;br /&#62;
always works for valid addresses.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;SerialUSB.println((int)memcpy(demo_array,flash_array,sizeof(demo_array)),HEX);&#60;/code&#62;&#60;br /&#62;
works for me. It works every time for valid addresses.&#60;br /&#62;
I can only think of one way to stop it working.&#60;br /&#62;
It just works.&#60;br /&#62;
You do not have to do anything at all to make it work.&#60;br /&#62;
You do not have to unlock flash, or use the flash keys.&#60;br /&#62;
DO NOTHING to the flash controller.&#60;/p&#62;
&#60;p&#62;memcpy(ram, flash, sizeof(ram)) works.&#60;/p&#62;
&#60;p&#62;In fact, do NOT even TRY to do anything to the flash controller because that is the only thing that can make it fail (with valid addresses)&#60;/p&#62;
&#60;p&#62;&#60;strong&#62;&#60;em&#62;memcpy FROM flash TO ram WILL ALWAYS WORK.&#60;/em&#62;&#60;/strong&#62;&#60;br /&#62;
&#60;em&#62;It never ever fails for valid addresses, unless the flash memory controller is busy. &#60;/em&#62;&#60;/p&#62;
&#60;p&#62;So for all uses of memcpy()  for case 1, where the code does not attempt to use the Flash memory controller, and the addresses are valid, memcpy() always work.&#60;/p&#62;
&#60;p&#62;------ case 2 -------&#60;br /&#62;
RAM TO FLASH&#60;br /&#62;
this is &#60;strong&#62;NOT&#60;/strong&#62; like RAM to RAM, or FLASH to RAM&#60;br /&#62;
memcpy(flash_array,demo_array,sizeof(flash_array))&#60;br /&#62;
does not work&#60;/p&#62;
&#60;p&#62;&#60;code&#62;SerialUSB.println((int)memcpy(flash_array,demo_array,sizeof(demo_array)),HEX);&#60;/code&#62;&#60;br /&#62;
never works for me.&#60;/p&#62;
&#60;p&#62;It does not matter if you use the Flash keys. That will not make it work.&#60;br /&#62;
It does not matter if you unlock Flash.  That will not make it work&#60;/p&#62;
&#60;p&#62;memcpy() will never ever work, no matter what sequence of Flash controller commands are used.&#60;/p&#62;
&#60;p&#62;&#60;strong&#62;&#60;em&#62;memcpy FROM ram TO flash will NEVER work. &#60;/em&#62;&#60;/strong&#62; (Note 1)&#60;/p&#62;
&#60;p&#62;&#60;strong&#62;IT WILL NEVER EVER WORK&#60;/strong&#62; (Note 1)&#60;br /&#62;
So for all uses of memcpy() for case 2, no matter what you do to the Flash memory controller, memcpy() will not work&#60;br /&#62;
If you do nothing with the Flash memory controller, memcpy() for case 2 will not work.&#60;br /&#62;
memcpy() is not useful for copying memory for case 2.&#60;/p&#62;
&#60;p&#62;---------------------------------------&#60;/p&#62;
&#60;p&#62;You have read the flash memory programming manual. So I assume you understand how it works.&#60;br /&#62;
You have written the code to copy from ram to flash in your original program, and you got it to work.&#60;br /&#62;
It tests every single write to flash memory. That is necessary for it to work.&#60;/p&#62;
&#60;p&#62;memcpy does not do that test. &#60;/p&#62;
&#60;p&#62;None of the memxxx functions, builtins or macros are likely to do that test because they are generic memory-copying code designed to work on every CPU that C has ever run on.&#60;br /&#62;
I think this is a sufficient explanation of why&#60;br /&#62;
memcpy(flash_array,demo_array,sizeof(flash_array))&#60;br /&#62;
will not work.&#60;/p&#62;
&#60;p&#62;The memxxx functions and builtins assume RAM to RAM.&#60;br /&#62;
(and implicitly FLASH to RAM, because the processor can just read Flash without any special machine code instructions)&#60;/p&#62;
&#60;p&#62;Those memxxx functions do not know about writing to Flash.&#60;/p&#62;
&#60;p&#62;You read in the Flash memory programming manual, you have to do an extra bunch of steps to program Flash.&#60;/p&#62;
&#60;p&#62;&#60;em&#62;YOU HAVE TO WRITE THE CODE TO COPY FROM RAM TO FLASH&#60;/em&#62;&#60;/p&#62;
&#60;p&#62;You have already written the code in your earlier program. There is no work to do. It is done.&#60;/p&#62;
&#60;p&#62;----------------&#60;br /&#62;
Summary:&#60;br /&#62;
&#60;code&#62;memcpy(ram_array, flash_array, sizeof(ram));&#60;/code&#62;&#60;br /&#62;
will always work, if you leave the flash memory controller alone.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;memcpy(flash_array, ram_array, sizeof(flash));&#60;/code&#62;&#60;br /&#62;
will never work. It will never work no matter what you do with the flash memory controller. It can not work. (Note 1)&#60;/p&#62;
&#60;p&#62;Is this clear?&#60;/p&#62;
&#60;p&#62;(Note 1: I think there is a way to copy exactly and only two bytes, but IMHO, there is no point wasting time on it. I'm not going to, it only confuses the issue)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>samtal on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6800</link>
			<pubDate>Sun, 09 Oct 2011 17:21:12 +0000</pubDate>
			<dc:creator>samtal</dc:creator>
			<guid isPermaLink="false">6800@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;/p&#62;
&#60;p&#62;We seem to be beating around the bush and never getting to the point or solution.&#60;/p&#62;
&#60;p&#62;At the end of all, you typed the same code I have sent that does not work, and you do not show the reason why.&#60;br /&#62;
Did you try make it work? did it work for you?&#60;br /&#62;
If it does, please let me know what am I doing wrong?&#60;/p&#62;
&#60;p&#62;Your comment  &#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;NEVER needs the Flash to be in program mode.&#60;br /&#62;
That memcpy() will work correctly without the FLASH_BASE-&#38;gt;CR &#124;= 1&#38;lt;&#38;lt;0; and FLASH_BASE-&#38;gt;CR = 0x80;&#60;/blockquote&#62;
 makes no sense to me (unless it works for you!?).&#60;/p&#62;
&#60;p&#62;The memcpy is a generic C/C++ macro that does not relate to flash, just to memory.&#60;br /&#62;
It does not know if the addressed memory location is flash, SRAM, DRAM or EPROM or whatever, or if it is STM32 or Microchip or Intel.&#60;br /&#62;
On the other hand, the STM32 flash can not be programmed without unlocking the double key, erasing the target (if not clear) and setting the program bit.&#60;br /&#62;
My logical conclusion is that one MUST unlock and set the program bit for a copy to flash to succeed. (It must also be 16 bits half word, no more no less).&#60;/p&#62;
&#60;p&#62;Actually, as I found no clean (or any) solution to the use of the memcpy for copying from / to STM32 Maple flash, I gave up and wrote my byte-by-byte copy function.&#60;/p&#62;
&#60;p&#62;If you want to play with the macros (there are more, like memmove, memset, etc. that may need similar treatment) and can make the memcpy work with flash, you'll be blessed. I have good use for it, but little time to struggle with a non-critical function in my project.&#60;br /&#62;
Thanks,&#60;br /&#62;
samtal
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6773</link>
			<pubDate>Fri, 07 Oct 2011 14:26:39 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6773@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;samtal&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;As you have probably seen before, I know how to copy from flash to ram and back, as well as dumping the flash (see &#60;a href=&#34;http://pastebin.com/h0CxGRQ7)&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/h0CxGRQ7)&#60;/a&#62;.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Yes, and very well done for slogging through the manuals and making that work. Kudos to you.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;The question here was how to use the memcpy macro to copy a block of data in both directions without the need for loop iterations.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Okay. I think I understand.&#60;br /&#62;
EDIT: It won't  work in both directions.&#60;br /&#62;
memcpy(flash_array,demo_array,sizeof(demo_array)),HEX); will not work&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I have built a small IDE test program that I can not make to work. It is at &#60;a href=&#34;http://pastebin.com/CDKv0WTd&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/CDKv0WTd&#60;/a&#62;.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Thank you very much for taking the time to post that code.&#60;br /&#62;
I find it is much easier to work from specific code, rather than a forum post. There is less chance of making a mistake.&#60;/p&#62;
&#60;p&#62;I apologise that my previous explanation was not clear. Please let me try again.&#60;/p&#62;
&#60;p&#62;Edit:&#60;br /&#62;
I have read your program, and I have tried to run it.&#60;br /&#62;
It does not work in the form you posted.&#60;br /&#62;
There are several errors.&#60;/p&#62;
&#60;p&#62;I think I understand what line 37 is trying to do, but it can not work:&#60;br /&#62;
 &#60;code&#62;Serial1.println((int)memcpy(flash_array,demo_array,sizeof(demo_array)),HEX);&#60;/code&#62; &#60;/p&#62;
&#60;p&#62;Edit: for all practical purposes &#60;code&#62;memcpy(flash_array,demo_array,sizeof(demo_array))&#60;/code&#62; does not work.&#60;/p&#62;
&#60;p&#62;AFAIK, your other program - &#60;a href=&#34;http://pastebin.com/h0CxGRQ7&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/h0CxGRQ7&#60;/a&#62;&#60;br /&#62;
works correctly.&#60;br /&#62;
In that program, every pair of bytes it tries to write to flash, it checks the FLASH_BASE-&#38;gt;SR bit (lines 356 &#38;amp; 357):&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;while (FLASH_BASE-&#38;gt;SR &#38;amp; (1&#38;lt;&#38;lt;0)) {
    }&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I am very sure memcpy() does not do that check. &#60;/p&#62;
&#60;p&#62;My suggestion in &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1009&#38;amp;page=2#post-6507&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1009&#38;amp;page=2#post-6507&#60;/a&#62; was to wrap that up in something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;int write_flash(byte flash_buffer[], byte ram_buffer[], uint num_bytes) {...}
// returns the number of bytes written from ram_buffer to flash_buffer
// or &#38;lt;0 if an error. This looks like memcpy() BUT
// this requires flash_buffer to be a valid flash memory address&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I can see where I may have caused confusion, and failed to clarify in my subsequent posts. I apologise.&#60;/p&#62;
&#60;p&#62;Conversely, the memcpy() between lines 50-53:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;FLASH_BASE-&#38;gt;CR &#124;= 1&#38;lt;&#38;lt;0;  //Set flash program bit
Serial1.println((int)memcpy(demo_array,flash_array,sizeof(demo_array)),HEX);
//Lock the flash
FLASH_BASE-&#38;gt;CR = 0x80;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;NEVER needs the Flash to be in program mode.&#60;br /&#62;
That memcpy() will work correctly without the &#60;code&#62;FLASH_BASE-&#38;gt;CR &#124;= 1&#38;lt;&#38;lt;0;&#60;/code&#62; and &#60;code&#62;FLASH_BASE-&#38;gt;CR = 0x80;&#60;/code&#62; so&#60;br /&#62;
&#60;code&#62;Serial1.println((int)memcpy(demo_array,flash_array,sizeof(demo_array)),HEX);&#60;/code&#62;&#60;br /&#62;
is all that is needed.&#60;br /&#62;
Edit: this memcpy() works.&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>samtal on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6771</link>
			<pubDate>Fri, 07 Oct 2011 09:34:26 +0000</pubDate>
			<dc:creator>samtal</dc:creator>
			<guid isPermaLink="false">6771@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;/p&#62;
&#60;p&#62;As you have probably seen before, I know how to copy from flash to ram and back, as well as dumping the flash (see &#60;a href=&#34;http://pastebin.com/h0CxGRQ7)&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/h0CxGRQ7)&#60;/a&#62;.&#60;/p&#62;
&#60;p&#62;The question here was how to use the memcpy macro to copy a block of data in both directions without the need for loop iterations.&#60;br /&#62;
I have built a small IDE test program that I can not make to work. It is at &#60;a href=&#34;http://pastebin.com/CDKv0WTd&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/CDKv0WTd&#60;/a&#62;.&#60;/p&#62;
&#60;p&#62;I am asking if someone can take a look at that test program and either make it work or tell me what needs to be done.&#60;/p&#62;
&#60;p&#62;The problem may be in a casting or addressing, or in the fact that the RAM is read in bytes, while writing to flash must be done in 16 bits half-words (See STM PM0075 Flash manual).&#60;br /&#62;
samtal
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6767</link>
			<pubDate>Thu, 06 Oct 2011 16:54:38 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6767@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;samtal - I don't understand your comments,&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I literally meant to copy from RAM to flash (and vise verse), thus the order of parameters was what I meant (and should work both directions).&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;It &#34;should work both directions&#34; If, and only if, (IFF) flash is &#34;programmable&#34;.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;memcpy()&#60;/code&#62; should always work from Flash to RAM, even if the flash is not programmable, because that is how the processor must work.&#60;/p&#62;
&#60;p&#62;So you could write something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;setup() {
    delay(5000);      // give 5 seconds to start the serial console
    SerialUSB.println(&#38;quot;Dump flash: &#38;quot;);
    for (byte* p=(byte*)0x08000000; p&#38;lt;=(byte*)0x0801FFFF; ++p) {
        SerialUSB.print(*p,HEX);
        SerialUSB.print(&#38;quot; &#38;quot;);
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Where 0x08000000 is the start address of flash memory, and 0x0801FFFF is the end address of flash memory.&#60;/p&#62;
&#60;p&#62;That should work in any case (on STM32F103xB), it doesn't need the Flash memory to be in &#34;program mode&#34;.&#60;br /&#62;
So I don't think there is much to be deduced from memcpy(demo_data, flash_array, sizeof(demo_data));&#60;/p&#62;
&#60;p&#62;EDIT: &#60;strong&#62;But memcpy() from RAM to Flash will never work.&#60;/strong&#62;&#60;/p&#62;
&#60;p&#62;It is as simple as that. End of story. Done. Nothing else to know. Finished.&#60;/p&#62;
&#60;p&#62;(WARNING: I have not compiled and tested that code, it's only an illustration)&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>samtal on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6759</link>
			<pubDate>Wed, 05 Oct 2011 14:01:08 +0000</pubDate>
			<dc:creator>samtal</dc:creator>
			<guid isPermaLink="false">6759@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer, &#60;/p&#62;
&#60;p&#62;Thanks for your reply.&#60;br /&#62;
I literally meant to copy from RAM to flash (and vise verse), thus the order of parameters was what I meant (and should work both directions).&#60;br /&#62;
From ST PM0075 Flash manual: &#34;The embedded Flash module can be addressed directly, as a common memory space&#34;.&#60;br /&#62;
I tried your proposed corrections (and many other options), but, as before it does not work.&#60;br /&#62;
One direction copies RAM to RAM (not to flash), while when switching direction the Maple crashes.&#60;/p&#62;
&#60;p&#62;memcpy(flash_array,demo_data,sizeof(demo_data) will output:&#60;br /&#62;
Copy demo data from:200012F8 to  (crash)&#60;/p&#62;
&#60;p&#62;memcpy(demo_data,flash_array,sizeof(demo_data) will output:&#60;br /&#62;
Copy demo data from:200012F8 to 200012F8  (RAM to RAM, same address!).&#60;/p&#62;
&#60;p&#62;Can you or someone else please try to run the program and find what is wrong??&#60;/p&#62;
&#60;p&#62;samtal
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=3#post-6756</link>
			<pubDate>Tue, 04 Oct 2011 20:21:42 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6756@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;samtal - The line:&#60;br /&#62;
&#60;code&#62;SerialUSB.println((uint32)memcpy(flash_array,&#38;amp;demo_data,num_cells),HEX);&#60;/code&#62;&#60;br /&#62;
is incorrect.&#60;/p&#62;
&#60;p&#62;The way to remember what memcpy does is to think of it as&#60;br /&#62;
&#60;code&#62;first-array = second-array&#60;/code&#62;&#60;br /&#62;
so the parameters in your code are the wrong way round, and your code is trying to copy RAM to Flash, which will not work, and may explain the error.&#60;/p&#62;
&#60;p&#62;Secondly. I wouldn't take the address of an array &#60;code&#62;&#38;amp;demo_data&#60;/code&#62;, because an array name is already an address.&#60;br /&#62;
I think it actually gives the correct value when the variable name is a global array, but I believe it would be wrong if the variable was a parameter (2am here), so I wouldn't write that expression.&#60;/p&#62;
&#60;p&#62;I would write the address this way:&#60;br /&#62;
&#60;code&#62;SerialUSB.println((uint32)memcpy(demo_data, flash_array, num_cells),HEX);&#60;/code&#62;&#60;br /&#62;
but this is also okay&#60;br /&#62;
&#60;code&#62;SerialUSB.println((uint32)memcpy(&#38;amp;demo_data[0], flash_array, num_cells),HEX);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;But I wouldn't write the line that way anyway because it isn't clear that num_cells means the number of bytes you want to copy (which is what memcpy needs), or the number of cells of the array you want to copy  (which are uint16).&#60;/p&#62;
&#60;p&#62;I'd write something like:&#60;br /&#62;
&#60;code&#62;SerialUSB.println((uint32)memcpy(demo_data, flash_array, num_cells*sizeof(uint16)),HEX);&#60;/code&#62;&#60;br /&#62;
because it seems clearer.&#60;/p&#62;
&#60;p&#62;In reality, I wouldn't bother trying to keep track of the amount of array used. I'd just copy the entire array back and forth, and hence write:&#60;br /&#62;
&#60;code&#62;SerialUSB.println((uint32)memcpy(demo_data, flash_array, sizeof(demo_data)),HEX);&#60;/code&#62;&#60;br /&#62;
which should be a bit more fool proof.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>samtal on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=2#post-6747</link>
			<pubDate>Tue, 04 Oct 2011 12:49:49 +0000</pubDate>
			<dc:creator>samtal</dc:creator>
			<guid isPermaLink="false">6747@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks mbolivar,&#60;/p&#62;
&#60;p&#62;As you can see in my code, (in a second commented line, starting with 'or'), I have tried first gbulmers version, but when it failed I tried another option (Need to correct [sizeof(ram_array)] to [PAGE_SIZE]).&#60;br /&#62;
Unfortunately, neither works (I tried even more options).&#60;/p&#62;
&#60;p&#62;Did you try running the program? Did it work for you?&#60;/p&#62;
&#60;p&#62;The interesting thing is that if I set the copy length (num bytes) to 1 or 2, it seems to work, and I get back an address in the flash, but any other number of bytes &#38;gt;2 crash.&#60;/p&#62;
&#60;p&#62;For the full program, I get 'Copy demo data from:200012F8 to', and it crashes.&#60;br /&#62;
For bytes to copy 2, I get: 'Copy demo data from:200012F8 to 8008800' which seems right.&#60;/p&#62;
&#60;p&#62;I have tried everything I know (which apparently isn't enough), but for no avail.&#60;br /&#62;
(I have the feeling it is a variable type or casting problem?)&#60;/p&#62;
&#60;p&#62;And 2 more, non-related:&#60;br /&#62;
1. Regarding the backticks; I did not see your edit in my code. (I naturally always ready to learn..)&#60;/p&#62;
&#60;p&#62;2. A general question: On each compile (IDE), I see that the compiler builds a C++ file. Is that file available? can I see or edit it? (I couldn't find it, and it looks like a RAM or virtual file??). &#60;/p&#62;
&#60;p&#62;samtal
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=2#post-6738</link>
			<pubDate>Mon, 03 Oct 2011 16:26:18 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6738@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;samtal,&#60;/p&#62;
&#60;p&#62;this appears to be a simple copy-paste error. you wrote:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;uint8 flash_array[PAGE_SIZE] _FLASH_H_ __PAGE_ALIGNED__;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;but gbulmer wrote:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;uint8 flash_array[sizeof(ram_array)] __FLASH__ __PAGE_ALIGNED__;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;note that you wrote &#60;code&#62;_FLASH_H_&#60;/code&#62; instead of &#60;code&#62;__FLASH__&#60;/code&#62;.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;_FLASH_H_&#60;/code&#62; is the #define used by flash.h to prevent recursive inclusion. &#60;code&#62;__FLASH__&#60;/code&#62; is a macro that directs the compiler to store a variable in flash.  see:&#60;/p&#62;
&#60;p&#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;/p&#62;
&#60;p&#62;edit: By the way, you can put code within backticks (the ` character underneath ~ on most US keyboards) in order to preserve formatting.  i have edited your post to use this feature; i hope you don't mind.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>samtal on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=2#post-6736</link>
			<pubDate>Mon, 03 Oct 2011 04:50:11 +0000</pubDate>
			<dc:creator>samtal</dc:creator>
			<guid isPermaLink="false">6736@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi,&#60;br /&#62;
I have tried hard the above advices with many variations, but still can not copy an array from RAM to Flash.&#60;br /&#62;
Here is a small IDE program that is supposed to copy a small array from the RAM to the Flash  (I added flash unlock and lock. I guess this is required).&#60;/p&#62;
&#60;p&#62;As can be seen by running the program, it copies from the original RAM location to another RAM location rather than to the flash.&#60;br /&#62;
I don't understand where is the flash address specified in the attribute.&#60;br /&#62;
What is wrong with this program?&#60;br /&#62;
samtal&#60;/p&#62;
&#60;p&#62;/************Program begins here*********************/&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;//Maple IDE memcpy test from RAM to flash by samtal Oct 3,2011

#include &#38;quot;stdlib.h&#38;quot;      //Included explicitly for proper data printing.
#include &#38;quot;flash.h&#38;quot;
#include &#38;quot;string.h&#38;quot;

#define PAGE_SIZE 1024
#define __PAGE_ALIGNED__ __attribute__((aligned (PAGE_SIZE)))
uint8 flash_array[PAGE_SIZE] _FLASH_H_ __PAGE_ALIGNED__;
//or uint8 flash_array[sizeof(ram_array)] __FLASH__ __PAGE_ALIGNED__;

uint16 demo_data[1024]; //Build the demo array in the setup()
uint16 num_cells=100;  //Set up the number of demo cells to copy.

void setup()
{
//Build the demo array
  for (uint16 d=0;d&#38;lt;num_cells;d++)
  {
    demo_data[d]=0xFFFF-d;
  }
}

void loop()  

{
delay(1000);

  //Unlock flash:
  FLASH_BASE-&#38;gt;KEYR = 0x45670123;   //The STM Key1
  FLASH_BASE-&#38;gt;KEYR = 0xCDEF89AB;   //The STM Key2

SerialUSB.println();
SerialUSB.print(&#38;quot;Copy demo data from:&#38;quot;);
SerialUSB.print((uint32)&#38;amp;demo_data,HEX);
SerialUSB.print(&#38;quot; to &#38;quot;);
SerialUSB.println((uint32)memcpy(flash_array,&#38;amp;demo_data,num_cells),HEX);

//Lock the flash
FLASH_BASE-&#38;gt;CR = 0x80;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;/******************End of program**************************/
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=2#post-6719</link>
			<pubDate>Sat, 01 Oct 2011 08:41:13 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6719@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;samtal - memcpy() does work&#60;br /&#62;
mbolivar explains how here:&#60;br /&#62;
&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1076#post-6620&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1076#post-6620&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The 'trick' is to&#60;br /&#62;
&#60;code&#62;#include &#38;lt;string.h&#38;gt;&#60;/code&#62;&#60;br /&#62;
near the top of your program. That declares memcpy (and a bunch of other functions), so the error message should go away.&#60;/p&#62;
&#60;p&#62;As mbolivar explains on that thread, the IDE links against newlib, which provides many of the standard C functions.&#60;br /&#62;
The documentation for newlib is at &#60;a href=&#34;http://sourceware.org/newlib/&#34; rel=&#34;nofollow&#34;&#62;http://sourceware.org/newlib/&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>samtal on "Loading data to /  from flash"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1009&amp;page=2#post-6718</link>
			<pubDate>Sat, 01 Oct 2011 00:41:13 +0000</pubDate>
			<dc:creator>samtal</dc:creator>
			<guid isPermaLink="false">6718@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Kind members,&#60;/p&#62;
&#60;p&#62;Thank you all for your support.&#60;br /&#62;
To the best of my knowledge, 'memcpy' and other C/C++ commands you use in your examples are not recognized by the Maple IDE and thus generate errors.&#60;br /&#62;
As I use the IDE, such commands are of no use to me (have I missed something?).&#60;br /&#62;
For the IDE we need lower level commands, or better drivers.  &#60;/p&#62;
&#60;p&#62;When, in the past, I suggested that someone knowledgeable will write a driver for the dual adc, I was opposed by several members claiming that Maple has more important tasks.&#60;br /&#62;
I therefore made my own unprofessional solution that, if used by others, may lead to errors and bugs.&#60;br /&#62;
The same happened with the flash program.&#60;br /&#62;
I made my own flash handling program, but it is an IDE program rather than C/C++, which I am forced to include as code in my main IDE, making it too long and difficult to handle.&#60;br /&#62;
I wish to use the flash program as an included external c file, but I do not have the knowledge for doing it right.&#60;br /&#62;
Can anyone lift that glove and convert my IDE (&#60;a href=&#34;http://pastebin.com/h0CxGRQ7&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/h0CxGRQ7&#60;/a&#62;) into a viable C/C++ included file?&#60;br /&#62;
This has to be done anyhow to make the Maple useful for a wider range of potential users. &#60;/p&#62;
&#60;p&#62;samtal
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
