Data compress flash command of S12XDP512

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Data compress flash command of S12XDP512

1,978 Views
Noir
Contributor I
Hello!
 
I´ve questions about the data compress flash command of the S12XDP512 MCU:
 
- Is it possible for the MCU to execute from flash while the data compress command is executed (even if it uses the same flash block?) or must the MCU execute in RAM while the command is running?
 
- I´ve written a piece of software for the pc to calculate the signature, but I don't get correct results. Maybe I didn't understand the underlying algorithm correct, which is described in the datasheet (S12XFTX512K4V2, page 1135 of the s12xdp512 datasheet; for a single misr):
 
1) MISR is set to 0xFFFF
2) 0xFFFF is compressed (-> Result is 0x0001)
3) Data is compressed (with address incrementing)
4) Data is compressed (with address decrementing)
5) Result in MISR (on the MCU it is written to FDATA)
 
I`ve tested this with one word, compressed with the MCU, the Data Compress Util (downloaded from freescale) and my own software:
 
Here the results: (Testword-Data: 0xFFFF)
 
MCU: 0xFFFA
Data Compress Util: 0xFFFA
My Software: 0x0004
 
Here is a line of my software, which calculates the content of the misr:
 
misr=((misr<<1) | (((misr>>15) ^ (misr>>4) ^ (misr>>2) ^ (misr>>1)) & 0x01)) ^ data;
 
On Start MISR ist initialized to 0xFFFF and then this line is executed 3 times (init; address increment; address decrement) with data=0xFFFF -> gives 0x0004
 
What's wrong?
 
Thanks for help, Noir.
Labels (1)
0 Kudos
5 Replies

493 Views
kef
Specialist I
1) No, it's not possible to "compress" from flash. You code should execute from RAM since flash is not readable while CCIF is 0 or while KEYACC is 1.
 
2) I also was puzzled by MISR checksum description. I remember I managed to make my MISR() and softMISR() routines returning the same results, see below. However I'm not sure if these routines are those last ones that worked. Still should shed some light on MISR:
 
Code:
unsigned CRC;unsigned crc_16(unsigned int c){char SH15 =0;char xorv;   if(CRC & (1<<15)) SH15 =1;   if(CRC & (1<<4)) xorv = 1;   else              xorv = 0;   SH15 ^= xorv;   if(CRC & (1<<2)) xorv = 1;   else              xorv = 0;   SH15 ^= xorv;   if(CRC & (1<<1)) xorv = 1;   else              xorv = 0;   SH15 ^= xorv;      CRC = ((CRC<<1) | SH15) ^ c;   return CRC;}int softMISR(int *adr, int size){int i;   CRC=1;   for(i=0; i<size;i++)   {      crc_16(*adr);      adr++;   }   for(i=0; i<size;i++)   {      adr--;      crc_16(*adr);   }   crc_16(CRC);   return CRC;}
// MISR routine should run from RAM
int MISR(int *adr, int size)
{
   FSTAT = 0x30;  // clear errs
   *adr = size;
   FCMD = 0x6;
   FSTAT &= 0x80;
   while(!(FSTAT & 0x40));
   return FDATA;
}

 
0 Kudos

493 Views
Noir
Contributor I
Thank you for the example code! I forgot the last step (compress the content of the MISR). Now i get the same results as your excample code (Result: 0x000D) for a single 0xFFFF word, but i still get not the same result as the MCU, or the Data Compress Utility (Result: 0xFFFA).
 
Here is my code. A little bit smaller, but it does the same:
 
void DataCompressWord(unsigned short *misr, unsigned short data)
{
  *misr=((*misr<<1) | (((*misr>>15) ^ (*misr>>4) ^ (*misr>>2) ^ (*misr>>1)) & 0x01)) ^ data;
}

unsigned short DataCompress(unsigned short *data, unsigned int length)
{
  unsigned short misr=0xFFFF;
  unsigned int i;
  DataCompressWord(&misr, 0xFFFF);
  for(i=0;i<length;i++)
  {
    DataCompressWord(&misr,data[i]);
  }
  for(i=length;i>0;i--)
  {
    DataCompressWord(&misr,data[i-1]);
  }
  DataCompressWord(&misr, misr);
  return misr;
}
 
0 Kudos

493 Views
kef
Specialist I
Both versions, yours and mine are working the same. Isn't problem caused by far vs near pointer differences? I'm using near pointers at the moment and hardware MISR matches software MISR. Flash block I'm testing is not empty, tested will all test block lengths from 1 to >3000 words. All checksums matched. 0L15Y maskset if that matters.
 
Regards
0 Kudos

493 Views
Noir
Contributor I
I found the mistake. I thought that the flash blocks are in ascending order in the memory map, but that's not true. I compressed one word at the address 0x780000, which is in block 3 (not in block 0). So it's wrong to compress the result in the same misr, it has to be compressed into another (in hardware misr of block 0), which contains 0xFFFF. So i got the correct results!
 
Now it's working, thanks for your help!
0 Kudos

493 Views
kef
Specialist I
Thenks, I've forgot about MISR algorithm differences between MISR of flash block 0 and MISR of other flash blocks. Now I remember why I decided to not use MISR. Standard CRC's are more stright forward and don't depend on number of flash block.
 
So bottom lines of your DataCompress routines should be something like this:
 
...
  i = misr;
  if ( not calculating misr for flash block 0 ) 
      misr = 0xFFFF;
  DataCompressWord(&misr, i);
  return misr;
}
 
Regards
0 Kudos