crc.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. ******************************************************************************
  3. * File Name : CRC.c
  4. * Description : This file provides code for the configuration
  5. * of the CRC instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "crc.h"
  21. /* USER CODE BEGIN 0 */
  22. /* USER CODE END 0 */
  23. CRC_HandleTypeDef hcrc;
  24. /* CRC init function */
  25. void MX_CRC_Init(void)
  26. {
  27. hcrc.Instance = CRC;
  28. if (HAL_CRC_Init(&hcrc) != HAL_OK)
  29. {
  30. Error_Handler();
  31. }
  32. }
  33. void HAL_CRC_MspInit(CRC_HandleTypeDef* crcHandle)
  34. {
  35. if(crcHandle->Instance==CRC)
  36. {
  37. /* USER CODE BEGIN CRC_MspInit 0 */
  38. /* USER CODE END CRC_MspInit 0 */
  39. /* CRC clock enable */
  40. __HAL_RCC_CRC_CLK_ENABLE();
  41. /* USER CODE BEGIN CRC_MspInit 1 */
  42. /* USER CODE END CRC_MspInit 1 */
  43. }
  44. }
  45. void HAL_CRC_MspDeInit(CRC_HandleTypeDef* crcHandle)
  46. {
  47. if(crcHandle->Instance==CRC)
  48. {
  49. /* USER CODE BEGIN CRC_MspDeInit 0 */
  50. /* USER CODE END CRC_MspDeInit 0 */
  51. /* Peripheral clock disable */
  52. __HAL_RCC_CRC_CLK_DISABLE();
  53. /* USER CODE BEGIN CRC_MspDeInit 1 */
  54. /* USER CODE END CRC_MspDeInit 1 */
  55. }
  56. }
  57. /* USER CODE BEGIN 1 */
  58. uint32_t crc32(uint8_t const * p_data, uint8_t size)
  59. {
  60. uint32_t crc;
  61. crc = 0xFFFFFFFF;
  62. for (uint32_t i = 0; i < size; i++)
  63. {
  64. if( (i<0x22) || (i>0x2f))
  65. {
  66. crc = crc ^ p_data[i];
  67. for (uint32_t j = 8; j > 0; j--)
  68. {
  69. crc = (crc >> 1) ^ (0xEDB88320U & ((crc & 1) ? 0xFFFFFFFF : 0));
  70. }
  71. }
  72. }
  73. return ~crc;
  74. }
  75. /* USER CODE END 1 */
  76. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/