<?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 Flash writing MCF522559 in ColdFire/68K Microcontrollers and Processors</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Flash-writing-MCF522559/m-p/1304931#M14096</link>
    <description>&lt;P&gt;Hi everyone I'm developing a code to write data into the flash memory.&lt;/P&gt;&lt;P&gt;I'm using the codewarrior 11.1 &amp;amp; coldfire v2 MCF52259&lt;/P&gt;&lt;P&gt;Reading the RM I found the next&lt;/P&gt;&lt;P&gt;"&lt;SPAN class="fontstyle0"&gt;B&lt;EM&gt;efore starting a command write sequence, the ACCERR and PVIOL flags in the CFMUSTAT register&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;must be clear and the CBEIF flag should be tested to determine the state of the address, data, and command&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;buffers. If the CBEIF flag is set, indicating the buffers are empty, a new command write sequence can be&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;executed.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;A command write sequence consists of three steps that must be strictly adhered to, because writes to&amp;nbsp; the&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;CFM are not permitted between steps. However, flash register and array reads are allowed during a&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;command write sequence. The basic command write sequence is as follows:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;1. Write to one or more addresses in the flash memory.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;2. Write a valid command to the CFMCMD register.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;3. Clear CBEIF flag by writing a 1 to CBEIF to launch the command.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;When the CBEIF flag is cleared, the CCIF flag is cleared on the same bus cycle by the flash command&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;controller indicating that the command was successfully launched.&lt;/EM&gt;&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;Base on this steps I developed the next function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#define FLASH_PROGRAM_ADDR(x) \
  (*(volatile unsigned long *)(void *)(&amp;amp;__IPSBAR[(0x04000000 + (x))]))

