/* * 函数名:main * 描述 :主函数 * 输入 :无 * 输出 :无 */ int main(void) { uint8_t i = 0; /* USART1 config 115200 8-N-1 */ USART1_Config(); /* 使能CRC时钟 */ CRC_Config(); printf("\r\n 这是一个 CRC(循环冗余校验)实验 \r\n"); /* Compute the CRC of "DataBuffer" */ for(i=0; i<BUFFER_SIZE; i++ ) { CRCValue = CRC_CalcBlockCRC((uint32_t *)DataBuffer, BUFFER_SIZE); printf("\r\n32-bit CRC 校验码为:0X%X\r\n", CRCValue); } printf("\r\nCRC(循环冗余校验)测试成功\r\n"); for(;;) { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontrollers clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file */ /* USART configuration -----------------------------------------------------*/ USART_Config(); /* SysTick configuration ---------------------------------------------------*/ SysTickConfig(); /* Initialize LEDs mounted on STM32303C-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); /* Configure the CRC peripheral to use the polynomial x8 + x7 + x6 + x4 + x2 + 1 */ CRC_Config(0xD5); #ifdef MODE_TRANSMITTER /* ------------------ USART in mode Tramitter ------------------------------*/ /* Configure the external interrupt "Joystick SEL" button */ STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); /* Forever loop */ while (1) { /*Wait "JOY_SEL" to start data transfer */ if ((PressedButton != JOY_NONE)) { /* Enable the USARTx transmit data register empty interrupt */ USART_ITConfig(USARTx, USART_IT_TXE, ENABLE); /* Set PressedButton to default value */ PressedButton = JOY_NONE; } } #else /* ------------------ USART in mode Receiver -------------------------------*/ /* Enable the USARTx receive data register not empty interrupt */ USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE); /* Infinite loop */ while(1) { } #endif /* MODE_TRANSMITTER */ }
/** * @brief Main program. * @param None * @retval None */ void CRC_32BitsCRCMessage(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file */ /* Initialize LEDs available on STM32303C-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED3); /* Configure the CRC peripheral to use the polynomial X32 + X26 + X23 + X22 + X16 + X12 + X11 + X10 +X8 + X7 + X5 + X4 + X2+ X +1 */ CRC_Config(0x4C11DB7); /* Compute the CRC value of the 8-bit buffer: CRCBuffer */ ComputedCRC = CRC_CalcBlockCRC(CRCBuffer, BUFFER_SIZE); /* Check if the computed CRC matches the expected one */ if (ComputedCRC != ExpectedCRC) { /* Turn on LD3 */ STM_EVAL_LEDOn(LED3); } else { /* Turn on LD1 */ STM_EVAL_LEDOn(LED1); } /* Infinite loop */ while(1) { } }
/*TASK*------------------------------------------------------------------- * * Task Name : CRC_main * Comments : * Demo application for CRC driver *END*----------------------------------------------------------------------*/ void CRC_main ( uint_32 initial_data ) { uint_32 crc_error=0; uint_32 poly; uint_32 tot; uint_32 totr; uint_32 fxor; uint_32 tcrc; uint_8 gbQuit = 0; uint_32 bByteCount; uint_8 ch; uint_32 seed,crc; uint_8 mode = 1; isCRC16 = 1; printf("\n====== CRC Lab ==========\r\n"); do { if (mode == 1) { mode = 0; printf("\nPlease select CRC width (16-bit/32-bit):\r\n"); printf("\n1. CRC16\n"); printf("\n2. CRC32\n"); printf("\n select:"); do { ch = fgetc(stdin); }while ((ch != '1') && (ch != '2')); printf("%c\r\n",ch); isCRC16 = !(ch-'1'); printf("\nPlease select CRC polynomial:\r\n"); printf("\n1. poly = 0x1021 (CRC-CCITT)\r\n"); printf("\n2. poly = 0x8408 (XMODEM)\r\n"); printf("\n3. poly = 0x8005 (ARC)\r\n"); printf("\n4. poly = 0x04C11DB7 (CRC32) \r\n"); printf("\n5. others\r\n"); printf("\nselect:"); do { ch = fgetc(stdin); }while(!((ch < '6') && (ch > '0'))); printf("%c\r\n",ch); if(ch == '5') { printf("Please enter a polynomial in hex format:"); poly = Input_Word(); } else { poly = polyTab[ch-'1']; } tcrc = (isCRC16)? 0: 1; printf("\nPlease select type of Transpose for input:\r\n"); printf("\n1. No Transposition\r\n"); printf("\n2. Only transpose bits in a byte\r\n"); printf("\n3. Transpose both bits and bytes\r\n"); printf("\n4. Only transpose bytes\r\n"); printf("\nselect:"); do { ch = fgetc(stdin); }while (!((ch < '5') && (ch > '0'))); printf("ch = %c \r\n",ch); tot = ch - '1'; printf("\nPlease select type of Transpose for Read:\r\n"); printf("\n1. No Transposition\r\n"); printf("\n2. Only transpose bits in a byte\r\n"); printf("\n3. Transpose both bits and bytes\r\n"); printf("\n4. Only transpose bytes\r\n"); printf("\nselect:"); do { ch = fgetc(stdin); }while (!((ch < '5') && (ch > '0'))); printf("ch = %c\r\n",ch); totr = ch - '1'; printf("XOR final checksum (y/n)?"); do { ch = fgetc(stdin); }while ((ch != 'y') && (ch != 'n')); printf("ch = %c\r\n",ch); fxor = (ch == 'y')? 1: 0; printf("\r\nPlease enter seed in hex:\r\n"); seed = Input_Word(); } printf("\nPlease enter an ASCII Message:"); bByteCount = Input_Message(&strMsg[0]); crc_error=CRC_Config(poly,tot,totr,fxor,tcrc); if(isCRC16) { crc = CRC_Cal_16(seed, &strMsg[0], bByteCount); printf("\n CRC result = %#04.4x\r\n",(crc & 0x0000FFFFL)); } else { crc = CRC_Cal_32(seed, &strMsg[0], bByteCount); printf("\n CRC result = %#08.8x\r\n",crc); } printf("\nPress any key to enter new data...,except 'q' to quit, 'c' to re-configuration !\r\n"); do { ch = fgetc(stdin); }while( !ch ); if(ch == 'q') { gbQuit = 1; } if(ch == 'c') { mode = 1; } }while(!gbQuit); gbQuit = 0; printf("\nDemo is quited!\r\n"); }