<?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: S12x Problem in accessing the flash memory in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186205#M7045</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes the code is allocated in the banked memory. Pardon my naiveness, I am a little new to the microcontroller programming, Can you please let me know what is wrong in the following code and how should I implement it ?.Is it something to do with using PPAGE since the code is allocated using it. So if that, should I use GPAGE instead ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 26 Nov 2012 08:55:40 GMT</pubDate>
    <dc:creator>vish</dc:creator>
    <dc:date>2012-11-26T08:55:40Z</dc:date>
    <item>
      <title>S12x Problem in accessing the flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186203#M7043</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I am having a little issue in accessing the flash memory on the S12X module. My requirement is to compute md5 on flash memory of the s12xd256 module. So my idea was to start reading all the locations, store them in a temporary buffer. And once the buffer is full, compute md5 on them and clear the contents of the buffer. I have implemented a very similar function on the s12 module which works flawlessly, but in S12x, the moment my device tries to access the flash memory, it restarts. I am attaching the snippet below.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Md5.SubpageSize = 16384/128;&lt;/P&gt;&lt;P&gt;if(page&amp;lt;32)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;if((subpage*Md5.SubpageSize)&amp;lt;16384)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;old_PPAGE = PPAGE;&lt;/P&gt;&lt;P&gt;PPAGE = 0xE0 + page;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for(j=0; j&amp;lt;g_Md5.SubpageSize; j+=64)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;for(k=0; k&amp;lt;32; ++k)&amp;nbsp;&amp;nbsp;&amp;nbsp; // just copy flash location ro RAM buffer&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;flash_buf[k] = *(word*)(0x8000+(subpage*g_Md5.SubpageSize)+j+(k*2));&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* 'word flash_buf[32]' is a temp buffer */&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;block_ptr = (byte*) &amp;amp;flash_buf[0];&lt;/P&gt;&lt;P&gt;MD5Update(&amp;amp;context, block_ptr, 64);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;PPAGE = old_PPAGE;&lt;/P&gt;&lt;P&gt;++subpage;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;if (page == 7){&lt;/P&gt;&lt;P&gt;page = 23;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Skip to page 23, since page 8-23 are not used*/&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;subpage = 0;&lt;/P&gt;&lt;P&gt;++page;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Nov 2012 13:45:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186203#M7043</guid>
      <dc:creator>vish</dc:creator>
      <dc:date>2012-11-23T13:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: S12x Problem in accessing the flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186204#M7044</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Isn't this code allocated in banked memory? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Nov 2012 18:48:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186204#M7044</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2012-11-23T18:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: S12x Problem in accessing the flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186205#M7045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes the code is allocated in the banked memory. Pardon my naiveness, I am a little new to the microcontroller programming, Can you please let me know what is wrong in the following code and how should I implement it ?.Is it something to do with using PPAGE since the code is allocated using it. So if that, should I use GPAGE instead ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2012 08:55:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186205#M7045</guid>
      <dc:creator>vish</dc:creator>
      <dc:date>2012-11-26T08:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: S12x Problem in accessing the flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186206#M7046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't manipulate PPAGE register when executing code in banked memory. Try flipping a page, which you are reading and continue reading from the same position on different page...&lt;/P&gt;&lt;P&gt;But I wonder how similar function would work on S12. Was it made nonbanked? Did you use small memory model?&lt;/P&gt;&lt;P&gt;To fix it, just allocate routine with PPAGE=xx and PPAGE = old_PPAGE in nonbanked memory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#pragma CODE_SEG __NEAR_SEG NON_BANKED&lt;/P&gt;&lt;P&gt;&amp;lt;put your routine here&amp;gt;&lt;/P&gt;&lt;P&gt;#pragma CODE_SEG DEFAULT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you declare prototype of this function anywhere, prototype also should be put between identical pragmas.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2012 10:24:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186206#M7046</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2012-11-26T10:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: S12x Problem in accessing the flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186207#M7047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, as Edward already mentioned directly change of PPAGE is not very save. &lt;/P&gt;&lt;P&gt;I created simple example code for CRC checksum calculation over paged flash (for S12G). &lt;SPAN lang="EN-GB" style="font-size: 11.0pt; font-family: 'Calibri','sans-serif';"&gt;It doesn't need to be in non banked flash.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You can take it as inspiration:&lt;/P&gt;&lt;P&gt;unsigned char crc_sum; &lt;/P&gt;&lt;P&gt;unsigned long j, ptr;&lt;/P&gt;&lt;P&gt;unsigned int k;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;crc_sum = 0xFF;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //CRC initial value&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;for(j=0x010000;j&amp;lt;=0x0E0000;j=j+0x010000)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //PPAGE increment (except last page)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt; for(k=0x8000;k&amp;lt;=0xBFFF;k++)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Address increment&lt;/P&gt;&lt;P&gt; {&lt;/P&gt;&lt;P&gt; ptr = j+k; //Complete address&lt;/P&gt;&lt;P&gt; crc_sum= CheckSumByteCRC8(crc_sum, *((unsigned char *far)ptr) , DEFAULT_CRC8_CHECKSUM);&lt;/P&gt;&lt;P&gt; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/P&gt;&lt;P&gt;j=0x0F0000;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //last page&lt;/P&gt;&lt;P&gt;for(k=0x8000;k&amp;lt;=0xBEFF;k++)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Address increment - without reset vectors&lt;/P&gt;&lt;P&gt; {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt; ptr = j+k; //Complete address&lt;/P&gt;&lt;P&gt; crc_sum= CheckSumByteCRC8(crc_sum, *((unsigned char *far)ptr) , DEFAULT_CRC8_CHECKSUM);&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;if (crc_sum == CHECKSUM_STORAGE_CRC8) PTT_PTT7 = 0;&amp;nbsp; //if checksum ok, LED on&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FYI: CodeWarrior linker is able calculate checksum automatically (according definition in *.prm file).&lt;/P&gt;&lt;P&gt;Example codes for checksum calculation you can find on your disk in CodeWarrior installation directory. Default path:&lt;/P&gt;&lt;P&gt;"c:\Program Files\Freescale\CWS12v5.1\(CodeWarrior_Examples)\HC12\Checksums\.."&lt;/P&gt;&lt;P&gt;Possible CHECKSUM_METHOD= "METHOD_CRC_CCITT"|"METHOD_CRC8"|"METHOD_CRC16"|"METHOD_CRC32"|"METHOD_ADD"|"METHOD_XOR".&lt;/P&gt;&lt;P&gt;CheckSumByteCRC8 is function from "c:\Program Files\Freescale\CWS12v5.1\lib\hc12c\src\checksum.c" file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you will need complete example code, please let me know, or create new service request at Freescale support page.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2012 13:35:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186207#M7047</guid>
      <dc:creator>RadekS</dc:creator>
      <dc:date>2012-11-26T13:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: S12x Problem in accessing the flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186208#M7048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using cosmic compiler and moreover, I ended up making a very silly error which I realized after my first reply to you. After writting that the code is allocated in the bank memory, I realised what was messing up. All I did was change the md5 code to unbanked memory in the linker file (.lkf). It started working. Thanks for pointing that out :smileyhappy:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2012 13:51:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12x-Problem-in-accessing-the-flash-memory/m-p/186208#M7048</guid>
      <dc:creator>vish</dc:creator>
      <dc:date>2012-11-26T13:51:02Z</dc:date>
    </item>
  </channel>
</rss>