unsigned char Write_Flash(uint32 *mainPtr, uint32 data)
{
  vuint8 status;
  MCF_CFM_CFMUSTAT |= ACCERR;                 // clean a possible access error flag
  MCF_CFM_CFMUSTAT |= PVIOL;                  // clean a possible violation access flag
  while ((MCF_CFM_CFMUSTAT &amp;amp; CBEIF) != CBEIF) {;} // ready for another command
  FLASH_PROGRAM_ADDR(*mainPtr) = data;         // write to an address (?)
  MCF_CFM_CFMCMD = WRITE_WORD;                 // write command
  MCF_CFM_CFMUSTAT |= CBEIF;                   // launch command
  
  while ((MCF_CFM_CFMUSTAT &amp;amp; CCIF) != CCIF) {;}
  status = MCF_CFM_CFMUSTAT;
  return  (status);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got the&amp;nbsp;&lt;STRONG&gt;FLASH_PROGRAM_ADDR(x)&amp;nbsp;&lt;/STRONG&gt;from an example and I think it makes sense since the RM says:&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;"&lt;EM&gt;Flash accesses (reads/writes) by a bus master other than the core (e.g. DMA&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;controller), or writes to flash by the core during programming must use the&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;backdoor flash address of IPSBAR plus an offset of 0x0400_0000.&lt;/EM&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;Running the programm the flash data doesn't change, at least&amp;nbsp; I can't see the change in debugger.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;Does anyone notice where I might be getting it wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;if it matters the chosen address&amp;nbsp; is 0x00009000&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;Thank you in advance.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jul 2021 18:38:14 GMT</pubDate>
    <dc:creator>adelvallem</dc:creator>
    <dc:date>2021-07-08T18:38:14Z</dc:date>
    <item>
      <title>Flash writing MCF522559</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Flash-writing-MCF522559/m-p/1304931#M14096</link>
      <description>&lt;P&gt;Hi everyone I'm developing a code to write data into the flash memory.&lt;/P&gt;&lt;P&gt;I'm using the codewarrior 11.1 &amp;amp; coldfire v2 MCF52259&lt;/P&gt;&lt;P&gt;Reading the RM I found the next&lt;/P&gt;&lt;P&gt;"&lt;SPAN class="fontstyle0"&gt;B&lt;EM&gt;efore starting a command write sequence, the ACCERR and PVIOL flags in the CFMUSTAT register&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;must be clear and the CBEIF flag should be tested to determine the state of the address, data, and command&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;buffers. If the CBEIF flag is set, indicating the buffers are empty, a new command write sequence can be&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;executed.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;A command write sequence consists of three steps that must be strictly adhered to, because writes to&amp;nbsp; the&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;CFM are not permitted between steps. However, flash register and array reads are allowed during a&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;command write sequence. The basic command write sequence is as follows:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;1. Write to one or more addresses in the flash memory.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;2. Write a valid command to the CFMCMD register.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;3. Clear CBEIF flag by writing a 1 to CBEIF to launch the command.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;When the CBEIF flag is cleared, the CCIF flag is cleared on the same bus cycle by the flash command&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;controller indicating that the command was successfully launched.&lt;/EM&gt;&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;Base on this steps I developed the next function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#define FLASH_PROGRAM_ADDR(x) \
  (*(volatile unsigned long *)(void *)(&amp;amp;__IPSBAR[(0x04000000 + (x))]))

unsigned char Write_Flash(uint32 *mainPtr, uint32 data)
{
  vuint8 status;
  MCF_CFM_CFMUSTAT |= ACCERR;                 // clean a possible access error flag
  MCF_CFM_CFMUSTAT |= PVIOL;                  // clean a possible violation access flag
  while ((MCF_CFM_CFMUSTAT &amp;amp; CBEIF) != CBEIF) {;} // ready for another command
  FLASH_PROGRAM_ADDR(*mainPtr) = data;         // write to an address (?)
  MCF_CFM_CFMCMD = WRITE_WORD;                 // write command
  MCF_CFM_CFMUSTAT |= CBEIF;                   // launch command
  
  while ((MCF_CFM_CFMUSTAT &amp;amp; CCIF) != CCIF) {;}
  status = MCF_CFM_CFMUSTAT;
  return  (status);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got the&amp;nbsp;&lt;STRONG&gt;FLASH_PROGRAM_ADDR(x)&amp;nbsp;&lt;/STRONG&gt;from an example and I think it makes sense since the RM says:&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;"&lt;EM&gt;Flash accesses (reads/writes) by a bus master other than the core (e.g. DMA&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;controller), or writes to flash by the core during programming must use the&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;backdoor flash address of IPSBAR plus an offset of 0x0400_0000.&lt;/EM&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;Running the programm the flash data doesn't change, at least&amp;nbsp; I can't see the change in debugger.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;Does anyone notice where I might be getting it wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;if it matters the chosen address&amp;nbsp; is 0x00009000&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;Thank you in advance.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 18:38:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Flash-writing-MCF522559/m-p/1304931#M14096</guid>
      <dc:creator>adelvallem</dc:creator>
      <dc:date>2021-07-08T18:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Flash writing MCF522559</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Flash-writing-MCF522559/m-p/1308269#M14098</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;First of all, sorry for the later reply.&lt;/P&gt;
&lt;P data-unlink="true"&gt;I would like to recommend customer to refer [&lt;A href="https://www.nxp.com/downloads/en/snippets-boot-code-headers-monitors/MCF5225x_SAMPLE_CODE.zip" target="_self"&gt;MCF5225x_SAMPLE_CODE&lt;/A&gt;&amp;nbsp;], which provides CFM project about how to erase/program MCF52259 internal Flash.&lt;/P&gt;
&lt;P data-unlink="true"&gt;There need to copy and run related Flash operation code at RAM during Flash operation, when code run in Flash. Customer could check &amp;lt;cfm.c&amp;gt; file for the detailed info.&lt;/P&gt;
&lt;P data-unlink="true"&gt;Wish it helps.&lt;/P&gt;
&lt;P data-unlink="true"&gt;best regards,&lt;/P&gt;
&lt;P data-unlink="true"&gt;Mike&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 08:42:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Flash-writing-MCF522559/m-p/1308269#M14098</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2021-07-15T08:42:28Z</dc:date>
    </item>
  </channel>
</rss>

