فهرست منبع

Basic communication protocol logic

Nagaev Aleksandr 2 سال پیش
والد
کامیت
5d7597e8aa

+ 2 - 0
stm32workspace/dosim-v1/.gitignore

@@ -0,0 +1,2 @@
+Debug/
+Release/

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
stm32workspace/dosim-v1/.mxproject


+ 20 - 0
stm32workspace/dosim-v1/Core/Inc/commprt.h

@@ -0,0 +1,20 @@
+/*
+ * commprt.h
+ *
+ *  Created on: Jan 25, 2022
+ *      Author: radioman
+ */
+
+#ifndef INC_COMMPRT_H_
+#define INC_COMMPRT_H_
+
+#include <stdint.h>
+
+typedef enum { COMM_BT, COMM_USB } COMM_IfaceTypeDef;
+typedef enum { COMM_OK, COMM_FAIL } COMM_StatusTypeDef;
+
+COMM_StatusTypeDef COMM_Receive(uint8_t *buf, COMM_IfaceTypeDef iface);
+
+COMM_StatusTypeDef COMM_Transmit(uint8_t *data, uint8_t len, COMM_IfaceTypeDef iface);
+
+#endif /* INC_COMMPRT_H_ */

+ 1 - 1
stm32workspace/dosim-v1/Core/Inc/stm32l1xx_hal_conf.h

@@ -36,7 +36,7 @@
 #define HAL_ADC_MODULE_ENABLED
 /*#define HAL_CRYP_MODULE_ENABLED   */
 #define HAL_COMP_MODULE_ENABLED
-/*#define HAL_CRC_MODULE_ENABLED   */
+#define HAL_CRC_MODULE_ENABLED
 /*#define HAL_CRYP_MODULE_ENABLED   */
 #define HAL_DAC_MODULE_ENABLED
 #define HAL_I2C_MODULE_ENABLED

+ 1 - 0
stm32workspace/dosim-v1/Core/Inc/stm32l1xx_it.h

@@ -62,6 +62,7 @@ void DMA1_Channel5_IRQHandler(void);
 void USB_LP_IRQHandler(void);
 void COMP_IRQHandler(void);
 void TIM4_IRQHandler(void);
+void USART1_IRQHandler(void);
 void EXTI15_10_IRQHandler(void);
 void TIM6_IRQHandler(void);
 /* USER CODE BEGIN EFP */

+ 4 - 4
stm32workspace/dosim-v1/Core/Inc/uartio.h

@@ -11,9 +11,9 @@
 #define UART_RX_BUF_SIZE 256
 #define UART_TX_BUF_SIZE 256
 
-void uartio_init(UART_HandleTypeDef *huart);
-uint32_t uartio_data_avail(UART_HandleTypeDef *huart);
-uint32_t uartio_receive(UART_HandleTypeDef *huart, uint8_t *buf);
-uint32_t uartio_transmit(UART_HandleTypeDef *huart, uint8_t *buf, uint32_t len);
+void UARTIO_Init(UART_HandleTypeDef *huart);
+uint32_t UARTIO_DataAvail(UART_HandleTypeDef *huart);
+uint32_t UARTIO_Receive(UART_HandleTypeDef *huart, uint8_t *buf);
+uint32_t UARTIO_Transmit(UART_HandleTypeDef *huart, uint8_t *buf, uint32_t len);
 
 #endif /* INC_UARTIO_H_ */

+ 53 - 0
stm32workspace/dosim-v1/Core/Src/commprt.c

@@ -0,0 +1,53 @@
+/*
+ * commprt.c
+ *
+ *  Created on: Jan 25, 2022
+ *      Author: radioman
+ */
+
+#include <string.h>
+#include "stm32l1xx_hal.h"
+#include "commprt.h"
+#include "uartio.h"
+#include "usbd_cdc_if.h"
+
+#define COMM_HEADER_BYTE	0x55;
+#define COMM_BUFFER_SIZE	260
+
+extern UART_HandleTypeDef huart1;
+
+static uint8_t comm_buffer[COMM_BUFFER_SIZE];
+
+uint8_t COMM_Checksum(const uint8_t *data, uint8_t len)
+{
+	uint8_t chk = 0;
+	while(len--)
+		chk ^= data[len];
+	return chk;
+}
+
+COMM_StatusTypeDef COMM_Receive(uint8_t *buf, COMM_IfaceTypeDef iface)
+{
+	return COMM_OK;
+}
+
+COMM_StatusTypeDef COMM_Transmit(uint8_t *data, uint8_t len, COMM_IfaceTypeDef iface)
+{
+	comm_buffer[0] = COMM_HEADER_BYTE;
+	comm_buffer[1] = len;
+	memcpy(&comm_buffer[2], data, len);
+	comm_buffer[len + 2] = COMM_Checksum(comm_buffer, len + 2);
+
+	switch(iface)
+	{
+		case COMM_BT:
+			UARTIO_Transmit(&huart1, comm_buffer, len + 3);
+			break;
+		case COMM_USB:
+			CDC_Transmit_FS(comm_buffer, len + 3);
+			break;
+		default:
+			return COMM_FAIL;
+	}
+	return COMM_OK;
+}

