Search code examples
cembeddedstm32crc

CRC_POLYLENGTH_16B undeclared in STM32F030CCTx


In STM32F030CCTx I need to set the CRC in 16-bit length by calling

HAL_CRCEx_Polynomial_Set(MATRIX_UART_settings->crc, CRC_POLY, CRC_POLYLENGTH_16B);

but the compiler shows the error :

'CRC_POLYLENGTH_16B' undeclared (first use in this function)

in the stm32f0xx_hal_crc.h file CRC_POLYLENGTH_16B is defined under preprocessor directive like

#if defined(CRC_POL_POL)
/** @defgroup CRC_Polynomial_Sizes Polynomial sizes to configure the peripheral
  * @{
  */
#define CRC_POLYLENGTH_32B                  0x00000000U        /*!< Resort to a 32-bit long generating polynomial */
#define CRC_POLYLENGTH_16B                  CRC_CR_POLYSIZE_0  /*!< Resort to a 16-bit long generating polynomial */
#define CRC_POLYLENGTH_8B                   CRC_CR_POLYSIZE_1  /*!< Resort to a 8-bit long generating polynomial  */
#define CRC_POLYLENGTH_7B                   CRC_CR_POLYSIZE    /*!< Resort to a 7-bit long generating polynomial  */
/**
  * @}
  */

/** @defgroup CRC_Polynomial_Size_Definitions CRC polynomial possible sizes actual definitions
  * @{
  */
#define HAL_CRC_LENGTH_32B     32U          /*!< 32-bit long CRC */
#define HAL_CRC_LENGTH_16B     16U          /*!< 16-bit long CRC */
#define HAL_CRC_LENGTH_8B       8U          /*!< 8-bit long CRC  */
#define HAL_CRC_LENGTH_7B       7U          /*!< 7-bit long CRC  */
/**
  * @}
  */
#endif /* CRC_POL_POL */

How can I access the CRC_POLYLENGTH_16B? and any documentation for using the HAL CRC library?


Solution

  • The STM32F0x0 CRC module has a fixed polynomial (i.e. you can't change the polynomial nor its length), see RM0360, CRC chapter. That's why you don't have defined the above symbol in (it's conditionally defined only if CRC_POL_POL is defined, and that's not defined for the 'F0x0 as it does not have the CRC_POL register for variable polynomial).

    You may argue that in fact the 'F030CC does have the CRC_POL register and does calculate the 16-bit CRC. Yes, it does, but officially it's not there, so it may happen that future revisions of that chip won't have that facility.

    And, as it's officially not there, Cube won't provide symbols needed to use it.

    The relevant Cube/HAL documentation is UM1785 chapter 13 HAL CRC Generic Driver, but I don't think you will find the above detail mentioned there.