• AVR Freaks

DMA-CRC not producing results

Author
snellr314
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2017/09/01 11:54:37
  • Location: 0
  • Status: offline
2017/10/04 05:47:42 (permalink)
0

DMA-CRC not producing results

MPLAB v3.65. Harmony v1.07.01. MHC v1.0.7.16. PIC32MZ2048EFM144
 
I can't seem to get the hardware crc to produce any results.  
 
My project is just a fresh new blank project, populated with MHC by adding the system service DMA. In the app task I attempt a DMA CRC calculation one time (using my dmatest file). However, the crc calculation never seems to complete because my callback function never gets called and neither do the error ISRs in sys_dma.c.  


Any tips?
 
Entire project attached.
#1
snellr314
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2017/09/01 11:54:37
  • Location: 0
  • Status: offline
Re: DMA-CRC not producing results 2017/10/04 06:15:58 (permalink)
4 (1)
By changing my cellSize to match the srcSize, the dma completion callback function does get called. Now to confirm the CRC value returned...
#2
snellr314
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2017/09/01 11:54:37
  • Location: 0
  • Status: offline
Re: DMA-CRC not producing results 2017/10/04 08:18:45 (permalink)
0
I'm having trouble getting the CRC output to match what I expect.  I'm trying to keep things simple and calculate the CRC-CCITT on the byte 'a', expecting the output to be 0x69F0 (as stated by https://www.lammertbies.nl/comm/info/crc-calculation.html).  But after playing with all the settings I can find, I can only get outputs from the PIC of 0xE176 or 0xE191 depending on whether I use DMA_CRC_BIT_ORDER_LSB or DMA_CRC_BIT_ORDER_MSB. Changing the datasize of buf and dstbuf to uint16_t or uint32_t doesn't seem to matter.
 
My trigger code:

uint8_t __attribute__((coherent)) __attribute__((aligned(16)))buf[14];
uint8_t __attribute__((coherent)) __attribute__((aligned(16)))dstbuf[14];
 
int DmaDoCrcExample(void)
{
/* Allocate DMA channel */
dmaHandle = SYS_DMA_ChannelAllocate(DMA_CHANNEL_ANY);
if (SYS_DMA_CHANNEL_HANDLE_INVALID == dmaHandle) {
while (1); //Trapped
}

SYS_DMA_ChannelTransferEventHandlerSet(dmaHandle, myDMAEventHandler, (__uintptr_t)&thisthat);

SYS_DMA_ChannelSetup(dmaHandle,(SYS_DMA_CHANNEL_OP_MODE_BASIC | SYS_DMA_CHANNEL_OP_MODE_CRC),DMA_TRIGGER_SOURCE_NONE);

/*
crc.type - CRC will calculate an IP header checksum or an LFSR CRC.
crc.mode - Compute the CRC in Background/Append mode.
crc.polyLength - Denotes the length of the polynomial.
crc.bitOrder - CRC is calculated LSb/MSb first.
crc.byteOrder - Byte selection order input pre-CRC Generator
crc.writeOrder - Write byte order selection post-CRC computation
crc.data - Computed/Seed CRC
crc.xorBitMask - Enable/Disable XOR bit mask on the corresponding bits
when mode is LFSR
*/
static SYS_DMA_CHANNEL_OPERATION_MODE_CRC crcMode;

crcMode.type = DMA_CRC_LFSR;
crcMode.mode = SYS_DMA_CHANNEL_CRC_MODE_APPEND;//SYS_DMA_CHANNEL_CRC_MODE_BACKGROUND;//
crcMode.polyLength = 16;
crcMode.bitOrder = DMA_CRC_BIT_ORDER_LSB;//DMA_CRC_BIT_ORDER_MSB;//
crcMode.byteOrder = DMA_CRC_BYTEORDER_NO_SWAPPING;//DMA_CRC_SWAP_BYTE_ON_WORD_BOUNDARY;//DMA_CRC_SWAP_HALF_WORD_ON_WORD_BOUNDARY;//DMA_CRC_SWAP_BYTE_ON_HALF_WORD_BOUNDARY;//
crcMode.writeOrder = SYS_DMA_CRC_WRITE_ORDER_MAINTAIN;//SYS_DMA_CRC_WRITE_ORDER_CHANGE;//
crcMode.data = 0xFFFF;
crcMode.xorBitMask = 0x1021;

SYS_DMA_ChannelCRCSet(dmaHandle, crcMode);
/*
srcAddr - Source of the DMA transfer
srcSize - Size of the source
destAddr - Destination of the DMA transfer
destSize - Size of the destination
cellSize - Size of the cell
*/

buf[0] = 'a';
buf[1] = 'b';
buf[2] = 'c';
buf[3] = 'd';
buf[4] = 'e';
buf[5] = 'f';
buf[6] = 'g';
buf[7] = 'h';
buf[8] = 'i';
buf[9] = 'j';
dstbuf[0] = 1;
dstbuf[1] = 1;
dstbuf[2] = 1;
dstbuf[3] = 1;
dstbuf[4] = 1;
dstbuf[5] = 1;
dstbuf[6] = 1;
dstbuf[7] = 1;
dstbuf[8] = 1;
dstbuf[9] = 1;

void *srcAddr;
void *destAddr;
size_t srcSize;
size_t destSize;
size_t cellSize;
srcAddr = (uint16_t *) &buf[0];
srcSize = 1;
destAddr = (uint16_t*) dstbuf;
destSize = 1;
cellSize = 1;

SYS_DMA_ChannelTransferAdd(dmaHandle, srcAddr, srcSize, destAddr, destSize, cellSize);
if(SYS_DMA_CHANNEL_HANDLE_INVALID == dmaHandle)
{
// Error handling here
}

//SYS_DMA_ChannelEnable(dmaHandle);
SYS_DMA_ChannelForceStart(dmaHandle);
//SYS_DMA_ChannelRelease(dmaHandle);
return (0);
}

 
event handler:

void myDMAEventHandler(SYS_DMA_TRANSFER_EVENT event,
SYS_DMA_CHANNEL_HANDLE handle, uintptr_t contextHandle){
uint32_t output = 0;
/* handler */
output = SYS_DMA_ChannelCRCGet();

while (output > 0){
output--;
}
}

#3
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
Re: DMA-CRC not producing results 2017/10/04 08:29:04 (permalink)
0
I am not sure 'cause i never used the CRC module, but is this
 crcMode.xorBitMask = 0x1021;
correct?

What CRC are you willing to use?

GENOVA :D :D ! GODO
#4
snellr314
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2017/09/01 11:54:37
  • Location: 0
  • Status: offline
Re: DMA-CRC not producing results 2017/10/04 09:33:57 (permalink)
0
I'm quite sure the xorbitmask of 0x1021 is correct because it matches the CCITT polynomial: 
CRC-CCITT0x1021x16 + x12 + x5 + 1 
Also, I referenced the https://www.lammertbies.nl/comm/info/crc-calculation.html site which indicates:

Just as a reference the polynomial functions for the most common CRC calculations. Please remember that the highest order term of the polynomal (x16 or x32) is not present in the binary number representation, but implied by the algorithm itself.

 
#5
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
Re: DMA-CRC not producing results 2017/10/04 09:45:44 (permalink)
0
I agree on that;
I was just not sure about that number at a glance, since it was not listed on that site in the upper window.
 
So, next step would be trying a software solution and then move on to the DMA version.

GENOVA :D :D ! GODO
#6
snellr314
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2017/09/01 11:54:37
  • Location: 0
  • Status: offline
Re: DMA-CRC not producing results 2017/10/05 06:58:57 (permalink)
3 (1)
The CRC-CCITT calculation difference is found in the 16bit zero augmentation at the end of the data, as touched on in other forums.
For simplicity, in order to get the correct CRC-CCITT calculation for the message "a", instead of having one byte of data 'a', use three bytes of data 'a', 0x00, 0x00. The 16bit zero augmentation is required.
 
The output of the pic32mz crc algorithm (MSB, 0xFFFF seed, 0x1021 bitmask) is 0x9479.
I can at least find this value on the sample crc calculation websites.
On https://www.lammertbies.nl/comm/info/crc-calculation.html that value is the result with the 0x1D0F seed. 
On http://srecord.sourceforge.net/crc16-ccitt.html that value is the result of the 0xFFFF seed.
 
Extending my data to "AB" with two zero bytes, the result of the pic32mz algorithm is 0xD2BB.
Again, on lammertbies this matches the 0x1D0F seed. 
 
So at least I have consistency.
#7
Jump to:
© 2019 APG vNext Commercial Version 4.5