+ 66 - 45
stm32workspace/dosim-v1/Core/Src/main.c

@@ -25,6 +25,7 @@
 /* USER CODE BEGIN Includes */
 #include "usbd_cdc_if.h"
 #include "uartio.h"
+#include "commprt.h"
 #include <stdlib.h>
 #include <stdio.h>
 /* USER CODE END Includes */
@@ -51,6 +52,8 @@ DMA_HandleTypeDef hdma_adc;
 
 COMP_HandleTypeDef hcomp2;
 
+CRC_HandleTypeDef hcrc;
+
 DAC_HandleTypeDef hdac;
 
 I2C_HandleTypeDef hi2c1;
@@ -99,6 +102,7 @@ static void MX_TIM4_Init(void);
 static void MX_TIM3_Init(void);
 static void MX_TIM2_Init(void);
 static void MX_I2C1_Init(void);
+static void MX_CRC_Init(void);
 /* USER CODE BEGIN PFP */
 
 /* USER CODE END PFP */
@@ -154,6 +158,12 @@ void SwitchPeriphSupply(OnOff_t state)
     HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
 }
 
+void Beep()
+{
+    HAL_TIM_Base_Stop(&htim2);
+    HAL_TIM_Base_Start(&htim2);
+}
+
 /* USER CODE END 0 */
 
 /**
@@ -195,6 +205,7 @@ int main(void)
   MX_TIM2_Init();
   MX_I2C1_Init();
   MX_USB_DEVICE_Init();
+  MX_CRC_Init();
   /* USER CODE BEGIN 2 */
 
   Switch3V3Regulator(ON);
@@ -223,37 +234,23 @@ int main(void)
   HAL_TIM_Base_Start_IT(&htim4);
   HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4);
 
-  uartio_init(&huart1);
+  UARTIO_Init(&huart1);
 
   /* USER CODE END 2 */
 
   /* Infinite loop */
   /* USER CODE BEGIN WHILE */
   char tempstr[32];
-  uint8_t rxtxbuf[256];
-  uint8_t bt_rx_flag = 0;
 
   uint32_t pps = 0;
   uint32_t pps_avg = 0;
