<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Flash Programming Not Working on Second Pass in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137493#M4697</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, mjcoury:&lt;BR /&gt;&lt;BR /&gt;I'm not using the same CPU, but I found that the writing of the address latch, the "*cMemory_ptr = 0xFF;" instruction, had to be executed from ram as well. Otherwise, the fetch of the following instruction caused the address latch to change.&lt;BR /&gt;&lt;BR /&gt;But that was on an HC08, not an S08, so it may not be your problem.&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Nov 2006 05:40:35 GMT</pubDate>
    <dc:creator>rocco</dc:creator>
    <dc:date>2006-11-22T05:40:35Z</dc:date>
    <item>
      <title>Flash Programming Not Working on Second Pass</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137492#M4696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;All -&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here are my erase and write routines -&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#pragma CODE_SEG ToCopyToRAM&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;void EraseFlash(void) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if ((FSTAT &amp;amp; 0x10) != 0) {&lt;/SPAN&gt;&lt;BR /&gt;&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gt;&lt;SPAN&gt;asm {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//LDA #$CC&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//STA $1600&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LDA #$20&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;STA FCMD&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LDA #$80&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;STA FSTAT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NOP&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NOP&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NOP&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NOP&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WFLOOP:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LDA FSTAT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LSLA&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;BPL WFLOOP&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;// while( (FSTAT &amp;amp; 0x40)!= 1) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;// asm("NOP");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;// }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;} // end WriteFlash&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#pragma CODE_SEG DEFAULT&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the routines that call it&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int LCDFlashCheck(){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataStored_ptr = (lcdram *) LCD_FLASH_START;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(sLCDDataStored_ptr-&amp;gt;iFlashKey == (word) FLASH_SEED) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cID = sLCDDataStored_ptr-&amp;gt;cID;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cChannel = sLCDDataStored_ptr-&amp;gt;cChannel;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cEncyptionKey = sLCDDataStored_ptr-&amp;gt;cEncyptionKey;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cPreset1 = sLCDDataStored_ptr-&amp;gt;cPreset1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cPreset2 = sLCDDataStored_ptr-&amp;gt;cPreset2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cMode = sLCDDataStored_ptr-&amp;gt;cMode;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cContrast = sLCDDataStored_ptr-&amp;gt;cContrast;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cBacklight = sLCDDataStored_ptr-&amp;gt;cBacklight;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return ERROR_NONE;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}else{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;iFlashKey = (word) FLASH_SEED;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cID = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cChannel = 5;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cEncyptionKey = 21;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cPreset1 = (char) PRESET1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cPreset2 = (char) PRESET2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cMode = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cContrast = 0x7F;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sLCDDataActive_ptr-&amp;gt;cBacklight = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LCDReWriteFlash();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return ERROR_FLASH_INVALID_KEY;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int LCDReWriteFlash(void){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;char cDummy = 0xFF;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;char *cDummy_ptr;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;char *cMemory_ptr;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int i;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;DisableInterrupts;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//Erase Flash&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cMemory_ptr = (char*) LCD_FLASH_START;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;*cMemory_ptr = 0xFF;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EraseFlash();&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//Write Flash&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cDummy_ptr = &amp;amp;(sLCDDataActive);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cMemory_ptr = (char*) LCD_FLASH_START;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for(i=0;i&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;*cMemory_ptr = *cDummy_ptr;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WriteFlash();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cMemory_ptr++;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cDummy_ptr++;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EnableInterrupts;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now when the device is freshly flashed the memory location in question is obviously all 0xFF. The routine works as expected and all the "default" data is stored into FLASH. Now any other write attempts will fail and just not work. When I step through the code at this point&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//Erase Flash&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cMemory_ptr = (char*) LCD_FLASH_START;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;*cMemory_ptr = 0xFF;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EraseFlash();&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;cMemory_ptr will correctly be addressed at 0x1600. However the next piece of code&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;*cMemory_ptr = 0xFF;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;appears to be "skipped" and because the value at cMemory pointer never changes, the EraseFlash() routine does not correctly erase the page, and of course without the erase there is no write...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any Ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Nov 2006 02:09:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137492#M4696</guid>
      <dc:creator>mjcoury</dc:creator>
      <dc:date>2006-11-22T02:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Flash Programming Not Working on Second Pass</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137493#M4697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, mjcoury:&lt;BR /&gt;&lt;BR /&gt;I'm not using the same CPU, but I found that the writing of the address latch, the "*cMemory_ptr = 0xFF;" instruction, had to be executed from ram as well. Otherwise, the fetch of the following instruction caused the address latch to change.&lt;BR /&gt;&lt;BR /&gt;But that was on an HC08, not an S08, so it may not be your problem.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Nov 2006 05:40:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137493#M4697</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-11-22T05:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Flash Programming Not Working on Second Pass</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137494#M4698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;not a bad idea... however, why would it work the first time i run the program from programming and not other attempts?&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Nov 2006 06:56:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137494#M4698</guid>
      <dc:creator>mjcoury</dc:creator>
      <dc:date>2006-11-22T06:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Flash Programming Not Working on Second Pass</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137495#M4699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;i have recently posted some code for the mc9s08rd32dwe processor. not alot of details in your post. the areas i got hung up in are:&lt;BR /&gt;&lt;BR /&gt;-the memory bus is tied up servicing the flash programmer state machine. you need to emulate out of ram while doing your lo level flash programming. put the assembly code to low level program flash in a C language array, make the linker put in ram at processor startup. to flash write it only takes like 30bytes. all this in my semi recent posting, search.&lt;BR /&gt;-to program flash you need to consider doing:&lt;BR /&gt;1)copy entire page flash to ram&lt;BR /&gt;2)modify the ram as needed&lt;BR /&gt;3)clear the entire flash page all at once&lt;BR /&gt;4)byte by byte copy ram to flash for the entire page&lt;BR /&gt;-rember to set the proper flash clock speed for your system in processor startup&lt;BR /&gt;-think of testing for proper vcc during flash write.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Nov 2006 04:20:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137495#M4699</guid>
      <dc:creator>jah</dc:creator>
      <dc:date>2006-11-23T04:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Flash Programming Not Working on Second Pass</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137496#M4700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;jah -&lt;BR /&gt;&lt;BR /&gt;to your points&lt;BR /&gt;&lt;BR /&gt;1)copy entire page flash to ram&lt;BR /&gt;&lt;BR /&gt;In my code you can see the #pragma CODE_SEG ToCopyToRAM which, already copies the write and erase routines to flash.&lt;BR /&gt;&lt;BR /&gt;2)modify the ram as needed&lt;BR /&gt;&lt;BR /&gt;Why would I need to modify the ram? I assume you are referring to the memory location to be written / erased. If this is true why does it work once through the process I currently use?&lt;BR /&gt;&lt;BR /&gt;3)clear the entire flash page all at once&lt;BR /&gt;&lt;BR /&gt;If you looked at my routine int LCDReWriteFlash(void){ you can clearly see the routine Erase Flash is called before write flash.&lt;BR /&gt;&lt;BR /&gt;cMemory_ptr = (char*) LCD_FLASH_START;&lt;BR /&gt;*cMemory_ptr = 0xFF;&lt;BR /&gt;EraseFlash();&lt;BR /&gt;&lt;BR /&gt;The problem is HERE, where the *cMemory_ptr SHOULD be getting the value dummy value of 0xFF - however - since this line gets "skipped" when I step through the code on a second pass - the MCU does not know to erase the page at location cMemory_ptr (in this case $1600)&lt;BR /&gt;&lt;BR /&gt;4)byte by byte copy ram to flash for the entire page&lt;BR /&gt;&lt;BR /&gt;//Write Flash&lt;BR /&gt;cDummy_ptr = &amp;amp;(sLCDDataActive);&lt;BR /&gt;cMemory_ptr = (char*) LCD_FLASH_START;&lt;BR /&gt;for(i=0;i&lt;BR /&gt;*cMemory_ptr = *cDummy_ptr;&lt;BR /&gt;WriteFlash();&lt;BR /&gt;cMemory_ptr++;&lt;BR /&gt;cDummy_ptr++;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;as you can see there is a byte by byte copy ram routine already present. This I assume would work correctly IF i was properly erasing the page - which seems to by why it is not working.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Nov 2006 22:57:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Flash-Programming-Not-Working-on-Second-Pass/m-p/137496#M4700</guid>
      <dc:creator>mjcoury</dc:creator>
      <dc:date>2006-11-27T22:57:08Z</dc:date>
    </item>
  </channel>
</rss>

