STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_crc_ex.c
Go to the documentation of this file.
1 
32 /* Includes ------------------------------------------------------------------*/
33 #include "stm32l4xx_hal.h"
34 
44 #ifdef HAL_CRC_MODULE_ENABLED
45 
46 /* Private typedef -----------------------------------------------------------*/
47 /* Private define ------------------------------------------------------------*/
48 /* Private macro -------------------------------------------------------------*/
49 /* Private variables ---------------------------------------------------------*/
50 /* Private function prototypes -----------------------------------------------*/
51 /* Exported functions --------------------------------------------------------*/
52 
89 HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength)
90 {
91  HAL_StatusTypeDef status = HAL_OK;
92  uint32_t msb = 31U; /* polynomial degree is 32 at most, so msb is initialized to max value */
93 
94  /* Check the parameters */
95  assert_param(IS_CRC_POL_LENGTH(PolyLength));
96 
97  /* check polynomial definition vs polynomial size:
98  * polynomial length must be aligned with polynomial
99  * definition. HAL_ERROR is reported if Pol degree is
100  * larger than that indicated by PolyLength.
101  * Look for MSB position: msb will contain the degree of
102  * the second to the largest polynomial member. E.g., for
103  * X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */
104  while ((msb-- > 0U) && ((Pol & ((uint32_t)(0x1U) << (msb & 0x1FU))) == 0U))
105  {
106  }
107 
108  switch (PolyLength)
109  {
110  case CRC_POLYLENGTH_7B:
111  if (msb >= HAL_CRC_LENGTH_7B)
112  {
113  status = HAL_ERROR;
114  }
115  break;
116  case CRC_POLYLENGTH_8B:
117  if (msb >= HAL_CRC_LENGTH_8B)
118  {
119  status = HAL_ERROR;
120  }
121  break;
122  case CRC_POLYLENGTH_16B:
123  if (msb >= HAL_CRC_LENGTH_16B)
124  {
125  status = HAL_ERROR;
126  }
127  break;
128 
129  case CRC_POLYLENGTH_32B:
130  /* no polynomial definition vs. polynomial length issue possible */
131  break;
132  default:
133  status = HAL_ERROR;
134  break;
135  }
136  if (status == HAL_OK)
137  {
138  /* set generating polynomial */
139  WRITE_REG(hcrc->Instance->POL, Pol);
140 
141  /* set generating polynomial size */
142  MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, PolyLength);
143  }
144  /* Return function status */
145  return status;
146 }
147 
159 HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode)
160 {
161  /* Check the parameters */
162  assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(InputReverseMode));
163 
164  /* Change CRC peripheral state */
165  hcrc->State = HAL_CRC_STATE_BUSY;
166 
167  /* set input data inversion mode */
168  MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, InputReverseMode);
169  /* Change CRC peripheral state */
170  hcrc->State = HAL_CRC_STATE_READY;
171 
172  /* Return function status */
173  return HAL_OK;
174 }
175 
185 HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode)
186 {
187  /* Check the parameters */
188  assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(OutputReverseMode));
189 
190  /* Change CRC peripheral state */
191  hcrc->State = HAL_CRC_STATE_BUSY;
192 
193  /* set output data inversion mode */
194  MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, OutputReverseMode);
195 
196  /* Change CRC peripheral state */
197  hcrc->State = HAL_CRC_STATE_READY;
198 
199  /* Return function status */
200  return HAL_OK;
201 }
202 
203 
204 
205 
216 #endif /* HAL_CRC_MODULE_ENABLED */
217 
225 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
This file contains all the functions prototypes for the HAL module driver.
__IO HAL_CRC_StateTypeDef State
return HAL_OK
HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength)
Initialize the CRC polynomial if different from default one.
CRC_TypeDef * Instance
CRC Handle Structure definition.
HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode)
Set the Reverse Input data mode.
HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode)
Set the Reverse Output data mode.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))