+  uint32_t total_dose = 0;
   uint8_t pwdn_cnt = 0;
   uint8_t window = 0;
 
   Flags.Exti = 0;
   while (1)
   {
-    if(pwdn_cnt > 10)
-    {
-      Flags.Exti = 0;
-      ssd1306_Reset();
-      SwitchPeriphSupply(OFF);
-      HAL_I2C_DeInit(&hi2c1);
-      HAL_I2C_DeInit(&hi2c2);
-      HAL_UART_DeInit(&huart1);
-      HAL_GPIO_DeInit(GPIOB, GPIO_PIN_All);
-      HAL_GPIO_DeInit(GPIOA, GPIO_PIN_All);
-      HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
-    }
-
     if(Flags.Exti)
     {
     	uint16_t btn = Flags.Exti;
@@ -262,32 +259,33 @@ int main(void)
     	{
     		window ^= 1;
     	}
-
-    	if(btn == GPIO_PIN_14)
-    	{
-    		uartio_transmit(&huart1, "Hello world\r\n", 13);
-    	}
-    }
-
-    if(uartio_data_avail(&huart1))
-    {
-    	uint32_t len = uartio_receive(&huart1, rxtxbuf);
-    	//rxtxbuf[len] = 0;
-    	CDC_Transmit_FS(rxtxbuf, len);
-    	//bt_rx_flag = len;
-    }
-
-    if(CDC_DataAvailable())
-    {
-    	int size = CDC_ReadData(rxtxbuf, sizeof(rxtxbuf));
-    	if(size > 0)
-    		uartio_transmit(&huart1, rxtxbuf, size);
     }
 
     if(Flags.Tim6)
     {
       Flags.Tim6 = 0;
       HAL_ADC_Stop_DMA(&hadc);
+
+      if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14) == GPIO_PIN_RESET)
+      {
+		if(++pwdn_cnt > 10)
+		{
+		  ssd1306_Reset();
+		  SwitchPeriphSupply(OFF);
+		  HAL_I2C_DeInit(&hi2c1);
+		  HAL_I2C_DeInit(&hi2c2);
+		  HAL_UART_DeInit(&huart1);
+		  HAL_GPIO_DeInit(GPIOB, GPIO_PIN_All);
+		  HAL_GPIO_DeInit(GPIOA, GPIO_PIN_All);
+		  HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
+
+		}
+      }
+      else
+      {
+    	  pwdn_cnt = 0;
+      }
+
       if((pps / pps_avg > 2) || (pps_avg / pps > 2))
       {
         pps_avg = pps;
@@ -309,18 +307,16 @@ int main(void)
       else
       {
     	  ssd1306_SetCursor(2, 2);
-    	  if(bt_rx_flag)
-    	  {
-    		  //sprintf(tempstr, "test:");
-    		  //sprintf(tempstr, ":%x", rxtxbuf[0]);
-    		  ssd1306_WriteString(rxtxbuf, Font_7x10, White);
-    		  //bt_rx_flag = 0;
-    	  }
+    	  ssd1306_WriteString(tempstr, Font_7x10, White);
       }
       ssd1306_UpdateScreen();
 
       SetDACVoltage(DAC_CHANNEL_1, SIPM_BIAS_VOLTAGE_OFFSET);
+      SetDACVoltage(DAC_CHANNEL_2, COMP_THRESHOLD_VOLTAGE);
       HAL_ADC_Start_DMA(&hadc, (uint32_t*)&adc_meas, 3);
+
+      sprintf(tempstr, "%5.2f uSv/h\r\n", (float)pps_avg / 100.0);
+      COMM_Transmit((uint8_t*)&pps_avg, sizeof(pps_avg), COMM_USB);
     }
 
     if(pulses > 50 || Flags.Tim4 > 3)
@@ -335,8 +331,7 @@ int main(void)
       htim4.Instance->CNT = 0;
       HAL_TIM_Base_Start(&htim4);
 
-      HAL_TIM_Base_Stop(&htim2);
-      HAL_TIM_Base_Start(&htim2);
+      Beep();
     }
 
     /* USER CODE END WHILE */
@@ -489,6 +484,32 @@ static void MX_COMP2_Init(void)
 
 }
 
+/**
+  * @brief CRC Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_CRC_Init(void)
+{
+
+  /* USER CODE BEGIN CRC_Init 0 */
+
+  /* USER CODE END CRC_Init 0 */
+
+  /* USER CODE BEGIN CRC_Init 1 */
+
+  /* USER CODE END CRC_Init 1 */
+  hcrc.Instance = CRC;
+  if (HAL_CRC_Init(&hcrc) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN CRC_Init 2 */
+
+  /* USER CODE END CRC_Init 2 */
+
+}
+
 /**
   * @brief DAC Initialization Function
   * @param None

+ 50 - 0
stm32workspace/dosim-v1/Core/Src/stm32l1xx_hal_msp.c

@@ -227,6 +227,50 @@ void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
 
 }
 
+/**
+* @brief CRC MSP Initialization
+* This function configures the hardware resources used in this example
+* @param hcrc: CRC handle pointer
+* @retval None
+*/
+void HAL_CRC_MspInit(CRC_HandleTypeDef* hcrc)
+{
+  if(hcrc->Instance==CRC)
+  {
+  /* USER CODE BEGIN CRC_MspInit 0 */
+
+  /* USER CODE END CRC_MspInit 0 */
+    /* Peripheral clock enable */
+    __HAL_RCC_CRC_CLK_ENABLE();
+  /* USER CODE BEGIN CRC_MspInit 1 */
+
+  /* USER CODE END CRC_MspInit 1 */
+  }
+
+}
+
+/**
+* @brief CRC MSP De-Initialization
+* This function freeze the hardware resources used in this example
+* @param hcrc: CRC handle pointer
+* @retval None
+*/
+void HAL_CRC_MspDeInit(CRC_HandleTypeDef* hcrc)
+{
+  if(hcrc->Instance==CRC)
+  {
+  /* USER CODE BEGIN CRC_MspDeInit 0 */
+
+  /* USER CODE END CRC_MspDeInit 0 */
+    /* Peripheral clock disable */
+    __HAL_RCC_CRC_CLK_DISABLE();
+  /* USER CODE BEGIN CRC_MspDeInit 1 */
+
+  /* USER CODE END CRC_MspDeInit 1 */
+  }
+
+}
+
 /**
 * @brief DAC MSP Initialization
 * This function configures the hardware resources used in this example
@@ -611,6 +655,9 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
 
     __HAL_LINKDMA(huart,hdmatx,hdma_usart1_tx);
 
+    /* USART1 interrupt Init */
+    HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
+    HAL_NVIC_EnableIRQ(USART1_IRQn);
   /* USER CODE BEGIN USART1_MspInit 1 */
 
   /* USER CODE END USART1_MspInit 1 */
