This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

crc模块计算出的signature 是一般算法的CRC值吗?

Other Parts Discussed in Thread: HALCOGEN, TMS570LS3137

我用的是你们crc64模块,定义了一个数组 int32 arr[4]={0x01234567,0x89abcdef,0x0,x0};第一次arr[0],arr[1],存放的是要计算的数据,计算crc后赋给arr[2],arr[3],第二次计算arr[0] arr[1] arr[2] arr[3] 数据的CRC值,发现第二次的CRC值竟然不是0!!!调整了字节顺序也不行!!

 

#include "sys_common.h"

 #include "system.h"

#include "crc.h"

 #include "het.h"

 int main(void)

{  

uint64 crc=0x0U;  

uint32 i=0;

 crcModConfig_t  conf;  

conf.mode=CRC_FULL_CPU;  

conf.crc_channel=0x00000000;  //需要计算的地址  

uint32 arr[4={0x01234567,0x89abcdef,0x0,x0};

conf.src_data_pat=arr;  

conf.data_length=1//长度指64 pattern

 //初始化CRC模块  

crcInit();  

crcSignGen(crcREG,&conf);

 

 /*读CRC的值

 arr[2]crcREG->PSA_SECSIGREGH1;  

arr[3]crcREG->PSA_SECSIGREGL1;

  //再进行一次实验,检验CRC计算正确性

 conf.src_data_pat=arr;  

conf.data_length=2

 crcInit();  

crcSignGen(crcREG,&conf);

 return 0;

}

  • Hi ron,

    由于你的数组设置是的32位,而CRC是按64位的计算的,所以这里就涉及到64存放顺序的问题。

    请把Main函数改成以下:

    void main(void)
    {
    /* USER CODE BEGIN (3) */
     uint64 crc=0x0U;
     uint32 i=0;
     uint32 arr[4]={0x01234567,0x89abcdef,0x0,0x0};

     crcModConfig_t  conf;

     conf.mode=CRC_FULL_CPU;
     conf.crc_channel=0x00000000;  //需要计算的地址
     conf.src_data_pat=(uint64*)arr;
     conf.data_length=1;//长度指64 pattern

     //初始化CRC模块

     crcInit();
     crcSignGen(crcREG,&conf);

      //读CRC的值

     arr[3]=crcREG->PSA_SECSIGREGH1;
     arr[2]=crcREG->PSA_SECSIGREGL1;

       //再进行一次实验,检验CRC计算正确性

     conf.src_data_pat=(uint64*)arr;
     conf.data_length=2;
     crcInit();

     crcSignGen(crcREG,&conf);

     while(1);

    }

    这样,可以看到CRC的结果是0.

    PsaSecSigL1 0x00000000 PSA Sector Signature Low Register 1 [Memory Mapped] 
    PsaSecSigH1 0x00000000 PSA Sector Signature High Register 1 [Memory Mapped] 

    Regards,

    Jay

  • 谢谢!您能把你测试的代码(包括头文件等)发给我吗?不胜感激,,,

  • Hi ron,

    工程压缩档:

    Regards,

    Jay

  • 这是我用halcogen生成的代码,这种计算方法对吗?  和你给我的代码计算出crc不同,,,下面我发的自动生成的感觉不是真正的CRC,,,

  • Hi ron,

    这个函数是用哪个版本的Halcogen生成的?

    我的工程文件是用最新版本 Halcogen生成的,版本号03.06.00。升级再试试。

    另外,我的工程是TMS570LS3137的,你用的芯片是那个颗呢?

    Regards,

    Jay

  • 用的是HACOGEN 版本 是03.05.00 用的是RM48950ZWT,,,,应该是生成的代码问题,,,,比如要计算0x0123456789abcdef的CRC值,实际算的是0x 00000000 01234567 89abcdef 的 CRC值,,,

  • 实际算的是0x 00000000 01234567 89abcdef  00000000

  • Hi ron,

    你说的没错。

    CRC计算Signature的时候,加入操作一定要按64位一起写进去。PSA Signature Register不管是写入高32位还是低32位,只要有写入操作就会计算一次CRC。所以,Halogen 03.05.00的函数,按32位写入来计算是不对的,分别写入高32位和低32位实际上就计算了两次CRC。

    请更新Halcogen到03.06.00,写入操作按64位数来操作。

    Regards,

    Jay