HAL CRC How to Use

group CRC_How_To_Use

How to use the CRC HAL module driver

Use the CRC HAL driver as follows:

  • Declare a hal_crc_handle_t handle structure, for example: hal_crc_handle_t hcrc;

  • Initialize the CRC handle by calling the HAL_CRC_Init() API. This API performs these operations:

    • Associate the instance with the handle

    • Initialize the handle state to HAL_CRC_STATE_IDLE

  • Enable the CRC peripheral clock:

    • Either at application level by calling the HAL_RCC_CRC_EnableClock() API

    • Or set the USE_HAL_CRC_CLK_ENABLE_MODEL define to HAL_CLK_ENABLE_PERIPH_ONLY within the stm32c5xx_hal_conf.h file. In this case, the CRC clock is enabled within the HAL_CRC_Init() API

  • Keep the default configuration (default register values) or configure the CRC module with user values:

    • Declare a hal_crc_config_t structure

    • Fill all parameters of the declared configuration structure

    • Call the HAL_CRC_SetConfig()

      function. This function:

      Update the CRC registers according to the user configuration provided by the input config structure

  • To restore the CRC default configuration, use the HAL_CRC_ResetConfig()

    API:

    This function resets the CRC configuration to the default one by setting the following fields to their default values:

    • The polynomial coefficient is set to 0x04C11DB7U

    • The polynomial size is set to 32-bits

    • The CRC init value is set to 0xFFFFFFFFU

    • The input reversibility mode is set to none

    • The output reversibility mode is set to none

  • For CRC I/O operations, one operation mode is available within this driver: polling mode I/O operation

    • Compute the CRC value of the input data buffer starting with the configured CRC initialization value using the HAL_CRC_Calculate() function

    • Compute the CRC value of the input data buffer starting with the previously computed CRC using the HAL_CRC_Accumulate() function

  • Deinitialize the CRC peripheral by calling the HAL_CRC_DeInit() API. This API performs these operations:

    • Reset the CRC configuration to the default one by setting the following fields to their default values:

      • The polynomial coefficient is set to 0x04C11DB7U

      • The polynomial size is set to 32-bits

      • The CRC init value is set to 0xFFFFFFFFU

      • The input reversibility mode is set to none

      • The output reversibility mode is set to none

    • Reset the independent data value to the default one (0xFFFFFFFFU)

    • Reset the handle state to the HAL_CRC_STATE_RESET