Demo of CRC hardware on nucleo F446RE

Dependencies:   mbed

Committer:
manitou
Date:
Sat Apr 23 00:44:02 2016 +0000
Revision:
0:b154a7908ef1
demo of CRC hardware

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manitou 0:b154a7908ef1 1 // test CRC hardware, stupid only 32-bit words, fixed poly
manitou 0:b154a7908ef1 2 // CRC32, CRC-32/ADCCP, PKZIP, ETHERNET, 802.3
manitou 0:b154a7908ef1 3 // (poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xcbf43926)
manitou 0:b154a7908ef1 4 #include "mbed.h"
manitou 0:b154a7908ef1 5
manitou 0:b154a7908ef1 6 Timer tmr;
manitou 0:b154a7908ef1 7 #define BUFSIZE 16384
manitou 0:b154a7908ef1 8
manitou 0:b154a7908ef1 9 uint8_t buf[BUFSIZE] __attribute__((aligned(4)));
manitou 0:b154a7908ef1 10
manitou 0:b154a7908ef1 11
manitou 0:b154a7908ef1 12 int main() {
manitou 0:b154a7908ef1 13 int i;
manitou 0:b154a7908ef1 14
manitou 0:b154a7908ef1 15 printf("\nSystemCoreClock %d %s %s\n",SystemCoreClock,__TIME__,__DATE__);
manitou 0:b154a7908ef1 16 tmr.start();
manitou 0:b154a7908ef1 17 RCC->AHB1ENR |= RCC_AHB1ENR_CRCEN; // enable CRC
manitou 0:b154a7908ef1 18 for ( i=0; i<BUFSIZE; i++) {
manitou 0:b154a7908ef1 19 buf[i] = (i+1) & 0xff;
manitou 0:b154a7908ef1 20 }
manitou 0:b154a7908ef1 21 while(1) {
manitou 0:b154a7908ef1 22 uint32_t i,us, *p = (uint32_t *)buf;
manitou 0:b154a7908ef1 23
manitou 0:b154a7908ef1 24 CRC->CR = 1; // reset
manitou 0:b154a7908ef1 25 while(CRC->DR != ~0); // wait for reset
manitou 0:b154a7908ef1 26 us = tmr.read_us();
manitou 0:b154a7908ef1 27 for(i=0;i<BUFSIZE/4;i++) CRC->DR = __RBIT(p[i]);
manitou 0:b154a7908ef1 28 us = tmr.read_us() - us;
manitou 0:b154a7908ef1 29 printf("0x%08x %d us ?=0x1271457f\n",~__RBIT(CRC->DR),us);
manitou 0:b154a7908ef1 30 us = __RBIT(0x41414141); // AAAA crc should be 9b0d08f1
manitou 0:b154a7908ef1 31 CRC->CR = 1; //reset
manitou 0:b154a7908ef1 32 while(CRC->DR != ~0); // wait for reset
manitou 0:b154a7908ef1 33 CRC->DR = us;
manitou 0:b154a7908ef1 34 printf("%x 0x%x crc(AAAA)=9b0d08f1\n",CRC->DR,~__RBIT(CRC->DR));
manitou 0:b154a7908ef1 35 CRC->CR = 1; // reset
manitou 0:b154a7908ef1 36 while(CRC->DR != ~0); // wait for reset
manitou 0:b154a7908ef1 37 CRC->DR = 0;
manitou 0:b154a7908ef1 38 printf("0x%x crc(0)=2144df1c\n",~__RBIT(CRC->DR));
manitou 0:b154a7908ef1 39
manitou 0:b154a7908ef1 40 wait(5.0);
manitou 0:b154a7908ef1 41 }
manitou 0:b154a7908ef1 42 }