CRC Example

Source code path: example/hal/crc

Supported Platforms

  • sf32lb52-lcd_n16r8

Overview

This example demonstrates using the CRC module for CRC checksum calculations, including:

  • CRC standard model calculations

    • Supported standard models are defined in the enumeration HAL_CRC_Mode.

  • Custom polynomial and initial value calculations

Example Usage

Hardware Requirements

Before running this example, you need to prepare a development board supported by this example

Compilation and Programming

Switch to the example project directory and run the scons command to compile:

scons --board=sf32lb52-lcd_n16r8 -j32

Run build_sf32lb52-lcd_n16r8_hcpu\uart_download.bat, select the port as prompted to download:

$ ./uart_download.bat

     Uart Download

please input the serial port num:5

For detailed steps on compilation and downloading, please refer to the relevant introduction in Getting Started Guide.

Expected Results

After the example starts, the serial port outputs the following:

  1. Print raw data:

10-20 20:35:31:631    Input raw data:
10-20 20:35:31:633     0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
10-20 20:35:31:635     0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x64,
10-20 20:35:31:637     0x61, 0x74, 0x61, 0x20, 0x75, 0x73, 0x65, 0x64,
10-20 20:35:31:639     0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x65, 0x73,
10-20 20:35:31:641     0x74, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x72, 0x63,
10-20 20:35:31:643     0x20, 0x61, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74,
10-20 20:35:31:644     0x68, 0x6d, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20,
10-20 20:35:31:693     0x74, 0x68, 0x65, 0x20, 0x63, 0x72, 0x63, 0x20,
10-20 20:35:31:698     0x68, 0x61, 0x72, 0x64, 0x77, 0x61, 0x72, 0x65,
10-20 20:35:31:704     0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e,
  1. CRC-7/MMC calculation result:

10-20 20:35:31:710    CRC Result(mode:0):
10-20 20:35:31:717    0x61
  1. CRC_8 calculation result:

10-20 20:35:31:722    CRC Result(mode:1):
10-20 20:35:31:726    0x62
  1. CRC-8/ITU calculation result:

10-20 20:35:31:730    CRC Result(mode:2):
10-20 20:35:31:734    0x37
  1. CRC-8/ROHC calculation result:

10-20 20:35:31:740    CRC Result(mode:3):
10-20 20:35:31:746    0xCD
  1. CRC-8/MAXIM calculation result:

10-20 20:35:31:750    CRC Result(mode:4):
10-20 20:35:31:754    0xBA
  1. CRC-16/IBM calculation result:

10-20 20:35:31:758    CRC Result(mode:5):
10-20 20:35:31:762    0x5263
  1. CRC-16/MAXIM calculation result:

10-20 20:35:31:767    CRC Result(mode:6):
10-20 20:35:31:775    0xAD9C
  1. CRC-16/USB calculation result:

10-20 20:35:31:781    CRC Result(mode:7):
10-20 20:35:31:785    0x72F2
  1. CRC-16/MODBUS calculation result:

10-20 20:35:31:794    CRC Result(mode:8):
10-20 20:35:31:799    0x8D0D
  1. CRC-16/CCITT calculation result:

10-20 20:35:31:806    CRC Result(mode:9):
10-20 20:35:31:810    0xFC57
  1. CRC-16/CCITT-FALSE calculation result:

10-20 20:35:31:814    CRC Result(mode:10):
10-20 20:35:31:819    0xBED
  1. CRC-16/X25 calculation result:

10-20 20:35:31:823    CRC Result(mode:11):
10-20 20:35:31:826    0xA52A
  1. CRC-16/XMODEM calculation result:

10-20 20:35:31:830    CRC Result(mode:12):
10-20 20:35:31:834    0x4A88
  1. CRC-16/DNP calculation result:

10-20 20:35:31:839    CRC Result(mode:13):
10-20 20:35:31:843    0xD423
  1. CRC-32 calculation result:

10-20 20:35:31:847    CRC Result(mode:14):
10-20 20:35:31:854    0x15B6B604
  1. CRC-32/MPEG_2 calculation result:

10-20 20:35:31:858    CRC Result(mode:15):
10-20 20:35:31:862    0x42F1290F
  1. Custom polynomial and initialization calculation result:

10-20 20:35:31:866    CRC Result(CRC_8 initial value:0xFF poly:0x1D):
10-20 20:35:31:869    0x45 

Exception Diagnosis

Reference Documents

Update Log

Version

Date

Release Notes

0.0.1

10/2024

Initial version