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.

TMS320F280037C: BGCRC and SREC CRC does not match up.

Part Number: TMS320F280037C


Hi! 

I'm trying to do run 128kB of data through BGCRC(  Flash bank. ). I'm not able to run all the data at once because it's in flash. I retrieve some of the data, run it through BGCRC and after the calculation is done I use the CRC result as the seed for the next calculation. Code composer checks if the BGCRC is idle before doing another calculation. The CRC I'm comparing to is calculated using SREC.

Also.. what CRC32 algorithm is BGCRC using?

SREC:

Fill 0xFFs
srec_cat.exe %outputfolder%\%projname%_clean.S -fill 0xFF %AppStartAddress% %AppEndAddress% -o %outputfolder%\%projname%_temp.S -Output_Block_Size=%blocksize%

Calculate checksum on filled hex file
%btfolder%\SREC\srec_cat.exe %outputfolder%\%projname%_temp.S -crop %AppStartAddress% %AppEndAddress% -CRC32LE %AppCrcAddress% -o %outputfolder%\%projname%_temp.S -Motorola 8 -Output_Block_Size=64

CCS:

INT16U  data[128] __attribute__ ((section(".BGCRC")));

//These are run in an init function:
BGCRC_setConfig(BGCRC_CPU_BASE, BGCRC_NMI_DISABLE, BGCRC_EMUCTRL_SOFT);
BGCRC_setRegion(BGCRC_CPU_BASE, (INT32U)&data, BGCRC_SIZE_BYTES_256, BGCRC_CRC_MODE);


void CheckFlashBankCRC(void)
{
    static INT32U WordsLeft = 57344; // Number of words in 14 sectors.
    static INT16U offset = 0;
    static INT32U crc = 0;
    INT32U receivedCrc = 0;
    static BOOL crcFinished = FALSE;



    // Check if BGCRC is finished with the previous calculation.
    if((BGCRC_getRunStatus(BGCRC_CPU_BASE) == BGCRC_IDLE))
    {
        crc = BGCRC_getResult(BGCRC_CPU_BASE);

        // Check if the crc is done.
        if(crcFinished)
        {
            // Read the received CRC in the flash bank.
            memcpy(receivedCrc, (INT32U*)(0x8DFFE + bankOffset), 2);

            // Check if CRC is OK
            if(receivedCrc == crc)
            {
                //Write revision
            }

            WordsLeft = 57344;
            offset = 0;
            crcFinished = FALSE;
        }
        else
        {
            BGCRC_setSeedValue(BGCRC_CPU_BASE, crc);
            
            if(WordsLeft <= 128)
            {
                // Read 128 words from Flash to RAM
                memcpy(data, (INT32U*)(0x80000 + bankOffset + offset), 128);
                // Last two words is set to FFFF because they contain the received CRC
                memset(data + 126, 0xFFFF, 2);
            }
            else
            {
                // Read 128 words from Flash to RAM
                memcpy(data, (INT32U*)(0x80000 + bankOffset + offset), 128);
            }

            WordsLeft -= 128;
            offset += 0x80;

            if(WordsLeft <= 0)
            {
                crcFinished = TRUE;
            }

            BGCRC_start(BGCRC_CPU_BASE);
        }
    }
}

  • The CRC I'm comparing to is calculated using SREC.

    You might find your problem is that srec.exe is unable to interpret the .hex/.s file correctly because in my experience the TI hex file output from hex2000.exe is not parse-able by many 3rd party tools due to the minimum addressable unit being 16 bits. Make a tiny hex file with one record that you can calculate the CRC manually and satisfy yourself that srec is going to calculate the expected CRC.

  • I have checked the SREC file and this is correct. My colleague looked at the source code of SREC and made a CRC32 function that made the CRCs match up. Thanks for your reply!