HAL CRC Functions

Initialization and De-initialization functions

group CRC_Exported_Functions_Group1

This subsection provides functions to initialize and deinitialize the CRC peripheral:

  • The HAL_CRC_Init() API: Allows initializing the HAL CRC driver so it can be configured and used to calculate the CRC of a given user data buffer. This API is the first API to call when using the HAL CRC. It takes two parameters as input:

    • The HAL CRC handle : A pointer to a hal_crc_handle_t structure

    • The CRC peripheral instance: A value from the enumeration hal_crc_t

  • The HAL_CRC_DeInit() API: Allows deinitializing the HAL CRC driver by resetting:

    • The global CRC configuration to the default one (default register values)

    • The independent data register to the default value

    • The handle global state to the HAL_CRC_STATE_RESET

Functions

hal_status_t HAL_CRC_Init ( hal_crc_handle_t * hcrc , hal_crc_t instance )

Initialize the CRC according to the associated instance.

Note

The user can choose to activate the CRC clock within the HAL_CRC_Init() function by setting the USE_HAL_CRC_CLK_ENABLE_MODEL flag to HAL_CLK_ENABLE_PERIPH_ONLY in the configuration file stm32c5xx_hal_conf.h

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • instancehal_crc_t enumerated type variable to be set according to the physical instance

Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the CRC handle is NULL

  • HAL_OK – The HAL CRC driver is initialized according to the given handle and instance

void HAL_CRC_DeInit ( hal_crc_handle_t * hcrc )

Deinitialize the CRC peripheral.

Parameters :

hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

Configuration functions

group CRC_Exported_Functions_Group2

This subsection provides a set of functions to configure the CRC peripheral:

There are two categories of HAL configuration APIs.

Each configuration API must first check the IDLE state (meaning HAL_CRC_Init() has been performed)

Functions

hal_status_t HAL_CRC_SetConfig ( hal_crc_handle_t * hcrc , const hal_crc_config_t * p_config )

Configure the CRC according to the user parameters.

Warning

The Polynomial size must be aligned to the configured output reverse mode (ex when output reverse mode is set to HAL_CRC_OUTDATA_REVERSE_HALFWORD_BYWORD, the provided Polynomial size must be a word)

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • p_config – Pointer to a hal_crc_config_t structure that contains the CRC configuration

Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when:

    • The configuration structure pointer is NULL

    • Or the provided polynomial is invalid (Even polynomial or polynomial size and coefficient are incoherent)

  • HAL_OK – CRC peripheral is correctly configured

void HAL_CRC_GetConfig ( const hal_crc_handle_t * hcrc , hal_crc_config_t * p_config )

Retrieve the CRC configuration.

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • p_config – Pointer to a hal_crc_config_t retrieved structure configuration

void HAL_CRC_ResetConfig ( hal_crc_handle_t * hcrc )

This function allows resetting a set of 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

Parameters :

hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

hal_status_t HAL_CRC_SetConfigPolynomial ( hal_crc_handle_t * hcrc , uint32_t poly_coefficient , hal_crc_polynomial_size_t poly_size , uint32_t crc_init_value )

Configure the CRC polynomial (polynomial size, polynomial coefficient, CRC init value).

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • poly_coefficient – A uint32_t CRC Polynomial coefficient that must be odd and coherent with the poly_size

  • poly_size – CRC Polynomial size with a hal_crc_polynomial_size_t type and a value within:

    • HAL_CRC_POLY_SIZE_32B

    • HAL_CRC_POLY_SIZE_16B

    • HAL_CRC_POLY_SIZE_8B

    • HAL_CRC_POLY_SIZE_7B

  • crc_init_value – A uint32_t initial CRC value

Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the provided polynomial is invalid (Even polynomial or polynomial size and coefficient are incoherent or polynomial size and output reverse mode are incoherent)

  • HAL_OK – CRC polynomial is correctly configured

