STM32L4xx_HAL_Driver  1.14.0
CRC Private Functions

Functions

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. More...
 
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. More...
 

Detailed Description

Function Documentation

◆ CRC_Handle_16()

static uint32_t CRC_Handle_16 ( CRC_HandleTypeDef hcrc,
uint16_t  pBuffer[],
uint32_t  BufferLength 
)
static

Enter 16-bit input data to the CRC calculator. Specific data handling to optimize processing time.

Parameters
hcrcCRC handle
pBufferpointer to the input data buffer
BufferLengthinput data buffer length
Return values
uint32_tCRC (returned value LSBs for CRC shorter than 32 bits)

Definition at line 483 of file stm32l4xx_hal_crc.c.

484 {
485  uint32_t i; /* input data buffer index */
486  __IO uint16_t *pReg;
487 
488  /* Processing time optimization: 2 HalfWords are entered in a row with a single word write,
489  * in case of odd length, last HalfWord must be carefully fed to the CRC calculator to ensure
490  * a correct type handling by the peripheral */
491  for (i = 0U; i < (BufferLength / 2U); i++)
492  {
493  hcrc->Instance->DR = ((uint32_t)pBuffer[2U * i] << 16U) | (uint32_t)pBuffer[(2U * i) + 1U];
494  }
495  if ((BufferLength % 2U) != 0U)
496  {
497  pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
498  *pReg = pBuffer[2U * i];
499  }
500 
501  /* Return the CRC computed value */
502  return hcrc->Instance->DR;
503 }
CRC_TypeDef * Instance

◆ CRC_Handle_8()

static uint32_t CRC_Handle_8 ( CRC_HandleTypeDef hcrc,
uint8_t  pBuffer[],
uint32_t  BufferLength 
)
static

Enter 8-bit input data to the CRC calculator. Specific data handling to optimize processing time.

Parameters
hcrcCRC handle
pBufferpointer to the input data buffer
BufferLengthinput data buffer length
Return values
uint32_tCRC (returned value LSBs for CRC shorter than 32 bits)

Definition at line 432 of file stm32l4xx_hal_crc.c.

433 {
434  uint32_t i; /* input data buffer index */
435  uint16_t data;
436  __IO uint16_t *pReg;
437 
438  /* Processing time optimization: 4 bytes are entered in a row with a single word write,
439  * last bytes must be carefully fed to the CRC calculator to ensure a correct type
440  * handling by the peripheral */
441  for (i = 0U; i < (BufferLength / 4U); i++)
442  {
443  hcrc->Instance->DR = ((uint32_t)pBuffer[4U * i] << 24U) | \
444  ((uint32_t)pBuffer[(4U * i) + 1U] << 16U) | \
445  ((uint32_t)pBuffer[(4U * i) + 2U] << 8U) | \
446  (uint32_t)pBuffer[(4U * i) + 3U];
447  }
448  /* last bytes specific handling */
449  if ((BufferLength % 4U) != 0U)
450  {
451  if ((BufferLength % 4U) == 1U)
452  {
453  *(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[4U * i]; /* Derogation MisraC2012 R.11.5 */
454  }
455  if ((BufferLength % 4U) == 2U)
456  {
457  data = ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U];
458  pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
459  *pReg = data;
460  }
461  if ((BufferLength % 4U) == 3U)
462  {
463  data = ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U];
464  pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR); /* Derogation MisraC2012 R.11.5 */
465  *pReg = data;
466 
467  *(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[(4U * i) + 2U]; /* Derogation MisraC2012 R.11.5 */
468  }
469  }
470 
471  /* Return the CRC computed value */
472  return hcrc->Instance->DR;
473 }
CRC_TypeDef * Instance