@@ -643,6 +690,9 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
     /* USART1 DMA DeInit */
     HAL_DMA_DeInit(huart->hdmarx);
     HAL_DMA_DeInit(huart->hdmatx);
+
+    /* USART1 interrupt DeInit */
+    HAL_NVIC_DisableIRQ(USART1_IRQn);
   /* USER CODE BEGIN USART1_MspDeInit 1 */
 
   /* USER CODE END USART1_MspDeInit 1 */

+ 15 - 0
stm32workspace/dosim-v1/Core/Src/stm32l1xx_it.c

@@ -63,6 +63,7 @@ extern TIM_HandleTypeDef htim4;
 extern TIM_HandleTypeDef htim6;
 extern DMA_HandleTypeDef hdma_usart1_rx;
 extern DMA_HandleTypeDef hdma_usart1_tx;
+extern UART_HandleTypeDef huart1;
 /* USER CODE BEGIN EV */
 
 /* USER CODE END EV */
@@ -289,6 +290,20 @@ void TIM4_IRQHandler(void)
   /* USER CODE END TIM4_IRQn 1 */
 }
 
+/**
+  * @brief This function handles USART1 global interrupt.
+  */
+void USART1_IRQHandler(void)
+{
+  /* USER CODE BEGIN USART1_IRQn 0 */
+
+  /* USER CODE END USART1_IRQn 0 */
+  HAL_UART_IRQHandler(&huart1);
+  /* USER CODE BEGIN USART1_IRQn 1 */
+
+  /* USER CODE END USART1_IRQn 1 */
+}
+
 /**
   * @brief This function handles EXTI line[15:10] interrupts.
   */

+ 13 - 10
stm32workspace/dosim-v1/Core/Src/uartio.c

@@ -11,30 +11,31 @@
 
 static uint8_t uart_rx_buffer[UART_RX_BUF_SIZE];
 static uint8_t uart_tx_buffer[UART_TX_BUF_SIZE];
+
 static uint32_t rd_ptr;
+static uint8_t tx_cplt = 1;
 
-void uartio_init(UART_HandleTypeDef *huart)
+void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
 {
+	tx_cplt = 1;
+}
 
+void UARTIO_Init(UART_HandleTypeDef *huart)
+{
 	HAL_UART_Receive_DMA(huart, uart_rx_buffer, UART_RX_BUF_SIZE);
 	rd_ptr = 0;
 }
 
-uint32_t uartio_data_avail(UART_HandleTypeDef *huart)
+uint32_t UARTIO_DataAvail(UART_HandleTypeDef *huart)
 {
-	if((UART_RX_BUF_SIZE - huart->hdmarx->Instance->CNDTR) != rd_ptr)
-		return 1;
-
-	return 0;
-	/*
 	if((UART_RX_BUF_SIZE - huart->hdmarx->Instance->CNDTR) >= rd_ptr)
 		return (UART_RX_BUF_SIZE - huart->hdmarx->Instance->CNDTR) - rd_ptr;
 	else
 		return (2 * UART_RX_BUF_SIZE) - rd_ptr - huart->hdmarx->Instance->CNDTR;
-		*/
+
 }
 
-uint32_t uartio_receive(UART_HandleTypeDef *huart, uint8_t *buf)
+uint32_t UARTIO_Receive(UART_HandleTypeDef *huart, uint8_t *buf)
 {
 	uint32_t dma_ptr = (UART_RX_BUF_SIZE - huart->hdmarx->Instance->CNDTR);
 	if(dma_ptr > rd_ptr)
@@ -58,9 +59,11 @@ uint32_t uartio_receive(UART_HandleTypeDef *huart, uint8_t *buf)
 	}
 }
 
