/** * @brief Computes the 32-bit CRC of 32-bit data buffer independently * of the previous CRC value. * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains * the configuration information for CRC * @param pBuffer: Pointer to the buffer containing the data to be computed * @param BufferLength: Length of the buffer to be computed * @retval 32-bit CRC */ uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength) { uint32_t index = 0; /* Process Locked */ __HAL_LOCK(hcrc); /* Change CRC peripheral state */ hcrc->State = HAL_CRC_STATE_BUSY; /* Reset CRC Calculation Unit */ __HAL_CRC_DR_RESET(hcrc); /* Enter Data to the CRC calculator */ for(index = 0; index < BufferLength; index++) { hcrc->Instance->DR = pBuffer[index]; } /* Change CRC peripheral state */ hcrc->State = HAL_CRC_STATE_READY; /* Process Unlocked */ __HAL_UNLOCK(hcrc); /* Return the CRC computed value */ return hcrc->Instance->DR; }
/** * @brief DeInitializes the CRC peripheral. * @param hcrc: CRC handle * @retval HAL status */ HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc) { /* Check the CRC handle allocation */ if(hcrc == NULL) { return HAL_ERROR; } /* Check the parameters */ assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance)); /* Check the CRC peripheral state */ if(hcrc->State == HAL_CRC_STATE_BUSY) { return HAL_BUSY; } /* Change CRC peripheral state */ hcrc->State = HAL_CRC_STATE_BUSY; /* Reset CRC calculation unit */ __HAL_CRC_DR_RESET(hcrc); /* DeInit the low level hardware */ HAL_CRC_MspDeInit(hcrc); /* Change CRC peripheral state */ hcrc->State = HAL_CRC_STATE_RESET; /* Process unlocked */ __HAL_UNLOCK(hcrc); /* Return function status */ return HAL_OK; }
/** * @brief 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. * @param hcrc: CRC handle * @param pBuffer: pointer to the input data buffer, exact input data format is * provided by hcrc->InputDataFormat. * @param BufferLength: input data buffer length * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits) */ uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength) { uint32_t index = 0; /* CRC input data buffer index */ uint32_t temp = 0; /* CRC output (read from hcrc->Instance->DR register) */ /* Process locked */ __HAL_LOCK(hcrc); /* Change CRC peripheral state */ hcrc->State = HAL_CRC_STATE_BUSY; /* Reset CRC Calculation Unit (hcrc->Instance->INIT is * written in hcrc->Instance->DR) */ __HAL_CRC_DR_RESET(hcrc); switch (hcrc->InputDataFormat) { case CRC_INPUTDATA_FORMAT_WORDS: /* Enter 32-bit input data to the CRC calculator */ for(index = 0; index < BufferLength; index++) { hcrc->Instance->DR = pBuffer[index]; } temp = hcrc->Instance->DR; break; case CRC_INPUTDATA_FORMAT_BYTES: /* Specific 8-bit input data handling */ temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength); break; case CRC_INPUTDATA_FORMAT_HALFWORDS: /* Specific 16-bit input data handling */ temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength); break; default: break; } /* Change CRC peripheral state */ hcrc->State = HAL_CRC_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcrc); /* Return the CRC computed value */ return temp; }