<?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>CodeWarrior for MCU中的主题 Can FLASH be set as Read/Write?</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134880#M1623</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am using the MC9S12XDP512 part and am wondering if I can set portions of the paged FLASH to be READ_WRITE instead of READ_ONLY.&amp;nbsp; I have a large configuration table that I need to store that may have to be occasionally changed so I would like to store it in FLASH instead of RAM.&amp;nbsp; If anyone knows the answer or has done something like this before, I would appreciate the help.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thomas&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 May 2006 21:19:38 GMT</pubDate>
    <dc:creator>ThomasG</dc:creator>
    <dc:date>2006-05-05T21:19:38Z</dc:date>
    <item>
      <title>Can FLASH be set as Read/Write?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134880#M1623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am using the MC9S12XDP512 part and am wondering if I can set portions of the paged FLASH to be READ_WRITE instead of READ_ONLY.&amp;nbsp; I have a large configuration table that I need to store that may have to be occasionally changed so I would like to store it in FLASH instead of RAM.&amp;nbsp; If anyone knows the answer or has done something like this before, I would appreciate the help.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thomas&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 May 2006 21:19:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134880#M1623</guid>
      <dc:creator>ThomasG</dc:creator>
      <dc:date>2006-05-05T21:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Can FLASH be set as Read/Write?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134881#M1624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Check out the follow thread in the 8-bit Microcontroller Forum. It has a discussion about how to program Flash to store variables:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=1084" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=1084" target="test_blank"&gt;http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&amp;amp;message.id=1084&lt;/A&gt; target=_blank&lt;BR /&gt;&lt;BR /&gt;It may not be exactly what you're looking for, but it will probably give you some ideas.&lt;BR /&gt;&lt;BR /&gt;---Tom&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 May 2006 21:56:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134881#M1624</guid>
      <dc:creator>J2MEJediMaster</dc:creator>
      <dc:date>2006-05-05T21:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can FLASH be set as Read/Write?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134882#M1625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;I have used FLASH on the HCS(X) devices to store lookup tables. Here is the code I used to erase and program the FLASH sectors (1024 bytes).&lt;/P&gt;&lt;P&gt;This first part shows I accessed and checked each value in a FLASH table. If any of the parameters are out of spec it programs the table to a DEFAULT setting.&lt;/P&gt;&lt;P&gt;The second section shows how to setup your GLOBAL segment to place the tables.&lt;/P&gt;&lt;P&gt;The third setion is the code to erase and program the FLASH.&lt;/P&gt;&lt;P&gt;Not sure if this is the best way to do it but it worked for me.&lt;/P&gt;&lt;P&gt;Be sure to #define the OSC_SPEED so the proper FLASH timing can be set. Look at the last function in this code.&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;#include "FlashCtrl.h"#pragma DATA_SEG DATATABLE_DATA#pragma CODE_SEG DATATABLE_CODE/* Check data tables */void CheckDataTables(void) { /* Local variables */ BYTE Flag; WORD i;  /* Check Nitrous table */ for(i = 0; i &amp;lt; NITROUS_TABLE_SIZE; i++) {  /* Check each table entry */  if(NitrousTable[SetupIndex][i] &amp;lt; NITROUS_PERCENT_MIN || NitrousTable[SetupIndex][i] &amp;gt; NITROUS_PERCENT_MAX){   /* Erase table sector */   Flag = Flash_EraseSector((INT16 *__far)&amp;amp;NitrousTable[SetupIndex][0]);   /* Write factory data */   for(i = 0; i &amp;lt; NITROUS_TABLE_SIZE; i++){    Flag = Flash_WriteWord((INT16 *__far)&amp;amp;NitrousTable[SetupIndex][i], NitrousTableDefault[i]);   }   /* Break loop */   break;  } }  /* Check Fuel table */ for(i = 0; i &amp;lt; FUEL_TABLE_SIZE; i++) {  /* Check each table entry */  if(FuelTable[SetupIndex][i] &amp;lt; FUEL_PERCENT_MIN || FuelTable[SetupIndex][i] &amp;gt; FUEL_PERCENT_MAX){   /* Erase table sector */   Flag = Flash_EraseSector((INT16 *__far)&amp;amp;FuelTable[SetupIndex][0]);   /* Write factory data */   for(i = 0; i &amp;lt; FUEL_TABLE_SIZE; i++){    Flag = Flash_WriteWord((INT16 *__far)&amp;amp;FuelTable[SetupIndex][i], FuelTableDefault[i]);   }   /* Break loop */   break;  } }}#pragma CODE_SEG DEFAULT#pragma DATA_SEG DEFAULT/* This SEGMENT(TABLE_ROM) must be declared as PAGED_FLASH in prm file */#pragma CONST_SEG __GPAGE_SEG TABLE_ROM/* Nitrous Table */const WORD NitrousTable[SETUP_MAX][512];/* Fuel Table */const WORD FuelTable[SETUP_MAX][512];#pragma CONST_SEG __GPAGE_SEG DEFAULTTABLE_ROM/* FLASH data table address range */#define TABLE_ADDRESS_LOW  0x780000#define TABLE_ADDRESS_HIGH  0x787FFF#pragma DATA_SEG FlashCtrl_DATA                                            #pragma CODE_SEG FlashCtrl_CODE                     /* Flash_WriteWord */BYTE Flash_WriteWord(WORD *__far WriteAddress, WORD Data){ /* Check range of WriteAddress */ if(WriteAddress &amp;lt; (WORD *__far)TABLE_ADDRESS_LOW || WriteAddress &amp;gt; (WORD *__far)TABLE_ADDRESS_HIGH)  return FALSE;  /* Has the FLASH divider clock been set— */ if(!FCLKDIV_FDIVLD)  FlashCtrl_Init();  /* Check command flag */ if(!FSTAT_CBEIF)  return FALSE;  /* Clear flags */ FSTAT = 48;    /* Array address and program data */   WriteAddress[0] = Data;    /* Word program command */ FCMD = 32;    /* Clear flag command buffer empty */    FSTAT = 128;     /* Is protection violation or acces error detected– */   if ((FSTAT_PVIOL == 1)||(FSTAT_ACCERR == 1))     return FALSE;      /* Wait to buffer empty */ while(FSTAT_CBEIF == 0); /* Wait to command complete */ while(FSTAT_CCIF == 0); /* Was write successful˜ */ if(WriteAddress[0] != Data)  return FALSE;  /* Return success */  return TRUE;}/* Flash_EraseSector */BYTE Flash_EraseSector(WORD *__far EraseAddress){ /* Check range of EraseAddress */ if(EraseAddress &amp;lt; (WORD *__far)TABLE_ADDRESS_LOW || EraseAddress &amp;gt; (WORD *__far)TABLE_ADDRESS_HIGH)  return FALSE;  /* Has the FLASH divider clock been set™ */ if(!FCLKDIV_FDIVLD)  FlashCtrl_Init();  /* Check command flag */ if(!FSTAT_CBEIF)  return FALSE;  /* Clear flags */ FSTAT = 48;  /* Write to erase address */ EraseAddress[0] = 0x10;   /* Initiate Sector Erase commamd */ FCMD = 64; /* Clear flag command buffer empty */ FSTAT = 128;        /* Is protection violation or access error detected ? */ if ((FSTAT_PVIOL == 1)||(FSTAT_ACCERR == 1))     /* If yes then error */     return FALSE;        /* Wait to buffer empty */   while(FSTAT_CBEIF == 0); /* Wait to command complete */ while(FSTAT_CCIF == 0);  /* Return success */ return TRUE;}/* FlashCtrl_Init */void FlashCtrl_Init(void){#if OSC_SPEED == 4000000 /* 4mhz clock */ FCLKDIV = 20;                        #elif OSC_SPEED == 8000000 /* 8mhz clock */ FCLKDIV = 40;#elif OSC_SPEED == 10000000 /* 10mhz clock */ FCLKDIV = 50;#endif}#pragma DATA_SEG DEFAULT                                            #pragma CODE_SEG DEFAULT                    &lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 May 2006 21:59:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134882#M1625</guid>
      <dc:creator>Technoman64</dc:creator>
      <dc:date>2006-05-05T21:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can FLASH be set as Read/Write?</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134883#M1626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Thank you for the replies.&amp;nbsp; I think this answers my basic question and can get me going with what I need to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 May 2006 23:22:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Can-FLASH-be-set-as-Read-Write/m-p/134883#M1626</guid>
      <dc:creator>ThomasG</dc:creator>
      <dc:date>2006-05-08T23:22:23Z</dc:date>
    </item>
  </channel>
</rss>