-uint32_t uartio_transmit(UART_HandleTypeDef *huart, uint8_t *buf, uint32_t len)
+uint32_t UARTIO_Transmit(UART_HandleTypeDef *huart, uint8_t *buf, uint32_t len)
 {
 	memcpy(uart_tx_buffer, buf, len);
+	while(!tx_cplt);
 	HAL_UART_Transmit_DMA(huart, uart_tx_buffer, len);
+	tx_cplt = 0;
 	return len;
 }

+ 184 - 0
stm32workspace/dosim-v1/Drivers/STM32L1xx_HAL_Driver/Inc/stm32l1xx_hal_crc.h

@@ -0,0 +1,184 @@
+/**
+  ******************************************************************************
+  * @file    stm32l1xx_hal_crc.h
+  * @author  MCD Application Team
+  * @brief   Header file of CRC HAL module.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
+  * All rights reserved.</center></h2>
+  *
+  * This software component is licensed by ST under BSD 3-Clause license,
+  * the "License"; You may not use this file except in compliance with the
+  * License. You may obtain a copy of the License at:
+  *                        opensource.org/licenses/BSD-3-Clause
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef STM32L1xx_HAL_CRC_H
+#define STM32L1xx_HAL_CRC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l1xx_hal_def.h"
+
+/** @addtogroup STM32L1xx_HAL_Driver
+  * @{
+  */
+
+/** @addtogroup CRC
+  * @{
+  */
+
+/* Exported types ------------------------------------------------------------*/
+/** @defgroup CRC_Exported_Types CRC Exported Types
+  * @{
+  */
+
+/**
+  * @brief  CRC HAL State Structure definition
+  */
+typedef enum
+{
+  HAL_CRC_STATE_RESET     = 0x00U,  /*!< CRC not yet initialized or disabled */
+  HAL_CRC_STATE_READY     = 0x01U,  /*!< CRC initialized and ready for use   */
+  HAL_CRC_STATE_BUSY      = 0x02U,  /*!< CRC internal process is ongoing     */
+  HAL_CRC_STATE_TIMEOUT   = 0x03U,  /*!< CRC timeout state                   */
+  HAL_CRC_STATE_ERROR     = 0x04U   /*!< CRC error state                     */
+} HAL_CRC_StateTypeDef;
+
+
+/**
+  * @brief  CRC Handle Structure definition
+  */
+typedef struct
+{
+  CRC_TypeDef                 *Instance;   /*!< Register base address        */
+
+  HAL_LockTypeDef             Lock;        /*!< CRC Locking object           */
+
+  __IO HAL_CRC_StateTypeDef   State;       /*!< CRC communication state      */
+
+} CRC_HandleTypeDef;
+/**
+  * @}
+  */
+
+/* Exported constants --------------------------------------------------------*/
+/** @defgroup CRC_Exported_Constants CRC Exported Constants
+  * @{
+  */
+
+/**
+  * @}
+  */
+
+/* Exported macros -----------------------------------------------------------*/
+/** @defgroup CRC_Exported_Macros CRC Exported Macros
+  * @{
+  */
+
+/** @brief Reset CRC handle state.
+  * @param  __HANDLE__ CRC handle.
+  * @retval None
+  */
+#define __HAL_CRC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRC_STATE_RESET)
+
+/**
+  * @brief  Reset CRC Data Register.
+  * @param  __HANDLE__ CRC handle
+  * @retval None
+  */
+#define __HAL_CRC_DR_RESET(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRC_CR_RESET)
+
+/**
+  * @brief Store data in the Independent Data (ID) register.
+  * @param __HANDLE__ CRC handle
+  * @param __VALUE__  Value to be stored in the ID register
+  * @note  Refer to the Reference Manual to get the authorized __VALUE__ length in bits
+  * @retval None
+  */
+#define __HAL_CRC_SET_IDR(__HANDLE__, __VALUE__) (WRITE_REG((__HANDLE__)->Instance->IDR, (__VALUE__)))
+
+/**
+  * @brief Return the data stored in the Independent Data (ID) register.
+  * @param __HANDLE__ CRC handle
+  * @note  Refer to the Reference Manual to get the authorized __VALUE__ length in bits
+  * @retval Value of the ID register
+  */
+#define __HAL_CRC_GET_IDR(__HANDLE__) (((__HANDLE__)->Instance->IDR) & CRC_IDR_IDR)
+/**
+  * @}
+  */
+
+
+/* Private macros --------------------------------------------------------*/
+/** @defgroup  CRC_Private_Macros CRC Private Macros
+  * @{
+  */
+
+/**
+  * @}
+  */
+
+/* Exported functions --------------------------------------------------------*/
+/** @defgroup CRC_Exported_Functions CRC Exported Functions
+  * @{
+  */
+
+/* Initialization and de-initialization functions  ****************************/
+/** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
+  * @{
+  */
+HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc);
+HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc);
+void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc);
+void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc);
+/**
+  * @}
+  */
+
+/* Peripheral Control functions ***********************************************/
+/** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
+  * @{
+  */
+uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
+uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
+/**
+  * @}
+  */
+
+/* Peripheral State and Error functions ***************************************/
+/** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
+  * @{
+  */
+HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc);
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* STM32L1xx_HAL_CRC_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 330 - 0
stm32workspace/dosim-v1/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_crc.c

