4
votes

I'm working with an ARM cortex M3 board which has an hardware CRC calculation unit. It supports 3 standard CRC polynominals. The interface to the module is very simple. I need to provide a pointer to the data and the data length. The problem I have is that it calculates LSB first. and I need to know the CRC Msb first (xmodem crc16-itt). Is there anyway to take the calculation it got and transform it into msb first?

3
When you say it calculates LSB first, you mean least significant bit or byte? Is your problem with bit order or byte order? I assume you are not saying just that the result contains the correct 2-byte CRC but just swapped order?TJD
what cortex m3 board/chip is this?old_timer
the sam3s4 is what you said. Now is this about speed or size? Do you have to use the hardware crc engine or what if you had a small footprint software solution?old_timer
why is the data stored with the wrong endian? is it transmitted or copied or shared in a way that cannot be swapped as received/sent?old_timer
@dwelch: When creating the firmware, you create a file on a PC which has different endianess than ARM. when the file is transferred to the device, it is saved in flash. because it's firmware I'm transferring, I can't switch the bytes around.stdcall

3 Answers

2
votes

EDIT/REWRITE:

From the information provided I think you have these choices:

1) arrange the data on the host (which is assumed to not be as resource constrained as a microcontroller) so that the microcontroller does not have to do as much work.

2) Make a (byteswapped) copy of the data using features/instructions where possible to make that faster, and then let the hardware CRC engine compute the crc.

3) Dont use the hardware crc engine, compute the crc using software.

4) Ignore the crc.

5) Use a different microcontroller (that can handle this use case).

0
votes

[...] I need to know the CRC Msb first (xmodem crc16-itt). Is there anyway to take the calculation it got and transform it into msb first?

The xmodem crc16-itt operates on bytes as data. So Most Significant Byte first or Least Significant Byte first will matter only for the representation of the CRC value. Just swap the computed value - e.g. with __REV16() CMSIS function.

Edit:

I assumed both sides see 0x01 0x02 0x03 0x04 as such. If one side sees different bytes, e.g. 0x04 0x03 0x02 0x01 in memory then the CRC will fail. But you probably want to fix that sooner than later anyway, as that will give you severe headache when processing the data.

-1
votes

Just swap the 2 bytes like this:

unsigned short crc_little_endian = ...; // call to your CRC function
unsigned short crc_big_endian = (crc_little_endian >> 8) | (crc_little_endian << 8);