<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/30930/how-do-i-know-which-flash-page-to-erase-to-subsequently-write-to-it</link><description> 
I have been asked to write an application to be able to change
some variables during runtime and be able to store them in
non-volatile memory (flash). I read the C8051f507 datasheet and the
process to erase and write to flash looks really straightforward</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/thread/140342?ContentTypeID=1</link><pubDate>Wed, 22 Aug 2012 05:30:00 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:baec12a0-b849-4257-a44c-903a2821ac2c</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Does anybody has an idea why this is happening?&lt;/i&gt;&lt;br /&gt;
yes, your puppy bites, disable the watchdog - unless you can set the
timeout long enough.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;I tried putting different delays in between function
calls&lt;/i&gt;&lt;br /&gt;
does the chip you have not seen fit to reveale not have an &amp;quot;erase
complete&amp;quot; flag. doing it with delays is not a good idea.&lt;/p&gt;

&lt;p&gt;
Since you have not revealed your chip, if it does not allow
disabling the WD and you can not set a long enough time, you will
need to run without it.&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/thread/131073?ContentTypeID=1</link><pubDate>Tue, 21 Aug 2012 15:13:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3418f8b3-de02-461a-a4a6-548459e8ef60</guid><dc:creator>Fernando Torres</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;b&gt;UPDATE&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;
I used an oscilloscope to trace how far my code was getting an I
found out that the processor resets right after&lt;/p&gt;

&lt;pre&gt;
 *pwrite = 0; // Initiate page erase
&lt;/pre&gt;

&lt;p&gt;
.&lt;/p&gt;

&lt;p&gt;
Does anybody has an idea why this is happening?&lt;/p&gt;

&lt;p&gt;
Thanks&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/thread/131074?ContentTypeID=1</link><pubDate>Tue, 21 Aug 2012 13:29:13 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bb9cf45f-20a4-48c1-bf5d-7a0e8adbad84</guid><dc:creator>Fernando Torres</dc:creator><description>&lt;p&gt;&lt;p&gt;
I tried putting different delays in between function calls but I&amp;#39;m
still seeing the same problem. I am suspecting that I am getting an
undesirable reset right after the erase but I haven&amp;#39;t been able to
figure out why this is happening.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/thread/127691?ContentTypeID=1</link><pubDate>Tue, 21 Aug 2012 10:24:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c558e8c7-eb6c-4706-bb5a-61e5e33e7c0f</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
... waiting for erase complete before writing?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/thread/116959?ContentTypeID=1</link><pubDate>Tue, 21 Aug 2012 09:45:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0e253bea-fb73-4adb-bc0b-e42a924ff2f6</guid><dc:creator>Fernando Torres</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanks for your replies.&lt;/p&gt;

&lt;p&gt;
So far I have been able to erase a page and write a byte to that
page; however, I have only been able to implement one function at the
time, when I try to call both functions it seems that only the
function that is called first is executed. I have included both of
the functions to see if somebody can tell me why they are not
executing when they are called one after the other.&lt;/p&gt;

&lt;p&gt;
Thanks&lt;/p&gt;

&lt;pre&gt;
void FLASH_ByteWrite (void)
{
        unsigned char xdata * pwrite;           // FLASH write pointer

        pwrite = (unsigned char xdata *) FLASH_WRITE_READ_ERASE;
        PSCTL = 0x01;     // PSWE = 1 which enables writes
        FLKEY = 0xA5;     // Key Sequence 1
        FLKEY = 0xF1;     // Key Sequence 2
        VDM0CN = 0xA0;    // Enable VDD monitor and high threshold
        RSTSRC = 0x02;    // Enable VDD monitor as a reset source
        *pwrite = 0xAA;   // Write the byte
        PSCTL &amp;amp;= ~0x03;   // PSWE = 0 which disable writes

}
&lt;/pre&gt;
&lt;pre&gt;
void FLASH_PageErase (void)
{
        unsigned char xdata * pwrite; // FLASH write pointer

        pwrite = (unsigned char xdata *) FLASH_WRITE_READ_ERASE;
        PSCTL = 0x03;    // PSWE = 1; PSEE = 1
        FLKEY = 0xA5;    // Key Sequence 1
        FLKEY = 0xF1;    // Key Sequence 2
        VDM0CN = 0xA0;   // Enable VDD monitor and high threshold
        RSTSRC = 0x02;   // Enable VDD monitor as a reset source
        *pwrite = 0;     // Initiate page erase
        PSCTL &amp;amp;= ~0x03;  // PSWE = 0; PSEE = 0
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/thread/106283?ContentTypeID=1</link><pubDate>Sat, 18 Aug 2012 11:57:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9844da91-6c71-45ce-a5fc-5400d92f38b9</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;How do you tell the linker to store those variables (in my
case, nine variables) in a specific flash page and nothing else so
that when I erase the page I only erase those variables and nothing
else?&lt;/i&gt;&lt;br /&gt;
I like to do such stuff in assembler it is a lot easier using means
that do not try to protect you from yourself.&lt;/p&gt;

&lt;p&gt;
anyhow it can be done in the assembler, the compiler or the
linker.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;and nothing else?&lt;/i&gt;&lt;br /&gt;
the only way I know of to do so is to fill the page up.&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/thread/80480?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2012 12:57:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:86efae26-943a-443d-ad37-28ae8b338a49</guid><dc:creator>Fernando Torres</dc:creator><description>&lt;p&gt;&lt;p&gt;
How do you tell the linker to store those variables (in my case,
nine variables) in a specific flash page and nothing else so that
when I erase the page I only erase those variables and nothing
else?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do I know which flash page to erase to subsequently write to it?</title><link>https://community.arm.com/thread/67663?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2012 12:37:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4775bea6-f6c6-44d1-b541-6cdc7c341fd7</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Well - sometime you are going to make a decision where to store
your variables that you want to be able to modify. When you have
decided on which page to store these variables, you will also know
which page to erase to modify them.&lt;/p&gt;

&lt;p&gt;
You obviously either have to set up the project so the linker
places the variables at the decided flash page. Or you have to
instead make use of a pointer to as struct and just initialize the
pointer to the address of the page.&lt;/p&gt;

&lt;p&gt;
Just remember one thing - what happens if the power is lost or
something else happens when you erase that page? Is it bad if you
lose the values of these variables?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>