@@ -0,0 +1,330 @@
+/**
+  ******************************************************************************
+  * @file    stm32l1xx_hal_crc.c
+  * @author  MCD Application Team
+  * @brief   CRC HAL module driver.
+  *          This file provides firmware functions to manage the following
+  *          functionalities of the Cyclic Redundancy Check (CRC) peripheral:
+  *           + Initialization and de-initialization functions
+  *           + Peripheral Control functions
+  *           + Peripheral State functions
+  *
+  @verbatim
+ ===============================================================================
+                     ##### How to use this driver #####
+ ===============================================================================
+    [..]
+         (+) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
+         (+) Initialize CRC calculator
+             (++) specify generating polynomial (peripheral default or non-default one)
+             (++) specify initialization value (peripheral default or non-default one)
+             (++) specify input data format
+             (++) specify input or output data inversion mode if any
+         (+) Use HAL_CRC_Accumulate() function to compute the CRC value of the
+             input data buffer starting with the previously computed CRC as
+             initialization value
+         (+) Use HAL_CRC_Calculate() function to compute the CRC value of the
+             input data buffer starting with the defined initialization value
+             (default or non-default) to initiate CRC calculation
+
+  @endverbatim
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
+  * All rights reserved.</center></h2>
+  *
+  * This software component is licensed by ST under BSD 3-Clause license,
+  * the "License"; You may not use this file except in compliance with the
+  * License. You may obtain a copy of the License at:
+  *                        opensource.org/licenses/BSD-3-Clause
+  *
+  ******************************************************************************
+  */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l1xx_hal.h"
+
+/** @addtogroup STM32L1xx_HAL_Driver
+  * @{
+  */
+
+/** @defgroup CRC CRC
+  * @brief CRC HAL module driver.
+  * @{
+  */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+
+/* Exported functions --------------------------------------------------------*/
+
+/** @defgroup CRC_Exported_Functions CRC Exported Functions
+  * @{
+  */
+
+/** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
+  *  @brief    Initialization and Configuration functions.
+  *
+@verbatim
+ ===============================================================================
+            ##### Initialization and de-initialization functions #####
+ ===============================================================================
+    [..]  This section provides functions allowing to:
+      (+) Initialize the CRC according to the specified parameters
+          in the CRC_InitTypeDef and create the associated handle
+      (+) DeInitialize the CRC peripheral
+      (+) Initialize the CRC MSP (MCU Specific Package)
+      (+) DeInitialize the CRC MSP
+
+@endverbatim
+  * @{
+  */
+
+/**
+  * @brief  Initialize the CRC according to the specified
+  *         parameters in the CRC_InitTypeDef and create the associated handle.
+  * @param  hcrc CRC handle
+  * @retval HAL status
+  */
+HAL_StatusTypeDef HAL_CRC_Init(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));
+
+  if (hcrc->State == HAL_CRC_STATE_RESET)
+  {
+    /* Allocate lock resource and initialize it */
+    hcrc->Lock = HAL_UNLOCKED;
+    /* Init the low level hardware */
+    HAL_CRC_MspInit(hcrc);
+  }
+
+  /* Change CRC peripheral state */
+  hcrc->State = HAL_CRC_STATE_READY;
+
+  /* Return function status */
+  return HAL_OK;
+}
+
+/**
+  * @brief  DeInitialize 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);
+
+  /* Reset IDR register content */
+  CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR);
+
+  /* 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  Initializes the CRC MSP.
+  * @param  hcrc CRC handle
+  * @retval None
+  */
+__weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
+{
+  /* Prevent unused argument(s) compilation warning */
+  UNUSED(hcrc);
+
+  /* NOTE : This function should not be modified, when the callback is needed,
+            the HAL_CRC_MspInit can be implemented in the user file
+   */
+}
+
+/**
+  * @brief  DeInitialize the CRC MSP.
+  * @param  hcrc CRC handle
+  * @retval None
+  */
+__weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
+{
+  /* Prevent unused argument(s) compilation warning */
+  UNUSED(hcrc);
+
+  /* NOTE : This function should not be modified, when the callback is needed,
+            the HAL_CRC_MspDeInit can be implemented in the user file
+   */
+}
+
+/**
+  * @}
+  */
+
+/** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
+  *  @brief    management functions.
+  *
+@verbatim
+ ===============================================================================
+                      ##### Peripheral Control functions #####
+ ===============================================================================
+    [..]  This section provides functions allowing to:
+      (+) compute the 32-bit CRC value of a 32-bit data buffer
+          using combination of the previous CRC value and the new one.
+
+       [..]  or
+
+      (+) compute the 32-bit CRC value of a 32-bit data buffer
+          independently of the previous CRC value.
+
+@endverbatim
+  * @{
+  */
+
+/**
+  * @brief  Compute the 32-bit CRC value of a 32-bit data buffer
+  *         starting with the previously computed CRC as initialization value.
+  * @param  hcrc CRC handle
+  * @param  pBuffer pointer to the input data buffer.
+  * @param  BufferLength input data buffer length (number of uint32_t words).
+  * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
+  */
+uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
+{
+  uint32_t index;      /* CRC input data buffer index */
+  uint32_t temp = 0U;  /* CRC output (read from hcrc->Instance->DR register) */
+
+  /* Change CRC peripheral state */
+  hcrc->State = HAL_CRC_STATE_BUSY;
+
+  /* Enter Data to the CRC calculator */
+  for (index = 0U; index < BufferLength; index++)
+  {
+    hcrc->Instance->DR = pBuffer[index];
+  }
+  temp = hcrc->Instance->DR;
+
+  /* Change CRC peripheral state */
+  hcrc->State = HAL_CRC_STATE_READY;
+
+  /* Return the CRC computed value */
+  return temp;
+}
+
+/**
+  * @brief  Compute the 32-bit CRC value of a 32-bit data buffer
+  *         starting with hcrc->Instance->INIT as initialization value.
+  * @param  hcrc CRC handle
+  * @param  pBuffer pointer to the input data buffer.
+  * @param  BufferLength input data buffer length (number of uint32_t words).
+  * @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;      /* CRC input data buffer index */
+  uint32_t temp = 0U;  /* CRC output (read from hcrc->Instance->DR register) */
+
+  /* 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);
+
+  /* Enter 32-bit input data to the CRC calculator */
+  for (index = 0U; index < BufferLength; index++)
+  {
+    hcrc->Instance->DR = pBuffer[index];
+  }
+  temp = hcrc->Instance->DR;
+
+  /* Change CRC peripheral state */
+  hcrc->State = HAL_CRC_STATE_READY;
+
+  /* Return the CRC computed value */
+  return temp;
+}
+
+/**
+  * @}
+  */
+
+/** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
+  *  @brief    Peripheral State functions.
+  *
+@verbatim
+ ===============================================================================
+                      ##### Peripheral State functions #####
+ ===============================================================================
+    [..]
+    This subsection permits to get in run-time the status of the peripheral.
+
+@endverbatim
+  * @{
+  */
+
+/**
+  * @brief  Return the CRC handle state.
+  * @param  hcrc CRC handle
+  * @retval HAL state
+  */
+HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
+{
+  /* Return CRC handle state */
+  return hcrc->State;
+}
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+
+#endif /* HAL_CRC_MODULE_ENABLED */
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 30 - 25
stm32workspace/dosim-v1/dosim-v1.ioc

