AnsweredAssumed Answered

S12X read paged flash 78 ( 0x780000 0x783FFF)

Question asked by firefox noIE on Oct 26, 2009
Latest reply on Oct 27, 2009 by firefox noIE

Hi All,

 

I m trying to read the page  0x00780000 to 0x00783FFF ( global Address ) and calculate the CRC16 of the flash memory

 

 


#define FLASH_START_ADDR     0x00780000
#define FLASH_END_ADDR      0x00783FFF

 the function calculate every 64 bytes the crc and go out from the function again

 


void Flash_CalcCRC(void)
{
// Puffer Zeiger auf aktuelles Byte mit Startadresse initialisieren

        static T_UC08* pucBuffer = (T_UC08*) FLASH_START_ADDR; // <-- wrong content

// berechne nur ein Teil des Flashes
T_UI16 uiBytesCounter = 0;
// Temporäre Variable
T_UI16 uiCryptPos = 0;

// nur eine gewisse Anzahl an Byte berechnen und die Funktion wieder verlassen
for (ulNumLoops ; (ulNumLoops <= FLASH_END_ADDR) && (uiBytesCounter < 64 ); ulNumLoops++)
{
  // Bytes Zähler inkrementieren
  uiBytesCounter++;
  // Word aus Puffer in uiCryptPos kopieren
  uiCryptPos = (T_UI16) *pucBuffer; // also wrong
  // Pufferzeiger inkrementieren
  pucBuffer++;
  // EXOR mit RückgabeCRC
  uiCryptPos ^= uiFlashCRC16;
  // CryptArrays einrechnen
  uiFlashCRC16 = *(T_UI16*)(uiCRC16l + (uiCryptPos & 0x000F)) ^
       *(T_UI16*)(uiCRC16h + ((uiCryptPos & 0x00F0) >> 4)) ^
       (uiFlashCRC16 >> 8);
}

if ( ulNumLoops == FLASH_END_ADDR )
{
  ucFinishFlag = 1;
  Flash_SetCRC16(uiFlashCRC16);
}
}

 MY PROBLEM is, when I try to read the flash memory, see uiCryptPos or *pucBuffer, in the debug modus, the content of memory is wrong! 

 

My function works very good, when I calculate the page  at start address 0x007F4000 to 0x007F7FFF

 

I dont know what to do and there is no help in the web concerning my problem.

 

thanks for help in advance

 

best regards

Outcomes