crc.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file crc.c
  5. * @brief This file provides code for the configuration
  6. * of the CRC instances.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2025 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. #include "stdio.h"
  20. /* USER CODE END Header */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "crc.h"
  23. /* USER CODE BEGIN 0 */
  24. /* USER CODE END 0 */
  25. CRC_HandleTypeDef hcrc;
  26. /* CRC init function */
  27. void MX_CRC_Init(void)
  28. {
  29. /* USER CODE BEGIN CRC_Init 0 */
  30. /* USER CODE END CRC_Init 0 */
  31. /* USER CODE BEGIN CRC_Init 1 */
  32. /* USER CODE END CRC_Init 1 */
  33. hcrc.Instance = CRC;
  34. hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;
  35. hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE;
  36. hcrc.Init.GeneratingPolynomial = 32773;
  37. hcrc.Init.CRCLength = CRC_POLYLENGTH_16B;
  38. hcrc.Init.InitValue = 0xFFFF;
  39. hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_BYTE;
  40. hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_ENABLE;
  41. hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
  42. if (HAL_CRC_Init(&hcrc) != HAL_OK)
  43. {
  44. Error_Handler();
  45. }
  46. /* USER CODE BEGIN CRC_Init 2 */
  47. /* USER CODE END CRC_Init 2 */
  48. }
  49. void HAL_CRC_MspInit(CRC_HandleTypeDef* crcHandle)
  50. {
  51. if(crcHandle->Instance==CRC)
  52. {
  53. /* USER CODE BEGIN CRC_MspInit 0 */
  54. /* USER CODE END CRC_MspInit 0 */
  55. /* CRC clock enable */
  56. __HAL_RCC_CRC_CLK_ENABLE();
  57. /* USER CODE BEGIN CRC_MspInit 1 */
  58. /* USER CODE END CRC_MspInit 1 */
  59. }
  60. }
  61. void HAL_CRC_MspDeInit(CRC_HandleTypeDef* crcHandle)
  62. {
  63. if(crcHandle->Instance==CRC)
  64. {
  65. /* USER CODE BEGIN CRC_MspDeInit 0 */
  66. /* USER CODE END CRC_MspDeInit 0 */
  67. /* Peripheral clock disable */
  68. __HAL_RCC_CRC_CLK_DISABLE();
  69. /* USER CODE BEGIN CRC_MspDeInit 1 */
  70. /* USER CODE END CRC_MspDeInit 1 */
  71. }
  72. }
  73. /* USER CODE BEGIN 1 */
  74. uint16_t mb_crc16(const uint8_t *buf, uint32_t len)
  75. {
  76. return HAL_CRC_Calculate(&hcrc, (uint32_t*)buf, len);
  77. }
  78. /* USER CODE END 1 */