There's actually a really neat property of CRC that allows you to verify packets with 32 bit wide DMA even if they aren't a multiple of 4 bytes, without implementing CRC in software as well. First, the last aligned word of the packet should have the 'extra' bytes set to 0 - this should already be the case when it comes from the PIO but if it isn't just AND it with 0xFFFFFFFF << (packet_size % 4).In my implementation, all data passes twice through DMA (same for Tx and Rx, just in opposite order) - once, 32-bit wide, between PIO and memory, and once, 8-bit wide memory-to-memory to calculate the CRC using the hardware CRC in the DMA engine.
[...]
If your AES50 packets are all the same size, you could maybe improve that *4 by doing the CRCs word-wide.
The trick is that because CRC is a remainder of sorts, a message together with it's CRC is always a fixed value, 0x2144DF1C for the ethernet CRC if the random online calculator I'm using isn't lying to me. If there's now an additional byte with value 0x00 at the end, and the CRC is correct, then the value would instead be 0xC622F71D. Same with 0xB1C2A1A3 for 2 null bytes and 0x9D6CDF7E for 3.
That means you can simply let the DMA run over the entire packet including the CRC in 4 byte chunks, and check if the resulting CRC is equal to the value in an array made from the 4 values above, indexed by packet_size % 4.
It would've been really nice if there were multiple copies of the SNIFF_DATA/CTRL registers, to make sharing the CRC hardware between different DMA channels feasible. Something like 4 copies, each configurable to only listen to a specific DMA channel. Would be a really neat feature for just the cost of a couple more registers and muxes unless I'm missing something.It's not feasible to do the CRCs as the data arrives from the PIO for multiple reasons (Tx and Rx are simultaneous with only one CRC engine, on Rx you don't know in advance where the packet boundaries are and on Tx you have almost no time to get the calculated CRC out of the CRC engine and into the PIO to transmit it right after the last byte that you've just done the calculation on).
Statistics: Posted by Tharre — Thu Aug 07, 2025 11:20 pm