hal_status_t HAL_CRC_SetInputReverseMode ( hal_crc_handle_t * hcrc , hal_crc_input_data_reverse_mode_t input_reverse_mode )

Configure the CRC Input reversibility mode.

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • input_reverse_mode – CRC input reversibility mode with a hal_crc_input_data_reverse_mode_t type and a value within:

    • HAL_CRC_INDATA_REVERSE_NONE

    • HAL_CRC_INDATA_REVERSE_BYTE

    • HAL_CRC_INDATA_REVERSE_HALFWORD

    • HAL_CRC_INDATA_REVERSE_WORD

    • HAL_CRC_INDATA_REVERSE_HALFWORD_BYWORD

    • HAL_CRC_INDATA_REVERSE_BYTE_BYWORD

Return values :

HAL_OK – CRC input reverse mode is correctly configured

hal_crc_input_data_reverse_mode_t HAL_CRC_GetInputReverseMode ( const hal_crc_handle_t * hcrc )

Retrieve the CRC configured input reversibility mode.

Parameters :

hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

Return values :
  • HAL_CRC_INDATA_REVERSE_NONE – The bit order of the input data is not affected

  • HAL_CRC_INDATA_REVERSE_BYTE – The bit reversal is done by byte. Example: 0x1A2B3C4D becomes 0x58D43CB2

  • HAL_CRC_INDATA_REVERSE_HALFWORD – The bit reversal is done by half word Ex: 0x1A2B3C4D becomes 0xD458B23C

  • HAL_CRC_INDATA_REVERSE_WORD – The bit-reversal is done on the full word Ex: 0x1A2B3C4D becomes 0xB23CD458

  • HAL_CRC_INDATA_REVERSE_HALFWORD_BYWORD – The bit reversal is done by half word by word Ex: 0x1A2B3C4D becomes 0x3C4D1A2B

  • HAL_CRC_INDATA_REVERSE_BYTE_BYWORD – The bit reversal is done by byte by word Ex: 0x1A2B3C4D becomes 0x4D3C2B1A

hal_status_t HAL_CRC_SetOutputReverseMode ( hal_crc_handle_t * hcrc , hal_crc_output_data_reverse_mode_t output_reverse_mode )

Configure the CRC Output reversibility mode.

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • output_reverse_mode – CRC output reversibility mode with a hal_crc_output_data_reverse_mode_t type and a value within:

    • HAL_CRC_OUTDATA_REVERSE_NONE

    • HAL_CRC_OUTDATA_REVERSE_BIT

    • HAL_CRC_OUTDATA_REVERSE_HALFWORD_BYWORD

    • HAL_CRC_OUTDATA_REVERSE_BYTE_BYWORD

Return values :
  • HAL_INVALID_PARAM – Invalid parameter return when the provided output reverse mode is invalid (output reverse mode and polynomial size are incoherent)

  • HAL_OK – CRC output reverse mode is correctly configured

hal_crc_output_data_reverse_mode_t HAL_CRC_GetOutputReverseMode ( const hal_crc_handle_t * hcrc )

Retrieve the CRC configured output reversibility mode.

Parameters :

hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

Return values :
  • HAL_CRC_OUTDATA_REVERSE_NONE – The bit order of the output data is not affected

  • HAL_CRC_OUTDATA_REVERSE_BIT – The bit-reversal of the output data is done by byte

  • HAL_CRC_OUTDATA_REVERSE_HALFWORD_BYWORD – The reversibility is done half word by word

  • HAL_CRC_OUTDATA_REVERSE_BYTE_BYWORD – The reversibility is done byte by word

hal_status_t HAL_CRC_SetIndependentData ( hal_crc_handle_t * hcrc , uint32_t independent_data )

Store user data in the Independent Data register.

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • independent_data – A uint32_t user data to be stored in the Independent data register

Return values :

HAL_OK – User independent data is correctly configured

uint32_t HAL_CRC_GetIndependentData ( const hal_crc_handle_t * hcrc )