@@ -62,21 +62,22 @@ KeepUserPlacement=false
 Mcu.Family=STM32L1
 Mcu.IP0=ADC
 Mcu.IP1=COMP2
-Mcu.IP10=TIM3
-Mcu.IP11=TIM4
-Mcu.IP12=TIM6
-Mcu.IP13=USART1
-Mcu.IP14=USB
-Mcu.IP15=USB_DEVICE
-Mcu.IP2=DAC
-Mcu.IP3=DMA
-Mcu.IP4=I2C1
-Mcu.IP5=I2C2
-Mcu.IP6=NVIC
-Mcu.IP7=RCC
-Mcu.IP8=SYS
-Mcu.IP9=TIM2
-Mcu.IPNb=16
+Mcu.IP10=TIM2
+Mcu.IP11=TIM3
+Mcu.IP12=TIM4
+Mcu.IP13=TIM6
+Mcu.IP14=USART1
+Mcu.IP15=USB
+Mcu.IP16=USB_DEVICE
+Mcu.IP2=CRC
+Mcu.IP3=DAC
+Mcu.IP4=DMA
+Mcu.IP5=I2C1
+Mcu.IP6=I2C2
+Mcu.IP7=NVIC
+Mcu.IP8=RCC
+Mcu.IP9=SYS
+Mcu.IPNb=17
 Mcu.Name=STM32L151C(6-8-B)TxA
 Mcu.Package=LQFP48
 Mcu.Pin0=PH0-OSC_IN
