need help understanding srec_cat CRC

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I am trying to program a bootloader  to calculate the CRC of an app file stored in flash using the CRCCU on the G55. I am hoping to use the CRC to compare it within the bootloader to a known CRC to check for transmission errors. I was hoping to get the known CRC value from srec_cat, but it's not giving me the same value as the CRCCU is.

 

I was hoping someone could help me with a couple questions:

 

1. Does srec_cat calculate the checksum using only the data from the hex file, or does it include the addresses and 2's compliments at the start and end of each line?

 

2. Does srec_cat use one of the polynomials available in the peripheral to calculate the CRC, or does it use some other method?

 

Just trying to narrow down where my problem might be.

 

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay, an update to provide more information.

 

right now I am trying to get the CRC32 checksum for the byte 0x20. I found this CRC checksum calculator, and was able to deduce that srec_cat is using the polynomial  0xEDB88320  for its checksum calculations. Both the checksum calculator and srec_cat give me a checksum of  45 CF 6C E9  for the byte 0x20.

 

The CRCCU uses the polynomial  0x04C11DB7 according to the datasheet. In binary, this is the reverse of what srec_cat uses. is there any way to convert between the two, or is this project impossible?

 

Either way, I can't get the value out of the CRCCU to align with what the web CRC calculator says it should be.

 

Here's my crc check c code:

 


/*APP start location*/
#define APP_START_ADDRESS	0x00410000UL

#define APP_LENGTH		0x1


static uint32_t compute_crc(uint8_t *p_buffer, uint32_t ul_length,
uint32_t ul_polynomial_type)
{
	uint32_t ul_crc = 0;
	uint32_t ul_timeout = 0;

	/* Reset the CRCCU */
	crccu_reset(CRCCU);

	memset((void *)&crc_dscr, 0, sizeof(crccu_dscr_type_t));

	crc_dscr.ul_tr_addr = (uint32_t) p_buffer;

	/* Transfer width: byte, interrupt enable */
	crc_dscr.ul_tr_ctrl =
	CRCCU_TR_CTRL_TRWIDTH_BYTE | ul_length |
	CRCCU_TR_CTRL_IEN_ENABLE;

	/* Configure the CRCCU descriptor */
	crccu_configure_descriptor(CRCCU, (uint32_t) &crc_dscr);

	/* Configure CRCCU mode */
	crccu_configure_mode(CRCCU, CRCCU_MR_ENABLE | ul_polynomial_type);

	/* Start the CRC calculation */
	crccu_enable_dma(CRCCU);

	/* Wait for calculation ready */
	while ((crccu_get_dma_status(CRCCU) == CRCCU_DMA_SR_DMASR) &&
	(ul_timeout++ < CRCCU_TIMEOUT)) {
	}

	/* Get CRC value */
	ul_crc = crccu_read_crc_value(CRCCU);

	/* Display CRC */
	if (ul_polynomial_type == CRCCU_MR_PTYPE_CCITT16) {
		/* 16-bits CRC */
		ul_crc &= 0xFFFF;
		printf("  CRC of the buffer is 0x%04x\n\r", ul_crc);
		} else {
		/* 32-bits CRC */
		printf("  CRC of the buffer is 0x%08x\n\r", ul_crc);
	}

	return ul_crc;
}

int main (void)
{
	/*system initialization*/
	sysclk_init();
	board_init();
	
	/*configure the console UART*/
	configure_console();
	
	/* Enable CRCCU peripheral clock */
	pmc_enable_periph_clk(ID_CRCCU);

	/* Initialize flash: 6 wait states for flash writing. */
	flash_init(FLASH_ACCESS_MODE_128, 6);

	/* Unlock flash page. */
	flash_unlock(APP_START_ADDRESS,
	APP_END_ADDRESS, NULL, NULL);
	
	printf("Beginning CRC test \n");
	
	uint32_t crc_value2 = compute_crc((uint8_t *) APP_START_ADDRESS, APP_LENGTH, CRCCU_MR_PTYPE_CCITT8023);
	
		while (1) {

	}
}

 

The 0x20 is stored at location 0x410000, I can see it there in the debugger, and it remains there between programs. The code gives me the checksum D6 2B 09 54.

 

According to checksum calculator, I should be getting the value  9C CD A7 FB .

Can anyone please help me?