Return the data stored in the Independent Data register.

Parameters :

hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

Return values :

Auint32_t retrieved user data from the Independent data register

Peripheral Control functions

group CRC_Exported_Functions_Group3

This subsection provides two CRC calculation functions:

  • HAL_CRC_Calculate() API: This function allows the user to calculate the CRC of an input data buffer starting with the configured CRC init value

  • HAL_CRC_Accumulate() API: This function allows the user to calculate the CRC of an input data buffer starting with the previously computed CRC as the initialization value

Functions

hal_status_t HAL_CRC_Calculate ( hal_crc_handle_t * hcrc , const void * p_data , uint32_t size_byte , uint32_t * p_crc_result )

Compute the 7, 8, 16, or 32-bit CRC value of a user data buffer starting with hcrc->Instance->INIT as initialization value.

Warning

The data size must be aligned to the configured input reverse mode (ex when input reverse mode is set to HAL_CRC_INDATA_REVERSE_WORD, the provided data size must be a multiple of words)

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • p_data – Pointer to const void data buffer provided by the user (buffer of bytes, halfwords or words)

  • size_byte – A uint32_t input data buffer length (number of bytes)

  • p_crc_result – A uint32_t Calculated CRC with a size aligned with the used polynomial one

Return values :
  • HAL_INVALID_PARAM – Invalid param return when the provided data buffer pointer is null or when this buffer is empty

  • HAL_BUSY – Another calculation process is ongoing

  • HAL_OK – The CRC is successfully calculated

hal_status_t HAL_CRC_Accumulate ( hal_crc_handle_t * hcrc , const void * p_data , uint32_t size_byte , uint32_t * p_crc_result )

Compute the 7, 8, 16, or 32-bit CRC value of a user data buffer starting with the previously computed CRC as the initialization value.

Note

The HAL_CRC_Accumulate() function must not be applied when the input reverse mode’s granularity is higher than the number of bytes already calculated

Warning

The data size must be aligned to the configured input reverse mode (ex when input reverse mode is set to HAL_CRC_INDATA_REVERSE_WORD, the provided data size must be a multiple of words)

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

  • p_data – Pointer to const void data buffer provided by the user (buffer of bytes, halfwords or words)

  • size_byte – A uint32_t input data buffer length (number of bytes)

  • p_crc_result – A uint32_t Calculated CRC with a size aligned with the used polynomial one

Return values :
  • HAL_INVALID_PARAM – Invalid param return when the provided data buffer pointer is null or when this buffer is empty

  • HAL_BUSY – Another calculation process is ongoing

  • HAL_OK – The CRC is successfully calculated

Peripheral State functions

group CRC_Exported_Functions_Group4

This subsection provides a HAL_CRC_GetState() function to retrieve the CRC peripheral global state

Functions

hal_crc_state_t HAL_CRC_GetState ( const hal_crc_handle_t * hcrc )

Retrieve the HAL CRC Global State.

Parameters :

hcrc – Pointer to a hal_crc_handle_t structure that is the object maintaining the specified CRC HAL context

Return values :
  • HAL_CRC_STATE_RESET – CRC peripheral is de-initialized

  • HAL_CRC_STATE_IDLE – CRC peripheral is initialized and configured

  • HAL_CRC_STATE_ACTIVE – CRC calculation is ongoing

User data functions

group CRC_Exported_Functions_Group5

This subsection provides a set of functions to get and set user data:

Functions

void HAL_CRC_SetUserData ( hal_crc_handle_t * hcrc , const void * p_user_data )

Store application user data pointer into the handle.

Parameters :
  • hcrc – Pointer to a hal_crc_handle_t structure

  • p_user_data – Pointer to the user data

const void * HAL_CRC_GetUserData ( const hal_crc_handle_t * hcrc )

Retrieve the application user data pointer from the handle.

Parameters :

hcrc – Pointer to a hal_crc_handle_t structure

Return values :

Pointer – to the user data