|
@@ -25,6 +25,7 @@
|
|
/* USER CODE BEGIN Includes */
|
|
/* USER CODE BEGIN Includes */
|
|
#include "usbd_cdc_if.h"
|
|
#include "usbd_cdc_if.h"
|
|
#include "uartio.h"
|
|
#include "uartio.h"
|
|
|
|
+#include "commprt.h"
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
/* USER CODE END Includes */
|
|
/* USER CODE END Includes */
|
|
@@ -51,6 +52,8 @@ DMA_HandleTypeDef hdma_adc;
|
|
|
|
|
|
COMP_HandleTypeDef hcomp2;
|
|
COMP_HandleTypeDef hcomp2;
|
|
|
|
|
|
|
|
+CRC_HandleTypeDef hcrc;
|
|
|
|
+
|
|
DAC_HandleTypeDef hdac;
|
|
DAC_HandleTypeDef hdac;
|
|
|
|
|
|
I2C_HandleTypeDef hi2c1;
|
|
I2C_HandleTypeDef hi2c1;
|
|
@@ -99,6 +102,7 @@ static void MX_TIM4_Init(void);
|
|
static void MX_TIM3_Init(void);
|
|
static void MX_TIM3_Init(void);
|
|
static void MX_TIM2_Init(void);
|
|
static void MX_TIM2_Init(void);
|
|
static void MX_I2C1_Init(void);
|
|
static void MX_I2C1_Init(void);
|
|
|
|
+static void MX_CRC_Init(void);
|
|
/* USER CODE BEGIN PFP */
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
|
|
/* USER CODE END PFP */
|
|
/* USER CODE END PFP */
|
|
@@ -154,6 +158,12 @@ void SwitchPeriphSupply(OnOff_t state)
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
|
|
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 */
|
|
/* USER CODE END 0 */
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -195,6 +205,7 @@ int main(void)
|
|
MX_TIM2_Init();
|
|
MX_TIM2_Init();
|
|
MX_I2C1_Init();
|
|
MX_I2C1_Init();
|
|
MX_USB_DEVICE_Init();
|
|
MX_USB_DEVICE_Init();
|
|
|
|
+ MX_CRC_Init();
|
|
/* USER CODE BEGIN 2 */
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
|
|
Switch3V3Regulator(ON);
|
|
Switch3V3Regulator(ON);
|
|
@@ -223,37 +234,23 @@ int main(void)
|
|
HAL_TIM_Base_Start_IT(&htim4);
|
|
HAL_TIM_Base_Start_IT(&htim4);
|
|
HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4);
|
|
HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4);
|
|
|
|
|
|
- uartio_init(&huart1);
|
|
|
|
|
|
+ UARTIO_Init(&huart1);
|
|
|
|
|
|
/* USER CODE END 2 */
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
/* Infinite loop */
|
|
/* Infinite loop */
|
|
/* USER CODE BEGIN WHILE */
|
|
/* USER CODE BEGIN WHILE */
|
|
char tempstr[32];
|
|
char tempstr[32];
|
|
- uint8_t rxtxbuf[256];
|
|
|
|
- uint8_t bt_rx_flag = 0;
|
|
|
|
|
|
|
|
uint32_t pps = 0;
|
|
uint32_t pps = 0;
|
|
uint32_t pps_avg = 0;
|
|
uint32_t pps_avg = 0;
|
|
|
|
+ uint32_t total_dose = 0;
|
|
uint8_t pwdn_cnt = 0;
|
|
uint8_t pwdn_cnt = 0;
|
|
uint8_t window = 0;
|
|
uint8_t window = 0;
|
|
|
|
|
|
Flags.Exti = 0;
|
|
Flags.Exti = 0;
|
|
while (1)
|
|
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)
|
|
if(Flags.Exti)
|
|
{
|
|
{
|
|
uint16_t btn = Flags.Exti;
|
|
uint16_t btn = Flags.Exti;
|
|
@@ -262,32 +259,33 @@ int main(void)
|
|
{
|
|
{
|
|
window ^= 1;
|
|
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)
|
|
if(Flags.Tim6)
|
|
{
|
|
{
|
|
Flags.Tim6 = 0;
|
|
Flags.Tim6 = 0;
|
|
HAL_ADC_Stop_DMA(&hadc);
|
|
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))
|
|
if((pps / pps_avg > 2) || (pps_avg / pps > 2))
|
|
{
|
|
{
|
|
pps_avg = pps;
|
|
pps_avg = pps;
|
|
@@ -309,18 +307,16 @@ int main(void)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
ssd1306_SetCursor(2, 2);
|
|
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();
|
|
ssd1306_UpdateScreen();
|
|
|
|
|
|
SetDACVoltage(DAC_CHANNEL_1, SIPM_BIAS_VOLTAGE_OFFSET);
|
|
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);
|
|
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)
|
|
if(pulses > 50 || Flags.Tim4 > 3)
|
|
@@ -335,8 +331,7 @@ int main(void)
|
|
htim4.Instance->CNT = 0;
|
|
htim4.Instance->CNT = 0;
|
|
HAL_TIM_Base_Start(&htim4);
|
|
HAL_TIM_Base_Start(&htim4);
|
|
|
|
|
|
- HAL_TIM_Base_Stop(&htim2);
|
|
|
|
- HAL_TIM_Base_Start(&htim2);
|
|
|
|
|
|
+ Beep();
|
|
}
|
|
}
|
|
|
|
|
|
/* USER CODE END WHILE */
|
|
/* 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
|
|
* @brief DAC Initialization Function
|
|
* @param None
|
|
* @param None
|