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

		<item>
			<title>mbolivar on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-3094</link>
			<pubDate>Sun, 12 Dec 2010 02:10:26 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">3094@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;structuresound -- thanks!&#60;/p&#62;
&#60;p&#62;will be having a look at this once 0.0.9 is out.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>structuresound on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-3050</link>
			<pubDate>Wed, 08 Dec 2010 02:17:40 +0000</pubDate>
			<dc:creator>structuresound</dc:creator>
			<guid isPermaLink="false">3050@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;mbolvar - I don't know much about contributing to repositories like github yet, so I've put the flash.c and flash.h files for you here &#60;a href=&#34;http://www.structuresound.com/maple/&#34; rel=&#34;nofollow&#34;&#62;http://www.structuresound.com/maple/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I would like to learn how to work with that kind of environment because I'm interested in contributing to the codebase, I'm just a little timid about it because I'm still very &#34;novice&#34; at coding in general.&#60;/p&#62;
&#60;p&#62;These don't have function definitions or implementations for the read/write functions that we've been discussing.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-3046</link>
			<pubDate>Tue, 07 Dec 2010 23:11:26 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">3046@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer - no, nothing stopping you, of course.&#60;/p&#62;
&#60;p&#62;structuresound - is this up anywhere?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>structuresound on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2968</link>
			<pubDate>Sat, 04 Dec 2010 01:36:06 +0000</pubDate>
			<dc:creator>structuresound</dc:creator>
			<guid isPermaLink="false">2968@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Also, in order to get things ready I wrapped the relevant functions from bootloader hardware.c/h into libmaple flash.c/h which requires a few of the defines from hardware.h, changing to the libmaple typdefs (i.e. u32 to uint32), include libmaple.h, and include usb_hardware.h&#60;/p&#62;
&#60;p&#62;This is my first time &#34;porting&#34; something albeit from one version of the same library to another, so I don't totally know what I'm doing but it seems to work great &#34;in practice&#34;.&#60;/p&#62;
&#60;p&#62;One weird thing is that I now get some compiler warnings for redefines between usb_hardware and rcc neither of which I modified and didn't repeat any of those defines in flash.h. They don't seem to halt the compile so I'm not sure what's up.&#60;/p&#62;
&#60;p&#62;Probably wouldn't take much more effort to wrap a couple of overloaded easy read/write functions make sure the pageclear is never less than 0x08005000 and call it a user eeprom library.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>structuresound on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2967</link>
			<pubDate>Sat, 04 Dec 2010 01:21:44 +0000</pubDate>
			<dc:creator>structuresound</dc:creator>
			<guid isPermaLink="false">2967@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bless you gbulmer, the union works like a charm. Only problem was that flashWriteWord doesn't want a pointer (it converts the address to a pointer internally, not sure why it's written this way). Here's what I did, to write use&#60;/p&#62;