@@ -96,23 +97,24 @@ Mcu.Pin20=PB7
 Mcu.Pin21=VP_ADC_TempSens_Input
 Mcu.Pin22=VP_ADC_Vref_Input
 Mcu.Pin23=VP_COMP2_VS_DACOUT2
-Mcu.Pin24=VP_SYS_VS_Systick
-Mcu.Pin25=VP_TIM2_VS_ClockSourceINT
-Mcu.Pin26=VP_TIM2_VS_OPM
-Mcu.Pin27=VP_TIM3_VS_ControllerModeGated
-Mcu.Pin28=VP_TIM3_VS_ClockSourceINT
-Mcu.Pin29=VP_TIM3_VS_ClockSourceITR
+Mcu.Pin24=VP_CRC_VS_CRC
+Mcu.Pin25=VP_SYS_VS_Systick
+Mcu.Pin26=VP_TIM2_VS_ClockSourceINT
+Mcu.Pin27=VP_TIM2_VS_OPM
+Mcu.Pin28=VP_TIM3_VS_ControllerModeGated
+Mcu.Pin29=VP_TIM3_VS_ClockSourceINT
 Mcu.Pin3=PA4
-Mcu.Pin30=VP_TIM4_VS_ClockSourceINT
-Mcu.Pin31=VP_TIM6_VS_ClockSourceINT
-Mcu.Pin32=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
+Mcu.Pin30=VP_TIM3_VS_ClockSourceITR
+Mcu.Pin31=VP_TIM4_VS_ClockSourceINT
+Mcu.Pin32=VP_TIM6_VS_ClockSourceINT
+Mcu.Pin33=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
 Mcu.Pin4=PA5
 Mcu.Pin5=PA7
 Mcu.Pin6=PB0
 Mcu.Pin7=PB1
 Mcu.Pin8=PB10
 Mcu.Pin9=PB11
-Mcu.PinsNb=33
+Mcu.PinsNb=34
 Mcu.ThirdPartyNb=0
 Mcu.UserConstants=
 Mcu.UserName=STM32L151CBTxA
@@ -135,6 +137,7 @@ NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false
 NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true
 NVIC.TIM4_IRQn=true\:0\:0\:false\:false\:true\:true\:true
 NVIC.TIM6_IRQn=true\:0\:0\:false\:false\:true\:true\:true
+NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true
 NVIC.USB_LP_IRQn=true\:0\:0\:false\:false\:true\:false\:true
 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
 PA0-WKUP1.Mode=IN0
@@ -297,6 +300,8 @@ VP_ADC_Vref_Input.Mode=IN-Vrefint
 VP_ADC_Vref_Input.Signal=ADC_Vref_Input
 VP_COMP2_VS_DACOUT2.Mode=INM_DACOUT2
 VP_COMP2_VS_DACOUT2.Signal=COMP2_VS_DACOUT2
+VP_CRC_VS_CRC.Mode=CRC_Activate
+VP_CRC_VS_CRC.Signal=CRC_VS_CRC
 VP_SYS_VS_Systick.Mode=SysTick
 VP_SYS_VS_Systick.Signal=SYS_VS_Systick
 VP_TIM2_VS_ClockSourceINT.Mode=Internal

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است