How to set the CRC peripheral of STM32

**Foreword** All STM32 microcontrollers come with a built-in CRC (Cyclic Redundancy Check) peripheral that provides hardware support for CRC calculations, which helps reduce the amount of code required in applications. The CRC value is commonly used to verify data integrity during data transmission and storage. In standards like IEC 60335, the integrity of the Flash memory is also verified using CRC checks. In applications where Flash integrity is checked via CRC, the CRC value of the entire Flash memory (excluding the byte that stores the CRC itself) must be calculated beforehand and stored at the end of the Flash. During program startup or runtime, the same method is used to calculate the CRC value of the entire Flash, and it is then compared with the pre-stored CRC value at the end of the Flash. Since version 5.5, EWARM has supported CRC calculation for STM32 devices. The process of calculating the CRC of the entire Flash and storing it at the end can be done directly within IAR. By configuring the CRC parameters in EWARM, the tool automatically calculates the CRC across the entire Flash space and places the result at the end. This article explains how to configure the IAR settings to match the CRC hardware module on STM32 microcontrollers. The examples provided are based on the STM32F072 series. **STM32 CRC Peripherals** The CRC check value is generated using polynomial division, which can be efficiently implemented through XOR operations between the divisor and the dividend. This method is well-suited for hardware implementation. When using the STM32 CRC peripheral, there are several key factors to consider: the generating polynomial, the input data (the data being verified), and the initial value. **Generating Polynomial** By default, the CRC32 polynomial is used: 0x4C11DB7. Some STM32 models, such as the STM32F3, STM32F0, and STM32L0 series, allow users to program their own polynomials. **Initial Value** The default initial value for STM32 CRC is 0xFFFFFFFF. However, certain STM32 series like F3, F0, and L0 allow the initial value to be modified. **Input/Output Data Inversion** The STM32F3, STM32F0, and STM32L0 series also offer the option to invert the input and output data. By default, no bit inversion is performed on the input or output data. - Bitwise inversion can be applied per byte, half-word, or word. For example, if the input data is 0x1A2B3C4D: - Inverting each byte results in 0x58D43CB2. - Inverting each half-word gives 0xD458B23C. - Inverting each word produces 0xB23CD458. - Output data can also be reversed. For instance, if the output is 0x11223344, reversing the bits would give 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 IAR linker file: ``` define symbol __CRC_START = 0x0801FFFC; ``` This line sets the location of the CRC checksum at the very end of the Flash memory. It is important to note that this is the end of the entire Flash space, not just the application code. As a result, the position of the CRC value remains fixed, regardless of the size of the code. **2. Configure the Checksum Page** In IAR v6.4 and above, the Checksum page is divided into two parts: - The first section defines the range of Flash memory where the CRC should be calculated and the padding value to be used. - The second section contains the configuration options for the CRC calculation. Key configuration parameters include: - **Checksum Size:** Choose the size of the checksum (in bytes). - **Alignment:** Define the alignment of the checksum. If not specified, the default is 2-byte alignment. - **Algorithm:** Select the algorithm used for the checksum calculation. - **Complement:** Decide whether to perform a complement operation. Choosing "As Is" means no complement is applied. - **Bit Order:** Set the order of the bits in the output. Options are MSB first (most significant bit first) or LSB first (least significant bit first). - **Reverse Byte Order Within Word:** This setting reverses the order of individual bytes within a word during processing. - **Initial Value:** Set the initial value used for the CRC calculation. - **Checksum Unit Size:** Choose the size of the unit for iteration—8-bit, 16-bit, or 32-bit. **3. STM32 CRC Peripheral Default Configuration vs. IAR Settings** For STM32 CRC peripherals, the default configuration includes: - **POLY:** 0x4C11DB7 (CRC32) - **Initial_Crc:** 0xFFFFFFFF - **Input/Output Data:** No inversion by default - **Input Data Range:** 0x08000000 to 0x0801FFFB (with the last 4 bytes reserved for the CRC value) These settings should be matched in IAR to ensure consistency between the software and hardware CRC modules. In practice, you can adjust these configurations based on your specific application requirements. Always double-check the settings against the documentation of both the STM32 and IAR tools to ensure correct functionality.

60Hz Diesel Generator

60Hz Diesel Generator assembly by diesel engine, alternator, radiator, controller, base frame;

. World Famous diesel engine brand: Cummins, Perkins, MTU, Kubota, Yuchai, Mitsubishi, Deutz, Doosan, MWM, GE, CRRC

. World famous AC alternator brand: Stamford, Leroy Somer, Mecc Alte, Marathon, Faraday, SWT

. World famous genset controller brand: Deepsea, ComAp, Deif, SmartGen,

. Good Quality Cooling Radiator

. Start Battery system

. 60Hz, 1800rpm

. Low or middle speed: 1200rpm, 900rpm, 720rpm, 600rpm, 500rpm

60Hz Genset,60Hz Generator,60Hz Generator Set,60Hz Diesel Generator

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