stm32h7xx_hal_crc.c
Go to the documentation of this file.
1 
45 /* Includes ------------------------------------------------------------------*/
46 #include "stm32h7xx_hal.h"
47 
57 #ifdef HAL_CRC_MODULE_ENABLED
58 
59 /* Private typedef -----------------------------------------------------------*/
60 /* Private define ------------------------------------------------------------*/
61 /* Private macro -------------------------------------------------------------*/
62 /* Private variables ---------------------------------------------------------*/
63 /* Private function prototypes -----------------------------------------------*/
67 static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength);
68 static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength);
73 /* Exported functions --------------------------------------------------------*/
74 
104 {
105  /* Check the CRC handle allocation */
106  if (hcrc == NULL)
107  {
108  return HAL_ERROR;
109  }
110 
111  /* Check the parameters */
113 
115  {
116  /* Allocate lock resource and initialize it */
118  /* Init the low level hardware */
120  }
121 
123 
124  /* check whether or not non-default generating polynomial has been
125  * picked up by user */
128  {
129  /* initialize peripheral with default generating polynomial */
132  }
133  else
134  {
135  /* initialize CRC peripheral with generating polynomial defined by user */
137  {
138  return HAL_ERROR;
139  }
140  }
141 
142  /* check whether or not non-default CRC initial value has been
143  * picked up by user */
146  {
148  }
149  else
150  {
152  }
153 
154 
155  /* set input data inversion mode */
158 
159  /* set output data inversion mode */
162 
163  /* makes sure the input data format (bytes, halfwords or words stream)
164  * is properly specified by user */
166 
167  /* Change CRC peripheral state */
169 
170  /* Return function status */
171  return HAL_OK;
172 }
173 
180 {
181  /* Check the CRC handle allocation */
182  if (hcrc == NULL)
183  {
184  return HAL_ERROR;
185  }
186 
187  /* Check the parameters */
189 
190  /* Check the CRC peripheral state */
191  if (hcrc->State == HAL_CRC_STATE_BUSY)
192  {
193  return HAL_BUSY;
194  }
195 
196  /* Change CRC peripheral state */
198 
199  /* Reset CRC calculation unit */
201 
202  /* Reset IDR register content */
204 
205  /* DeInit the low level hardware */
207 
208  /* Change CRC peripheral state */
210 
211  /* Process unlocked */
213 
214  /* Return function status */
215  return HAL_OK;
216 }
217 
224 {
225  /* Prevent unused argument(s) compilation warning */
226  UNUSED(hcrc);
227 
228  /* NOTE : This function should not be modified, when the callback is needed,
229  the HAL_CRC_MspInit can be implemented in the user file
230  */
231 }
232 
239 {
240  /* Prevent unused argument(s) compilation warning */
241  UNUSED(hcrc);
242 
243  /* NOTE : This function should not be modified, when the callback is needed,
244  the HAL_CRC_MspDeInit can be implemented in the user file
245  */
246 }
247 
287 uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
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 */
294 
295  switch (hcrc->InputDataFormat)
296  {
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 
307  temp = CRC_Handle_8(hcrc, (uint8_t *)pBuffer, BufferLength);
308  break;
309 
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 */
319 
320  /* Return the CRC computed value */
321  return temp;
322 }
323 
339 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
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 */
346 
347  /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
348  * written in hcrc->Instance->DR) */
350 
351  switch (hcrc->InputDataFormat)
352  {
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 
363  /* Specific 8-bit input data handling */
364  temp = CRC_Handle_8(hcrc, (uint8_t *)pBuffer, BufferLength);
365  break;
366 
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 */
378 
379  /* Return the CRC computed value */
380  return temp;
381 }
382 
407 {
408  /* Return CRC handle state */
409  return hcrc->State;
410 }
411 
432 static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)
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 }
474 
483 static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength)
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 }
504 
509 #endif /* HAL_CRC_MODULE_ENABLED */
510 
518 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
assert_param
#define assert_param(expr)
Include module's header file.
Definition: stm32f407/stm32f407g-disc1/Inc/stm32f4xx_hal_conf.h:353
CRC_InitTypeDef::InputDataInversionMode
uint32_t InputDataInversionMode
Definition: stm32h7xx_hal_crc.h:87
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
IS_DEFAULT_POLYNOMIAL
#define IS_DEFAULT_POLYNOMIAL(DEFAULT)
Definition: stm32h7xx_hal_crc.h:267
HAL_CRC_Init
HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
CRC_CR_REV_IN
#define CRC_CR_REV_IN
Definition: stm32f769xx.h:5929
IS_CRC_ALL_INSTANCE
#define IS_CRC_ALL_INSTANCE(INSTANCE)
Definition: stm32f407xx.h:15091
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
IS_DEFAULT_INIT_VALUE
#define IS_DEFAULT_INIT_VALUE(VALUE)
Definition: stm32h7xx_hal_crc.h:270
HAL_CRC_STATE_RESET
@ HAL_CRC_STATE_RESET
Definition: stm32h7xx_hal_crc.h:49
HAL_UNLOCKED
@ HAL_UNLOCKED
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:53
CRC_InitTypeDef::DefaultInitValueUse
uint8_t DefaultInitValueUse
Definition: stm32h7xx_hal_crc.h:67
DEFAULT_INIT_VALUE_ENABLE
#define DEFAULT_INIT_VALUE_ENABLE
Definition: stm32h7xx_hal_crc.h:159
DEFAULT_CRC_INITVALUE
#define DEFAULT_CRC_INITVALUE
Definition: stm32h7xx_hal_crc.h:142
DEFAULT_CRC32_POLY
#define DEFAULT_CRC32_POLY
Definition: stm32h7xx_hal_crc.h:134
DEFAULT_POLYNOMIAL_ENABLE
#define DEFAULT_POLYNOMIAL_ENABLE
Definition: stm32h7xx_hal_crc.h:150
CRC_HandleTypeDef::InputDataFormat
uint32_t InputDataFormat
Definition: stm32h7xx_hal_crc.h:113
HAL_ERROR
@ HAL_ERROR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:43
CLEAR_BIT
#define CLEAR_BIT(REG, BIT)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:214
HAL_CRC_STATE_BUSY
@ HAL_CRC_STATE_BUSY
Definition: stm32h7xx_hal_crc.h:51
CRC_INPUTDATA_FORMAT_WORDS
#define CRC_INPUTDATA_FORMAT_WORDS
Definition: stm32h7xx_hal_crc.h:197
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
CRC_CR_REV_OUT
#define CRC_CR_REV_OUT
Definition: stm32f769xx.h:5934
UNUSED
#define UNUSED(x)
Definition: porcupine/demo/c/dr_libs/old/dr.h:92
HAL_CRC_Accumulate
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
CRC_POLYLENGTH_32B
#define CRC_POLYLENGTH_32B
Definition: stm32h7xx_hal_crc.h:168
CRC_HandleTypeDef::Lock
HAL_LockTypeDef Lock
Definition: stm32h7xx_hal_crc.h:109
MODIFY_REG
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:224
CRC_TypeDef::POL
__IO uint32_t POL
Definition: stm32f769xx.h:324
CRC_HandleTypeDef::State
__IO HAL_CRC_StateTypeDef State
Definition: stm32h7xx_hal_crc.h:111
CRC_InitTypeDef::GeneratingPolynomial
uint32_t GeneratingPolynomial
Definition: stm32h7xx_hal_crc.h:72
CRC_InitTypeDef::InitValue
uint32_t InitValue
Definition: stm32h7xx_hal_crc.h:84
HAL_BUSY
@ HAL_BUSY
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:44
HAL_CRCEx_Polynomial_Set
HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength)
CRC_TypeDef::CR
__IO uint32_t CR
Definition: stm32f407xx.h:286
CRC_IDR_IDR
#define CRC_IDR_IDR
Definition: stm32f407xx.h:5428
CRC_CR_POLYSIZE
#define CRC_CR_POLYSIZE
Definition: stm32f769xx.h:5924
CRC_HandleTypeDef
CRC Handle Structure definition.
Definition: stm32h7xx_hal_crc.h:103
__HAL_UNLOCK
#define __HAL_UNLOCK(__HANDLE__)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:105
CRC_INPUTDATA_FORMAT_BYTES
#define CRC_INPUTDATA_FORMAT_BYTES
Definition: stm32h7xx_hal_crc.h:195
CRC_HandleTypeDef::Init
CRC_InitTypeDef Init
Definition: stm32h7xx_hal_crc.h:107
HAL_CRC_STATE_READY
@ HAL_CRC_STATE_READY
Definition: stm32h7xx_hal_crc.h:50
HAL_CRC_Calculate
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
CRC_InitTypeDef::CRCLength
uint32_t CRCLength
Definition: stm32h7xx_hal_crc.h:77
CRC_TypeDef::DR
__IO uint32_t DR
Definition: stm32f407xx.h:282
HAL_CRC_DeInit
HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
CRC_INPUTDATA_FORMAT_HALFWORDS
#define CRC_INPUTDATA_FORMAT_HALFWORDS
Definition: stm32h7xx_hal_crc.h:196
CRC_TypeDef::INIT
__IO uint32_t INIT
Definition: stm32f769xx.h:323
__HAL_CRC_DR_RESET
#define __HAL_CRC_DR_RESET(__HANDLE__)
Reset CRC Data Register.
Definition: stm32h7xx_hal_crc.h:231
WRITE_REG
#define WRITE_REG(REG, VAL)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:220
HAL_CRC_GetState
HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
CRC_HandleTypeDef::Instance
CRC_TypeDef * Instance
Definition: stm32h7xx_hal_crc.h:105
IS_CRC_INPUTDATA_FORMAT
#define IS_CRC_INPUTDATA_FORMAT(FORMAT)
Definition: stm32h7xx_hal_crc.h:278
IS_CRC_INPUTDATA_INVERSION_MODE
#define IS_CRC_INPUTDATA_INVERSION_MODE(MODE)
Definition: stm32h7xx_hal_crc_ex.h:105
CRC_InitTypeDef::DefaultPolynomialUse
uint8_t DefaultPolynomialUse
Definition: stm32h7xx_hal_crc.h:61
CRC_InitTypeDef::OutputDataInversionMode
uint32_t OutputDataInversionMode
Definition: stm32h7xx_hal_crc.h:94
HAL_CRC_MspInit
void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
CRC MSP Initialization This function configures the hardware resources used in this example.
Definition: stm32h7xx_hal_msp.c:86
CRC_TypeDef::IDR
__IO uint8_t IDR
Definition: stm32f407xx.h:283
IS_CRC_OUTPUTDATA_INVERSION_MODE
#define IS_CRC_OUTPUTDATA_INVERSION_MODE(MODE)
Definition: stm32h7xx_hal_crc_ex.h:110
HAL_CRC_StateTypeDef
HAL_CRC_StateTypeDef
CRC HAL State Structure definition.
Definition: stm32h7xx_hal_crc.h:47
HAL_CRC_MspDeInit
void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
CRC MSP De-Initialization This function freeze the hardware resources used in this example.
Definition: stm32h7xx_hal_msp.c:108
hcrc
CRC_HandleTypeDef hcrc
Definition: stm32h735/stm32h735g-dk/Src/pv_audio_rec.c:36


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:54