&#60;p&#62;assuming myArray is the global variable I'm interested in storing&#60;br /&#62;
also I hardcoded 64 in there instead of sizeOf probably will return to &#34;macro'd&#34; now that everything is squared away.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void writeFlash(){
uint32 flashPtr = (uint32)0x08015000L;
flashErasePage(flashPtr);

  union { uint32 ui; uint8 ub[4]; } u;
  int i;
  u.ui = 0;
  for (i=0; i&#38;lt;64; i++) {
    u.ub[i%4] = myArray[i];
    if (i%4 == 3) { // time to write it
      flashWriteWord(flashPtr, u.ui);
      flashPtr += 0x04;
      u.ui = 0;
    }
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;to read the data back out of memory&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void readFlash(){
uint32 flashPtr = (uint32)0x08015000L;
  union { uint32 ui; uint8 ub[4]; } u;
  int i;
  u.ui = 0;
  for (i=0; i&#38;lt;64; i++) {
    if (i%4 == 0) {
      u.ui = *((uint32*)flashPtr);
      flashPtr += 0x04;
    }
    myArray[i] = u.ub[i%4];
  }
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>gbulmer on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2964</link>
			<pubDate>Fri, 03 Dec 2010 21:15:30 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2964@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Argh!£%^&#38;amp;*&#60;/p&#62;
&#60;p&#62;The formatting on this forum drives me nuts!&#60;br /&#62;
I can't get the spaces in front of &#60;code&#62;uint32 *flashPtr = (uint32 *)0x08010000L;&#60;/code&#62; to stay!&#60;/p&#62;
&#60;p&#62;GHAAARG!-(
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2963</link>
			<pubDate>Fri, 03 Dec 2010 21:02:43 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2963@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Spoiler alert&#60;br /&#62;
- This contains a suggestion for code&#60;br /&#62;
- ignore if you are having fun doing it your way&#60;/p&#62;
&#60;p&#62;If you have a byte array, you can do a truly horrible tricks with a pointer, but I won't encourage you (hint, use a pointer to the enum :-)&#60;/p&#62;
&#60;p&#62;Copy hardware.c and using my enum example above, do something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;uint32 *flashPtr = (uint32 *)0x08010000L;
  union { uint32 ui; uint8 ub[4]; } u;
  uint8 buff[100];
  int i;
  u.ui = 0;
  for (i=0; i&#38;lt;sizeof(buff); i++) {
    u.ub[i%4] = buff[i];
    if (i%4 == 3) { // time to write it
      flashWriteWord(flashPtr, u.ui);
      ++flashPtr;
      u.ui = 0;
    }
  }
  // now tidy up any remainder of 1, 2, or 3 bytes
  // using flashWriteWord(flashPtr, u.ui);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;(I didn't want to take away all the fun, so I left tidying up TODO :-)&#60;/p&#62;
&#60;p&#62;It isn't as compact as using a pointer, but avoids any issues of reading from non-aligned uint32's (which AFAIK is fine on Cortex-M3, but isn't supported on all ARM architectures)&#60;/p&#62;
&#60;p&#62;WARNING - I have not tested this code.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>structuresound on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2961</link>
			<pubDate>Fri, 03 Dec 2010 20:25:58 +0000</pubDate>
			<dc:creator>structuresound</dc:creator>
			<guid isPermaLink="false">2961@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;okay, cool that seems easier, I was trying this method:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;long l = 0;
    l &#124;= b[0] &#38;amp; 0xFF;
    l &#38;lt;&#38;lt;= 8;
    l &#124;= b[1] &#38;amp; 0xFF;
    l &#38;lt;&#38;lt;= 8;
    l &#124;= b[2] &#38;amp; 0xFF;
    l &#38;lt;&#38;lt;= 8;
    l &#124;= b[3] &#38;amp; 0xFF;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;now the byte arrays I want to copy are larger than 4 bytes, maybe I can use a 32 bit array pointer to step through 4 bytes at a time?&#60;/p&#62;
&#60;p&#62;I'll try a direct implementation of hardware.c and see what I can come up with.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2959</link>
			<pubDate>Fri, 03 Dec 2010 19:34:41 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2959@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;mbolivar - I assume there is nothing to stop us just using hardware.c directly. Correct?&#60;br /&#62;
Maybe, at some point in the future, factor out from hardware.c the flash functions, and put into their own file so that the Maple library API can use them too?&#60;/p&#62;
&#60;p&#62;structuresound - I'd just use hardware.c directly.&#60;/p&#62;
&#60;p&#62;All you need to do is pack 4 bytes into an unsigned int, or uint32 to avoid possible confusion. &#60;/p&#62;
&#60;p&#62;Packing can be done at the bit level with shifts, and's and or's, or you could try it with a &#60;code&#62;union&#60;/code&#62;. You likely know this, but for the benefit of readers who follow ...&#60;/p&#62;
&#60;p&#62;Whenever I use a &#60;code&#62;union&#60;/code&#62;, I always do a quick check to make sure it is going to work the way I want, e.g.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void loop() {
  union { uint32 ui; uint8 ub[4]; } u;
  if ( sizeof(u) == 4 ) { // Yipee, game on
    SerialUSB.print(&#38;quot;sizeof(u) is correctly reported as 4 bytes: &#38;quot;);
    SerialUSB.println(sizeof(u));
  } else {
    SerialUSB.print(&#38;quot;Unions will not work, sizeof(u) is not 4 bytes, it is reported as: &#38;quot;);
    SerialUSB.println(sizeof(u));
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I do the check because the C standard says that the behaviour of unions is implementation defined, so it can vary from compiler to compiler. But, IMHO, if it does work, byte packing using a union is easier to understand than bit packing.&#60;/p&#62;
&#60;p&#62;EDIT: WARNING - I have not tested this code.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2957</link>
			<pubDate>Fri, 03 Dec 2010 18:41:40 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">2957@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;structuresound -- yup, there's (currently) no libmaple support for writing flash, and there's no time-line in place for adding that support.  as you discovered, we do it in the bootloader only.  it's not on the critical path right now, although it's certainly reasonable for flash write support to get added to (at least) the libmaple C api.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>structuresound on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2954</link>
			<pubDate>Fri, 03 Dec 2010 17:32:53 +0000</pubDate>
			<dc:creator>structuresound</dc:creator>
			<guid isPermaLink="false">2954@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Seems like there are two prerequisites to read/write memory&#60;/p&#62;
&#60;p&#62;1) Set up RCC&#60;br /&#62;
2) Unlock Flash&#60;/p&#62;
&#60;p&#62;The methods for this are integrated into the bootloader hardware.h but not in the normal libmaple.&#60;/p&#62;
&#60;p&#62;Does it seem like a better solution to borrow these from the bootloader or to try and port STM's eeprom.h so that it fits in libmaple?&#60;/p&#62;
&#60;p&#62;If anybody else is successfully reading/writing words to upper flash around say 0x08010000 I'd love to hear about it, otherwise I'll keep plugging away and report back if I have any success.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>structuresound on "FlashWriteWord"</title>
			<link>http://forums.leaflabs.com/topic.php?id=550#post-2942</link>
			<pubDate>Thu, 02 Dec 2010 22:06:31 +0000</pubDate>
			<dc:creator>structuresound</dc:creator>
			<guid isPermaLink="false">2942@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Any further developments on flash write / read?&#60;/p&#62;
&#60;p&#62;Working with flashWriteWord, but seems a little strange, I'm trying to deal with u8[]'s but that function seems to want u32's that then get chopped to two u16's to be written sequentially. I think I can do some bitwise copying and end up okay but I was wondering if anyone else had seen a simpler implementation for copying straight to memory with an index of 1 byte.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
