stm32f4xx_crc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_crc.c
  4. * @author MCD Application Team
  5. * @version V1.8.1
  6. * @date 27-January-2022
  7. * @brief This file provides all the CRC firmware functions.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * Copyright (c) 2016 STMicroelectronics.
  12. * All rights reserved.
  13. *
  14. * This software is licensed under terms that can be found in the LICENSE file
  15. * in the root directory of this software component.
  16. * If no LICENSE file comes with this software, it is provided AS-IS.
  17. *
  18. ******************************************************************************
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f4xx_crc.h"
  22. /** @addtogroup STM32F4xx_StdPeriph_Driver
  23. * @{
  24. */
  25. /** @defgroup CRC
  26. * @brief CRC driver modules
  27. * @{
  28. */
  29. /* Private typedef -----------------------------------------------------------*/
  30. /* Private define ------------------------------------------------------------*/
  31. /* Private macro -------------------------------------------------------------*/
  32. /* Private variables ---------------------------------------------------------*/
  33. /* Private function prototypes -----------------------------------------------*/
  34. /* Private functions ---------------------------------------------------------*/
  35. /** @defgroup CRC_Private_Functions
  36. * @{
  37. */
  38. /**
  39. * @brief Resets the CRC Data register (DR).
  40. * @param None
  41. * @retval None
  42. */
  43. void CRC_ResetDR(void)
  44. {
  45. /* Reset CRC generator */
  46. CRC->CR = CRC_CR_RESET;
  47. }
  48. /**
  49. * @brief Computes the 32-bit CRC of a given data word(32-bit).
  50. * @param Data: data word(32-bit) to compute its CRC
  51. * @retval 32-bit CRC
  52. */
  53. uint32_t CRC_CalcCRC(uint32_t Data)
  54. {
  55. CRC->DR = Data;
  56. return (CRC->DR);
  57. }
  58. /**
  59. * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
  60. * @param pBuffer: pointer to the buffer containing the data to be computed
  61. * @param BufferLength: length of the buffer to be computed
  62. * @retval 32-bit CRC
  63. */
  64. uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
  65. {
  66. uint32_t index = 0;
  67. for(index = 0; index < BufferLength; index++)
  68. {
  69. CRC->DR = pBuffer[index];
  70. }
  71. return (CRC->DR);
  72. }
  73. /**
  74. * @brief Returns the current CRC value.
  75. * @param None
  76. * @retval 32-bit CRC
  77. */
  78. uint32_t CRC_GetCRC(void)
  79. {
  80. return (CRC->DR);
  81. }
  82. /**
  83. * @brief Stores a 8-bit data in the Independent Data(ID) register.
  84. * @param IDValue: 8-bit value to be stored in the ID register
  85. * @retval None
  86. */
  87. void CRC_SetIDRegister(uint8_t IDValue)
  88. {
  89. CRC->IDR = IDValue;
  90. }
  91. /**
  92. * @brief Returns the 8-bit data stored in the Independent Data(ID) register
  93. * @param None
  94. * @retval 8-bit value of the ID register
  95. */
  96. uint8_t CRC_GetIDRegister(void)
  97. {
  98. return (CRC->IDR);
  99. }
  100. /**
  101. * @}
  102. */
  103. /**
  104. * @}
  105. */
  106. /**
  107. * @}
  108. */