How to set the CRC peripheral of STM32

**Foreword** All STM32 microcontrollers are equipped with a CRC (Cyclic Redundancy Check) peripheral that provides hardware support for CRC calculations, helping to reduce the code size in applications. The CRC check value is commonly used to verify the integrity of data during transmission and storage. In standards like IEC 60335, the integrity of the Flash memory is also verified using CRC checks. In Flash integrity checking applications, it's necessary to calculate the CRC value of the entire Flash memory (excluding the byte where the CRC value is stored) in advance and place it at the end of the Flash. During program startup or execution, the same method is used to compute the CRC of the entire Flash and compare it with the stored CRC value at the end. Since version 5.5, EWARM supports CRC calculation for STM32 chips. Using IAR, you can calculate the CRC of the entire Flash and store the result at the end of the Flash. By configuring the CRC parameters in EWARM, the system automatically calculates the CRC over the entire Flash space and places the result at the end. This article explains how to configure the IAR CRC settings to match the STM32 hardware CRC module. The examples in this article are based on the STM32F072. **STM32 CRC Peripherals** The CRC check value is calculated using polynomial division, which can be implemented via XOR operations between the divisor and dividend. This makes it highly suitable for implementation in hardware circuits. When using the STM32 CRC peripheral, it's important to consider the following factors: the CRC polynomial used, the input data (the data to be verified), and the initial value. **1. Generating Polynomial** By default, the STM32 uses the CRC32 polynomial: `0x4C11DB7`. Some STM32 series, such as the STM32F3, STM32F0, and STM32L0, support programmable polynomials. **2. Initial Value** The default initial value for the STM32 CRC is `0xFFFFFFFF`. However, the STM32F3, STM32F0, and STM32L0 series allow users to modify this initial value. **3. Input/Output Data Inversion** The STM32F3, STM32F0, and STM32L0 series also support inversion of input and output data. By default, no bit inversion is performed on the input or output data. - **Input Data Bit Inversion**: You can choose to invert bits in units of bytes, halfwords, or words. For example, if the input data is `0x1A2B3C4D`: - Inverting each byte gives `0x58D43CB2` - Inverting each halfword gives `0xD458B23C` - Inverting each word gives `0xB23CD458` - **Output Data Bit Reversal**: For example, if the output data is `0x11223344`, reversing the bits results in `0x22CC4488`. **IAR CRC Configuration** **1. Modify the Link File** To specify where the CRC checksum will be stored in Flash, add the following line to your link file: ``` CRC_CHECKSUM = 0x0801FFFC; ``` This statement defines the location of the CRC value at the end of the Flash. It is the very end of the entire Flash space, not just the end of the application code. Therefore, the position of the CRC value remains fixed regardless of the code size. **2. Configure the Checksum Page** In IAR (v6.4 and above), the Checksum page is divided into two parts: - The first part defines the range of Flash memory where CRC should be calculated and includes a free byte padding value. - The second part sets the CRC calculation parameters. **Checksum Parameters:** - **Checksum Size:** Choose the size of the checksum (in bytes). - **Alignment:** Specifies the alignment of the checksum. If not specified, the default is 2-byte alignment. - **Algorithm:** Select the algorithm used for checksum calculation. - **Complement:** Choose whether to perform a complement calculation. “Asis” means no complement is applied. - **Bit Order:** Define the order of bit output—MSB first (high-order bits first) or LSB first (low-order bits first). - **Reverse Byte Order Within Word:** Reverses the order of individual bytes within a word. - **Initial Value:** Set the initial value used in the CRC calculation. - **Checksum Unit Size:** Choose the unit size for iteration—8-bit, 16-bit, or 32-bit. **3. STM32 CRC Peripheral Default Configuration vs. IAR Settings** The STM32 CRC peripheral typically uses the following default configuration: - **Polynomial:** `0x4C11DB7` (CRC32) - **Initial Crc:** `0xFFFFFFFF` - **Input/Output Data:** No inversion - **Data Range:** `0x08000000` to `0x0801FFFB` (with the last 4 bytes reserved for the CRC value) Configuring these settings correctly ensures that the CRC generated by IAR matches the one computed by the STM32 hardware. In practice, you can adjust these settings based on your specific application requirements. Always verify that the CRC values match after configuration to ensure data integrity.

Power Transformer Station

Power transformer Station:

. Step-up transformer

. Step-down transformer

. Oil immersed transformer

. Dry type transformer

. Containerized transformer

. Transformer substation

. Packaged power substation

Power Trandformers,Distribution Transformer,Transformer Substation,Oil Immersed Tramsformer

Guangdong Superwatt Power Equipment Co., Ltd , https://www.swtgenset.com