]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/ST_Library/stm32f7xx_hal_crc.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil / ST_Library / stm32f7xx_hal_crc.c
diff --git a/FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/ST_Library/stm32f7xx_hal_crc.c b/FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/ST_Library/stm32f7xx_hal_crc.c
new file mode 100644 (file)
index 0000000..dad4db2
--- /dev/null
@@ -0,0 +1,507 @@
+/**\r
+  ******************************************************************************\r
+  * @file    stm32f7xx_hal_crc.c\r
+  * @author  MCD Application Team\r
+  * @version V1.0.0RC1\r
+  * @date    24-March-2015\r
+  * @brief   CRC HAL module driver.\r
+  *          This file provides firmware functions to manage the following \r
+  *          functionalities of the Cyclic Redundancy Check (CRC) peripheral:\r
+  *           + Initialization and de-initialization functions\r
+  *           + Peripheral Control functions \r
+  *           + Peripheral State functions\r
+  *\r
+  @verbatim\r
+ ===============================================================================\r
+                     ##### CRC How to use this driver #####\r
+ ===============================================================================\r
+    [..]\r
+\r
+    (#) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();\r
+\r
+    (#) Initialize CRC calculator\r
+         (++) specify generating polynomial (IP default or non-default one)\r
+         (++) specify initialization value (IP default or non-default one)\r
+         (++) specify input data format\r
+         (++) specify input or output data inversion mode if any\r
+\r
+    (#) Use HAL_CRC_Accumulate() function to compute the CRC value of the \r
+        input data buffer starting with the previously computed CRC as \r
+        initialization value\r
+\r
+    (#) Use HAL_CRC_Calculate() function to compute the CRC value of the \r
+        input data buffer starting with the defined initialization value \r
+        (default or non-default) to initiate CRC calculation\r
+\r
+  @endverbatim\r
+  ******************************************************************************\r
+  * @attention\r
+  *\r
+  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
+  *\r
+  * Redistribution and use in source and binary forms, with or without modification,\r
+  * are permitted provided that the following conditions are met:\r
+  *   1. Redistributions of source code must retain the above copyright notice,\r
+  *      this list of conditions and the following disclaimer.\r
+  *   2. Redistributions in binary form must reproduce the above copyright notice,\r
+  *      this list of conditions and the following disclaimer in the documentation\r
+  *      and/or other materials provided with the distribution.\r
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
+  *      may be used to endorse or promote products derived from this software\r
+  *      without specific prior written permission.\r
+  *\r
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+  *\r
+  ******************************************************************************\r
+  */\r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "stm32f7xx_hal.h"\r
+\r
+/** @addtogroup STM32F7xx_HAL_Driver\r
+  * @{\r
+  */\r
+\r
+/** @defgroup CRC CRC\r
+  * @brief CRC HAL module driver.\r
+  * @{\r
+  */\r
+\r
+#ifdef HAL_CRC_MODULE_ENABLED\r
+\r
+/* Private typedef -----------------------------------------------------------*/\r
+/* Private define ------------------------------------------------------------*/\r
+/* Private macro -------------------------------------------------------------*/\r
+/* Private variables ---------------------------------------------------------*/\r
+/* Private function prototypes -----------------------------------------------*/\r
+static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength);\r
+static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength);\r
+/* Exported functions --------------------------------------------------------*/\r
+\r
+/** @defgroup CRC_Exported_Functions\r
+  * @{\r
+  */\r
+\r
+/** @defgroup HAL_CRC_Group1 Initialization/de-initialization functions \r
+ *  @brief    Initialization and Configuration functions. \r
+ *\r
+@verbatim    \r
+ ===============================================================================\r
+            ##### Initialization and de-initialization functions #####\r
+ ===============================================================================\r
+    [..]  This section provides functions allowing to:\r
+      (+) Initialize the CRC according to the specified parameters \r
+          in the CRC_InitTypeDef and create the associated handle\r
+      (+) DeInitialize the CRC peripheral\r
+      (+) Initialize the CRC MSP\r
+      (+) DeInitialize CRC MSP \r
\r
+@endverbatim\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @brief  Initializes the CRC according to the specified\r
+  *         parameters in the CRC_InitTypeDef and creates the associated handle.\r
+  * @param  hcrc: CRC handle\r
+  * @retval HAL status\r
+  */\r
+HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)\r
+{\r
+  /* Check the CRC handle allocation */\r
+  if(hcrc == NULL)\r
+  {\r
+    return HAL_ERROR;\r
+  }\r
+\r
+  /* Check the parameters */\r
+  assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));\r
+\r
+  if(hcrc->State == HAL_CRC_STATE_RESET)\r
+  {\r
+    /* Init the low level hardware */\r
+    HAL_CRC_MspInit(hcrc);\r
+  }\r
+  \r
+  /* Change CRC peripheral state */\r
+  hcrc->State = HAL_CRC_STATE_BUSY;\r
+  \r
+  /* check whether or not non-default generating polynomial has been \r
+   * picked up by user */\r
+  assert_param(IS_DEFAULT_POLYNOMIAL(hcrc->Init.DefaultPolynomialUse)); \r
+  if (hcrc->Init.DefaultPolynomialUse == DEFAULT_POLYNOMIAL_ENABLE)\r
+  {\r
+    /* initialize IP with default generating polynomial */\r
+    WRITE_REG(hcrc->Instance->POL, DEFAULT_CRC32_POLY);  \r
+    MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, CRC_POLYLENGTH_32B);\r
+  }\r
+  else\r
+  {\r
+    /* initialize CRC IP with generating polynomial defined by user */\r
+    if (HAL_CRCEx_Polynomial_Set(hcrc, hcrc->Init.GeneratingPolynomial, hcrc->Init.CRCLength) != HAL_OK)\r
+    {\r
+      return HAL_ERROR;\r
+    }\r
+  }\r
+  \r
+  /* check whether or not non-default CRC initial value has been \r
+   * picked up by user */\r
+  assert_param(IS_DEFAULT_INIT_VALUE(hcrc->Init.DefaultInitValueUse));\r
+  if (hcrc->Init.DefaultInitValueUse == DEFAULT_INIT_VALUE_ENABLE)\r
+  {\r
+    WRITE_REG(hcrc->Instance->INIT, DEFAULT_CRC_INITVALUE);  \r
+  }\r
+  else\r
+  {\r
+    WRITE_REG(hcrc->Instance->INIT, hcrc->Init.InitValue);\r
+  }\r
+  \r
+\r
+  /* set input data inversion mode */\r
+  assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(hcrc->Init.InputDataInversionMode)); \r
+  MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, hcrc->Init.InputDataInversionMode); \r
+  \r
+  /* set output data inversion mode */\r
+  assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(hcrc->Init.OutputDataInversionMode)); \r
+  MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, hcrc->Init.OutputDataInversionMode);  \r
+  \r
+  /* makes sure the input data format (bytes, halfwords or words stream)\r
+   * is properly specified by user */\r
+  assert_param(IS_CRC_INPUTDATA_FORMAT(hcrc->InputDataFormat));\r
+\r
+  /* Change CRC peripheral state */\r
+  hcrc->State = HAL_CRC_STATE_READY;\r
+  \r
+  /* Return function status */\r
+  return HAL_OK;\r
+}\r
+\r
+/**\r
+  * @brief  DeInitializes the CRC peripheral.\r
+  * @param  hcrc: CRC handle\r
+  * @retval HAL status\r
+  */\r
+HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)\r
+{\r
+  /* Check the CRC handle allocation */\r
+  if(hcrc == NULL)\r
+  {\r
+    return HAL_ERROR;\r
+  }\r
+\r
+  /* Check the parameters */\r
+  assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));\r
+  \r
+  /* Check the CRC peripheral state */\r
+  if(hcrc->State == HAL_CRC_STATE_BUSY)\r
+  {\r
+    return HAL_BUSY;\r
+  }\r
+  \r
+  /* Change CRC peripheral state */\r
+  hcrc->State = HAL_CRC_STATE_BUSY;\r
+  \r
+  /* Reset CRC calculation unit */\r
+  __HAL_CRC_DR_RESET(hcrc);\r
+\r
+  /* DeInit the low level hardware */\r
+  HAL_CRC_MspDeInit(hcrc);\r
+\r
+  /* Change CRC peripheral state */\r
+  hcrc->State = HAL_CRC_STATE_RESET;\r
+\r
+  /* Process unlocked */\r
+  __HAL_UNLOCK(hcrc);\r
+\r
+  /* Return function status */\r
+  return HAL_OK;\r
+}\r
+\r
+/**\r
+  * @brief  Initializes the CRC MSP.\r
+  * @param  hcrc: CRC handle\r
+  * @retval None\r
+  */\r
+__weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)\r
+{\r
+  /* NOTE : This function should not be modified, when the callback is needed,\r
+            the HAL_CRC_MspInit can be implemented in the user file\r
+   */\r
+}\r
+\r
+/**\r
+  * @brief  DeInitializes the CRC MSP.\r
+  * @param  hcrc: CRC handle\r
+  * @retval None\r
+  */\r
+__weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)\r
+{\r
+  /* NOTE : This function should not be modified, when the callback is needed,\r
+            the HAL_CRC_MspDeInit can be implemented in the user file\r
+   */\r
+}\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup HAL_CRC_Group2 Peripheral Control functions \r
+ *  @brief   Peripheral Control functions \r
+ *\r
+@verbatim  \r
+ ==============================================================================\r
+                      ##### Peripheral Control functions #####\r
+ ==============================================================================  \r
+    [..]  This section provides functions allowing to:\r
+      (+) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer\r
+          using combination of the previous CRC value and the new one.\r
+          \r
+          or\r
+          \r
+      (+) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer\r
+          independently of the previous CRC value.\r
+\r
+@endverbatim\r
+  * @{\r
+  */\r
+\r
+/**                  \r
+  * @brief  Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer\r
+  *         starting with the previously computed CRC as initialization value.\r
+  * @param  hcrc: CRC handle\r
+  * @param  pBuffer: pointer to the input data buffer, exact input data format is\r
+  *         provided by hcrc->InputDataFormat.  \r
+  * @param  BufferLength: input data buffer length\r
+  * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)\r
+  */\r
+uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)\r
+{\r
+  uint32_t index = 0; /* CRC input data buffer index */\r
+  uint32_t temp = 0;  /* CRC output (read from hcrc->Instance->DR register) */\r
+  \r
+  /* Process locked */\r
+  __HAL_LOCK(hcrc); \r
+    \r
+  /* Change CRC peripheral state */  \r
+  hcrc->State = HAL_CRC_STATE_BUSY;\r
+  \r
+  switch (hcrc->InputDataFormat)\r
+  {\r
+    case CRC_INPUTDATA_FORMAT_WORDS:  \r
+      /* Enter Data to the CRC calculator */\r
+      for(index = 0; index < BufferLength; index++)\r
+      {\r
+        hcrc->Instance->DR = pBuffer[index];\r
+      }\r
+      temp = hcrc->Instance->DR;\r
+      break;\r
+      \r
+    case CRC_INPUTDATA_FORMAT_BYTES: \r
+      temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);\r
+      break;\r
+      \r
+    case CRC_INPUTDATA_FORMAT_HALFWORDS: \r
+      temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);\r
+      break;\r
+    default:\r
+      break;  \r
+  }\r
+  \r
+  /* Change CRC peripheral state */    \r
+  hcrc->State = HAL_CRC_STATE_READY; \r
+  \r
+  /* Process unlocked */\r
+  __HAL_UNLOCK(hcrc);\r
+  \r
+  /* Return the CRC computed value */ \r
+  return temp;\r
+}\r
+\r
+\r
+/**                  \r
+  * @brief  Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer\r
+  *         starting with hcrc->Instance->INIT as initialization value.\r
+  * @param  hcrc: CRC handle\r
+  * @param  pBuffer: pointer to the input data buffer, exact input data format is\r
+  *         provided by hcrc->InputDataFormat.  \r
+  * @param  BufferLength: input data buffer length\r
+  * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)\r
+  */  \r
+uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)\r
+{\r
+  uint32_t index = 0; /* CRC input data buffer index */\r
+  uint32_t temp = 0;  /* CRC output (read from hcrc->Instance->DR register) */\r
+    \r
+  /* Process locked */\r
+  __HAL_LOCK(hcrc); \r
+  \r
+  /* Change CRC peripheral state */  \r
+  hcrc->State = HAL_CRC_STATE_BUSY;\r
+  \r
+  /* Reset CRC Calculation Unit (hcrc->Instance->INIT is \r
+  *  written in hcrc->Instance->DR) */\r
+  __HAL_CRC_DR_RESET(hcrc);\r
+  \r
+  switch (hcrc->InputDataFormat)\r
+  {\r
+    case CRC_INPUTDATA_FORMAT_WORDS:  \r
+      /* Enter 32-bit input data to the CRC calculator */\r
+      for(index = 0; index < BufferLength; index++)\r
+      {\r
+        hcrc->Instance->DR = pBuffer[index];\r
+      }\r
+      temp = hcrc->Instance->DR;\r
+      break;\r
+      \r
+    case CRC_INPUTDATA_FORMAT_BYTES: \r
+      /* Specific 8-bit input data handling  */\r
+      temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);\r
+      break;\r
+      \r
+    case CRC_INPUTDATA_FORMAT_HALFWORDS: \r
+      /* Specific 16-bit input data handling  */\r
+      temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);\r
+      break;\r
+    default:\r
+      break;\r
+  }\r
+\r
+  /* Change CRC peripheral state */\r
+  hcrc->State = HAL_CRC_STATE_READY;\r
+\r
+  /* Process unlocked */\r
+  __HAL_UNLOCK(hcrc);\r
+  \r
+  /* Return the CRC computed value */ \r
+  return temp;\r
+}\r
+\r
+\r
+\r
+/**             \r
+  * @brief  Enter 8-bit input data to the CRC calculator.\r
+  *         Specific data handling to optimize processing time.  \r
+  * @param  hcrc: CRC handle\r
+  * @param  pBuffer: pointer to the input data buffer\r
+  * @param  BufferLength: input data buffer length\r
+  * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)\r
+  */\r
+static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)\r
+{\r
+  uint32_t i = 0; /* input data buffer index */\r
+  \r
+   /* Processing time optimization: 4 bytes are entered in a row with a single word write,\r
+    * last bytes must be carefully fed to the CRC calculator to ensure a correct type\r
+    * handling by the IP */\r
+   for(i = 0; i < (BufferLength/4); i++)\r
+   {\r
+     hcrc->Instance->DR = (uint32_t)(((uint32_t)(pBuffer[4*i])<<24) | ((uint32_t)(pBuffer[4*i+1])<<16) | ((uint32_t)(pBuffer[4*i+2])<<8) | (uint32_t)(pBuffer[4*i+3]));\r
+   }\r
+   /* last bytes specific handling */\r
+   if ((BufferLength%4) != 0)\r
+   {\r
+     if  (BufferLength%4 == 1)\r
+     {\r
+       *(__IO uint8_t*) (&hcrc->Instance->DR) = pBuffer[4*i];\r
+     }\r
+     if  (BufferLength%4 == 2)\r
+     {\r
+       *(__IO uint16_t*) (&hcrc->Instance->DR) = (uint16_t)(((uint32_t)(pBuffer[4*i])<<8) | (uint32_t)(pBuffer[4*i+1]));\r
+     }\r
+     if  (BufferLength%4 == 3)\r
+     {\r
+       *(__IO uint16_t*) (&hcrc->Instance->DR) = (uint16_t)(((uint32_t)(pBuffer[4*i])<<8) | (uint32_t)(pBuffer[4*i+1]));\r
+       *(__IO uint8_t*) (&hcrc->Instance->DR) = pBuffer[4*i+2];       \r
+     }\r
+   }\r
+  \r
+  /* Return the CRC computed value */ \r
+  return hcrc->Instance->DR;\r
+}\r
+\r
+\r
+\r
+/**             \r
+  * @brief  Enter 16-bit input data to the CRC calculator.\r
+  *         Specific data handling to optimize processing time.  \r
+  * @param  hcrc: CRC handle\r
+  * @param  pBuffer: pointer to the input data buffer\r
+  * @param  BufferLength: input data buffer length\r
+  * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)\r
+  */  \r
+static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength)\r
+{\r
+  uint32_t i = 0;  /* input data buffer index */\r
+  \r
+  /* Processing time optimization: 2 HalfWords are entered in a row with a single word write,\r
+   * in case of odd length, last HalfWord must be carefully fed to the CRC calculator to ensure \r
+   * a correct type handling by the IP */\r
+  for(i = 0; i < (BufferLength/2); i++)\r
+  {\r
+    hcrc->Instance->DR = (((uint32_t)(pBuffer[2*i])<<16) | (uint32_t)(pBuffer[2*i+1]));\r
+  }\r
+  if ((BufferLength%2) != 0)\r
+  {\r
+       *(__IO uint16_t*) (&hcrc->Instance->DR) = pBuffer[2*i]; \r
+  }\r
+   \r
+  /* Return the CRC computed value */ \r
+  return hcrc->Instance->DR;\r
+}\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/** @defgroup HAL_CRC_Group3 Peripheral State functions \r
+ *  @brief    Peripheral State functions. \r
+ *\r
+@verbatim   \r
+ ==============================================================================\r
+                      ##### Peripheral State functions #####\r
+ ==============================================================================  \r
+    [..]\r
+    This subsection permits to get in run-time the status of the peripheral \r
+    and the data flow.\r
+\r
+@endverbatim\r
+  * @{\r
+  */\r
+\r
+/**\r
+  * @brief  Returns the CRC state.\r
+  * @param  hcrc: CRC handle\r
+  * @retval HAL state\r
+  */\r
+HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)\r
+{\r
+  return hcrc->State;\r
+}\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+#endif /* HAL_CRC_MODULE_ENABLED */\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r