STM32L4xx_HAL_Driver  1.14.0
Peripheral Control functions

management functions. More...

Functions

uint32_t HAL_CRC_Accumulate (CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
 Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer starting with the previously computed CRC as initialization value. More...
 
uint32_t HAL_CRC_Calculate (CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
 Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer starting with hcrc->Instance->INIT as initialization value. More...
 

Detailed Description

management functions.

 ===============================================================================
                      ##### Peripheral Control functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
          using combination of the previous CRC value and the new one.

       [..]  or

      (+) compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
          independently of the previous CRC value.

Function Documentation

◆ HAL_CRC_Accumulate()

uint32_t HAL_CRC_Accumulate ( CRC_HandleTypeDef hcrc,
uint32_t  pBuffer[],
uint32_t  BufferLength 
)

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

Parameters
hcrcCRC handle
pBufferpointer to the input data buffer, exact input data format is provided by hcrc->InputDataFormat.
BufferLengthinput data buffer length (number of bytes if pBuffer type is * uint8_t, number of half-words if pBuffer type is * uint16_t, number of words if pBuffer type is * uint32_t).
Note
By default, the API expects a uint32_t pointer as input buffer parameter. Input buffer pointers with other types simply need to be cast in uint32_t and the API will internally adjust its input data processing based on the handle field hcrc->InputDataFormat.
Return values
uint32_tCRC (returned value LSBs for CRC shorter than 32 bits)

Definition at line 287 of file stm32l4xx_hal_crc.c.

288 {
289  uint32_t index; /* CRC input data buffer index */
290  uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
291 
292  /* Change CRC peripheral state */
293  hcrc->State = HAL_CRC_STATE_BUSY;
294 
295  switch (hcrc->InputDataFormat)
296  {
297  case CRC_INPUTDATA_FORMAT_WORDS:
298  /* Enter Data to the CRC calculator */
299  for (index = 0U; index < BufferLength; index++)
300  {
301  hcrc->Instance->DR = pBuffer[index];
302  }
303  temp = hcrc->Instance->DR;
304  break;
305 
306  case CRC_INPUTDATA_FORMAT_BYTES:
307  temp = CRC_Handle_8(hcrc, (uint8_t *)pBuffer, BufferLength);
308  break;
309 
310  case CRC_INPUTDATA_FORMAT_HALFWORDS:
311  temp = CRC_Handle_16(hcrc, (uint16_t *)(void *)pBuffer, BufferLength); /* Derogation MisraC2012 R.11.5 */
312  break;
313  default:
314  break;
315  }
316 
317  /* Change CRC peripheral state */
318  hcrc->State = HAL_CRC_STATE_READY;
319 
320  /* Return the CRC computed value */
321  return temp;
322 }
static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)
Enter 8-bit input data to the CRC calculator. Specific data handling to optimize processing time...
__IO HAL_CRC_StateTypeDef State
static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength)
Enter 16-bit input data to the CRC calculator. Specific data handling to optimize processing time...
CRC_TypeDef * Instance

◆ HAL_CRC_Calculate()

uint32_t HAL_CRC_Calculate ( CRC_HandleTypeDef hcrc,
uint32_t  pBuffer[],
uint32_t  BufferLength 
)

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

Parameters
hcrcCRC handle
pBufferpointer to the input data buffer, exact input data format is provided by hcrc->InputDataFormat.
BufferLengthinput data buffer length (number of bytes if pBuffer type is * uint8_t, number of half-words if pBuffer type is * uint16_t, number of words if pBuffer type is * uint32_t).
Note
By default, the API expects a uint32_t pointer as input buffer parameter. Input buffer pointers with other types simply need to be cast in uint32_t and the API will internally adjust its input data processing based on the handle field hcrc->InputDataFormat.
Return values
uint32_tCRC (returned value LSBs for CRC shorter than 32 bits)

Definition at line 339 of file stm32l4xx_hal_crc.c.

340 {
341  uint32_t index; /* CRC input data buffer index */
342  uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
343 
344  /* Change CRC peripheral state */
345  hcrc->State = HAL_CRC_STATE_BUSY;
346 
347  /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
348  * written in hcrc->Instance->DR) */
349  __HAL_CRC_DR_RESET(hcrc);
350 
351  switch (hcrc->InputDataFormat)
352  {
353  case CRC_INPUTDATA_FORMAT_WORDS:
354  /* Enter 32-bit input data to the CRC calculator */
355  for (index = 0U; index < BufferLength; index++)
356  {
357  hcrc->Instance->DR = pBuffer[index];
358  }
359  temp = hcrc->Instance->DR;
360  break;
361 
362  case CRC_INPUTDATA_FORMAT_BYTES:
363  /* Specific 8-bit input data handling */
364  temp = CRC_Handle_8(hcrc, (uint8_t *)pBuffer, BufferLength);
365  break;
366 
367  case CRC_INPUTDATA_FORMAT_HALFWORDS:
368  /* Specific 16-bit input data handling */
369  temp = CRC_Handle_16(hcrc, (uint16_t *)(void *)pBuffer, BufferLength); /* Derogation MisraC2012 R.11.5 */
370  break;
371 
372  default:
373  break;
374  }
375 
376  /* Change CRC peripheral state */
377  hcrc->State = HAL_CRC_STATE_READY;
378 
379  /* Return the CRC computed value */
380  return temp;
381 }
static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)
Enter 8-bit input data to the CRC calculator. Specific data handling to optimize processing time...
__IO HAL_CRC_StateTypeDef State
static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength)
Enter 16-bit input data to the CRC calculator. Specific data handling to optimize processing time...
CRC_TypeDef * Instance