|
@@ -63,12 +63,15 @@ CRC_HandleTypeDef hcrc;
|
|
|
|
|
|
DAC_HandleTypeDef hdac1;
|
|
|
|
|
|
+IWDG_HandleTypeDef hiwdg1;
|
|
|
+
|
|
|
RNG_HandleTypeDef hrng;
|
|
|
|
|
|
TIM_HandleTypeDef htim1;
|
|
|
TIM_HandleTypeDef htim2;
|
|
|
TIM_HandleTypeDef htim3;
|
|
|
TIM_HandleTypeDef htim4;
|
|
|
+TIM_HandleTypeDef htim8;
|
|
|
|
|
|
UART_HandleTypeDef huart8;
|
|
|
UART_HandleTypeDef huart1;
|
|
@@ -143,6 +146,8 @@ static void MX_TIM3_Init(void);
|
|
|
static void MX_DAC1_Init(void);
|
|
|
static void MX_COMP1_Init(void);
|
|
|
static void MX_TIM4_Init(void);
|
|
|
+static void MX_TIM8_Init(void);
|
|
|
+static void MX_IWDG1_Init(void);
|
|
|
void StartDefaultTask(void *argument);
|
|
|
void debugLedTimerCallback(void *argument);
|
|
|
void fanTimerCallback(void *argument);
|
|
@@ -230,8 +235,10 @@ int main(void)
|
|
|
MX_DAC1_Init();
|
|
|
MX_COMP1_Init();
|
|
|
MX_TIM4_Init();
|
|
|
+ MX_TIM8_Init();
|
|
|
+ MX_IWDG1_Init();
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
-
|
|
|
+// HAL_IWDG_Refresh(&hiwdg1);
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
/* Init scheduler */
|
|
@@ -272,7 +279,7 @@ int main(void)
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_THREADS */
|
|
|
/* add threads, ... */
|
|
|
-// Uart8TasksInit();
|
|
|
+ HAL_IWDG_Refresh(&hiwdg1);
|
|
|
UartTasksInit();
|
|
|
#ifdef USER_MOCKS
|
|
|
MockMeasurmetsTaskInit();
|
|
@@ -323,8 +330,10 @@ void SystemClock_Config(void)
|
|
|
/** Initializes the RCC Oscillators according to the specified parameters
|
|
|
* in the RCC_OscInitTypeDef structure.
|
|
|
*/
|
|
|
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE;
|
|
|
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_LSI
|
|
|
+ |RCC_OSCILLATORTYPE_HSE;
|
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
|
+ RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
|
|
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
|
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
@@ -416,7 +425,7 @@ static void MX_ADC1_Init(void)
|
|
|
hadc1.Init.ContinuousConvMode = ENABLE;
|
|
|
hadc1.Init.NbrOfConversion = 7;
|
|
|
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
|
|
- hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T2_TRGO;
|
|
|
+ hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T8_TRGO;
|
|
|
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
|
|
|
hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
|
|
|
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
|
@@ -540,7 +549,7 @@ static void MX_ADC2_Init(void)
|
|
|
hadc2.Init.ContinuousConvMode = ENABLE;
|
|
|
hadc2.Init.NbrOfConversion = 3;
|
|
|
hadc2.Init.DiscontinuousConvMode = DISABLE;
|
|
|
- hadc2.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T2_TRGO;
|
|
|
+ hadc2.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T8_TRGO;
|
|
|
hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
|
|
|
hadc2.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
|
|
|
hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
|
@@ -619,7 +628,7 @@ static void MX_ADC3_Init(void)
|
|
|
hadc3.Init.ContinuousConvMode = ENABLE;
|
|
|
hadc3.Init.NbrOfConversion = 5;
|
|
|
hadc3.Init.DiscontinuousConvMode = DISABLE;
|
|
|
- hadc3.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T2_TRGO;
|
|
|
+ hadc3.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T8_TRGO;
|
|
|
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
|
|
|
hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
|
|
|
hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
|
@@ -806,6 +815,35 @@ static void MX_DAC1_Init(void)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @brief IWDG1 Initialization Function
|
|
|
+ * @param None
|
|
|
+ * @retval None
|
|
|
+ */
|
|
|
+static void MX_IWDG1_Init(void)
|
|
|
+{
|
|
|
+
|
|
|
+ /* USER CODE BEGIN IWDG1_Init 0 */
|
|
|
+
|
|
|
+ /* USER CODE END IWDG1_Init 0 */
|
|
|
+
|
|
|
+ /* USER CODE BEGIN IWDG1_Init 1 */
|
|
|
+
|
|
|
+ /* USER CODE END IWDG1_Init 1 */
|
|
|
+ hiwdg1.Instance = IWDG1;
|
|
|
+ hiwdg1.Init.Prescaler = IWDG_PRESCALER_64;
|
|
|
+ hiwdg1.Init.Window = 249;
|
|
|
+ hiwdg1.Init.Reload = 249;
|
|
|
+ if (HAL_IWDG_Init(&hiwdg1) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ /* USER CODE BEGIN IWDG1_Init 2 */
|
|
|
+
|
|
|
+ /* USER CODE END IWDG1_Init 2 */
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* @brief RNG Initialization Function
|
|
|
* @param None
|
|
|
* @retval None
|
|
@@ -922,9 +960,9 @@ static void MX_TIM2_Init(void)
|
|
|
|
|
|
/* USER CODE END TIM2_Init 1 */
|
|
|
htim2.Instance = TIM2;
|
|
|
- htim2.Init.Prescaler = 0;
|
|
|
+ htim2.Init.Prescaler = 9999;
|
|
|
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
|
- htim2.Init.Period = 9999999;
|
|
|
+ htim2.Init.Period = 2999;
|
|
|
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV2;
|
|
|
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
|
|
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
|
|
@@ -1050,10 +1088,10 @@ static void MX_TIM4_Init(void)
|
|
|
|
|
|
/* USER CODE END TIM4_Init 1 */
|
|
|
htim4.Instance = TIM4;
|
|
|
- htim4.Init.Prescaler = 19999;
|
|
|
+ htim4.Init.Prescaler = 9999;
|
|
|
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
|
- htim4.Init.Period = 9999;
|
|
|
- htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
|
+ htim4.Init.Period = 2999;
|
|
|
+ htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV2;
|
|
|
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
|
|
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
|
|
|
{
|
|
@@ -1093,6 +1131,53 @@ static void MX_TIM4_Init(void)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @brief TIM8 Initialization Function
|
|
|
+ * @param None
|
|
|
+ * @retval None
|
|
|
+ */
|
|
|
+static void MX_TIM8_Init(void)
|
|
|
+{
|
|
|
+
|
|
|
+ /* USER CODE BEGIN TIM8_Init 0 */
|
|
|
+
|
|
|
+ /* USER CODE END TIM8_Init 0 */
|
|
|
+
|
|
|
+ TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
|
+ TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
|
+
|
|
|
+ /* USER CODE BEGIN TIM8_Init 1 */
|
|
|
+
|
|
|
+ /* USER CODE END TIM8_Init 1 */
|
|
|
+ htim8.Instance = TIM8;
|
|
|
+ htim8.Init.Prescaler = 9999;
|
|
|
+ htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
|
+ htim8.Init.Period = 999;
|
|
|
+ htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV2;
|
|
|
+ htim8.Init.RepetitionCounter = 0;
|
|
|
+ htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
|
|
+ if (HAL_TIM_Base_Init(&htim8) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
|
+ if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
|
|
|
+ sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
|
|
|
+ sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
|
|
|
+ if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ /* USER CODE BEGIN TIM8_Init 2 */
|
|
|
+
|
|
|
+ /* USER CODE END TIM8_Init 2 */
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* @brief UART8 Initialization Function
|
|
|
* @param None
|
|
|
* @retval None
|
|
@@ -1322,20 +1407,25 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
|
|
|
|
|
|
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
|
|
|
{
|
|
|
+#if 0
|
|
|
if (htim->Instance == TIM4)
|
|
|
{
|
|
|
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3)
|
|
|
{
|
|
|
- encoderXChannelA = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3);
|
|
|
+ encoderXChannelA += HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3) + 1;
|
|
|
} else if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4)
|
|
|
{
|
|
|
- encoderXChannelB = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
|
|
|
+ encoderXChannelB += HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4) + 1;
|
|
|
}
|
|
|
if((encoderXChannelA != 0) && (encoderXChannelB != 0))
|
|
|
{
|
|
|
EncoderData encoderData = { 0 };
|
|
|
encoderData.axe = encoderAxeX;
|
|
|
encoderData.direction = encoderXChannelA - encoderXChannelB < 0 ? encoderCW : encoderCCW;
|
|
|
+ if (encoderData.direction == encoderCCW)
|
|
|
+ {
|
|
|
+ asm("nop;");
|
|
|
+ }
|
|
|
osMessageQueuePut(encoderXDataQueue, &encoderData, 0, 0);
|
|
|
encoderXChannelA = 0;
|
|
|
encoderXChannelB = 0;
|
|
@@ -1344,10 +1434,10 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
|
|
|
{
|
|
|
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3)
|
|
|
{
|
|
|
- encoderYChannelA = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3);
|
|
|
+ encoderYChannelA += HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3) + 1;
|
|
|
} else if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4)
|
|
|
{
|
|
|
- encoderYChannelB = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
|
|
|
+ encoderYChannelB += HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4) + 1;
|
|
|
}
|
|
|
if((encoderYChannelA != 0) && (encoderYChannelB != 0))
|
|
|
{
|
|
@@ -1359,6 +1449,88 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
|
|
|
encoderYChannelB = 0;
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
+ if (htim->Instance == TIM4)
|
|
|
+ {
|
|
|
+ if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3)
|
|
|
+ {
|
|
|
+ if(encoderXChannelB > 0)
|
|
|
+ {
|
|
|
+ encoderXChannelA = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ encoderXChannelA = 1;
|
|
|
+ __HAL_TIM_SET_COUNTER(htim,0);
|
|
|
+ }
|
|
|
+ } else if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4)
|
|
|
+ {
|
|
|
+ if(encoderXChannelA > 0)
|
|
|
+ {
|
|
|
+ encoderXChannelB = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ encoderXChannelB = 1;
|
|
|
+ __HAL_TIM_SET_COUNTER(htim,0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if((encoderXChannelA != 0) && (encoderXChannelB != 0))
|
|
|
+ {
|
|
|
+ EncoderData encoderData = { 0 };
|
|
|
+ encoderData.axe = encoderAxeX;
|
|
|
+ encoderData.direction = encoderXChannelA - encoderXChannelB < 0 ? encoderCW : encoderCCW;
|
|
|
+ if (encoderData.direction == encoderCCW)
|
|
|
+ {
|
|
|
+ asm("nop;");
|
|
|
+ }
|
|
|
+ osMessageQueuePut(encoderDataQueue, &encoderData, 0, 0);
|
|
|
+ encoderXChannelA = 0;
|
|
|
+ encoderXChannelB = 0;
|
|
|
+ }
|
|
|
+ } else if (htim->Instance == TIM2)
|
|
|
+ {
|
|
|
+ if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3)
|
|
|
+ {
|
|
|
+ if(encoderYChannelB > 0)
|
|
|
+ {
|
|
|
+ encoderYChannelA = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_3);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ encoderYChannelA = 1;
|
|
|
+ __HAL_TIM_SET_COUNTER(htim,0);
|
|
|
+ }
|
|
|
+ } else if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4)
|
|
|
+ {
|
|
|
+ if(encoderYChannelA > 0)
|
|
|
+ {
|
|
|
+ encoderYChannelB = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ encoderYChannelB = 1;
|
|
|
+ __HAL_TIM_SET_COUNTER(htim,0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if((encoderYChannelA != 0) && (encoderYChannelB != 0))
|
|
|
+ {
|
|
|
+ EncoderData encoderData = { 0 };
|
|
|
+ encoderData.axe = encoderAxeY;
|
|
|
+ encoderData.direction = encoderYChannelA - encoderYChannelB < 0 ? encoderCW : encoderCCW;
|
|
|
+ if (encoderData.direction == encoderCCW)
|
|
|
+ {
|
|
|
+ asm("nop;");
|
|
|
+ }
|
|
|
+ if (encoderData.direction == encoderCW)
|
|
|
+ {
|
|
|
+ asm("nop;");
|
|
|
+ }
|
|
|
+ osMessageQueuePut(encoderDataQueue, &encoderData, 0, 0);
|
|
|
+ encoderYChannelA = 0;
|
|
|
+ encoderYChannelB = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* USER CODE END 4 */
|
|
@@ -1373,12 +1545,18 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
|
|
|
void StartDefaultTask(void *argument)
|
|
|
{
|
|
|
/* USER CODE BEGIN 5 */
|
|
|
+ HAL_IWDG_Refresh(&hiwdg1);
|
|
|
SelectCurrentSensorGain(CurrentSensorL1, csGain3);
|
|
|
SelectCurrentSensorGain(CurrentSensorL2, csGain3);
|
|
|
SelectCurrentSensorGain(CurrentSensorL3, csGain3);
|
|
|
EnableCurrentSensors();
|
|
|
- osDelay(pdMS_TO_TICKS(1000));
|
|
|
- if(HAL_TIM_Base_Start(&htim2) != HAL_OK)
|
|
|
+ osDelay(pdMS_TO_TICKS(100));
|
|
|
+ HAL_IWDG_Refresh(&hiwdg1);
|
|
|
+ if(HAL_TIM_Base_Start(&htim8) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ if(HAL_TIM_Base_Start_IT(&htim2) != HAL_OK)
|
|
|
{
|
|
|
Error_Handler();
|
|
|
}
|
|
@@ -1415,10 +1593,12 @@ void StartDefaultTask(void *argument)
|
|
|
Error_Handler();
|
|
|
}
|
|
|
HAL_COMP_Start(&hcomp1);
|
|
|
+ HAL_IWDG_Refresh(&hiwdg1);
|
|
|
/* Infinite loop */
|
|
|
for(;;)
|
|
|
{
|
|
|
osDelay(pdMS_TO_TICKS(100));
|
|
|
+ HAL_IWDG_Refresh(&hiwdg1);
|
|
|
if(HAL_TIM_GetChannelState(&htim3, TIM_CHANNEL_1) == HAL_TIM_CHANNEL_STATE_READY &&
|
|
|
HAL_TIM_GetChannelState(&htim3, TIM_CHANNEL_2) == HAL_TIM_CHANNEL_STATE_READY)
|
|
|
{
|
|
@@ -1548,24 +1728,42 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
|
/* USER CODE BEGIN Callback 1 */
|
|
|
else if (htim->Instance == TIM4)
|
|
|
{
|
|
|
- if(encoderXChannelA > 0)
|
|
|
- {
|
|
|
- encoderXChannelB += htim->Instance->ARR;
|
|
|
- } else if(encoderXChannelB > 0)
|
|
|
- {
|
|
|
- encoderXChannelA += htim->Instance->ARR;
|
|
|
- }
|
|
|
+ encoderXChannelA = 0;
|
|
|
+ encoderXChannelB = 0;
|
|
|
}
|
|
|
else if (htim->Instance == TIM2)
|
|
|
{
|
|
|
- if(encoderYChannelA > 0)
|
|
|
- {
|
|
|
- encoderYChannelB += htim->Instance->ARR;
|
|
|
- } else if(encoderYChannelB > 0)
|
|
|
- {
|
|
|
- encoderYChannelA += htim->Instance->ARR;
|
|
|
- }
|
|
|
- }
|
|
|
+ encoderYChannelA = 0;
|
|
|
+ encoderYChannelB = 0;
|
|
|
+ }
|
|
|
+// else if (htim->Instance == TIM4)
|
|
|
+// {
|
|
|
+// if((encoderXChannelA > 0) && (encoderXChannelB == 0))
|
|
|
+// {
|
|
|
+// encoderXChannelB += htim->Instance->ARR;
|
|
|
+// } else if((encoderXChannelB > 0) && (encoderXChannelA == 0 ))
|
|
|
+// {
|
|
|
+// encoderXChannelA += htim->Instance->ARR;
|
|
|
+// } else
|
|
|
+// {
|
|
|
+// encoderXChannelA = 0;
|
|
|
+// encoderXChannelB = 0;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if (htim->Instance == TIM2)
|
|
|
+// {
|
|
|
+// if((encoderYChannelA > 0) && (encoderYChannelB == 0))
|
|
|
+// {
|
|
|
+// encoderYChannelB += htim->Instance->ARR;
|
|
|
+// } else if((encoderYChannelB > 0) && (encoderYChannelA == 0))
|
|
|
+// {
|
|
|
+// encoderYChannelA += htim->Instance->ARR;
|
|
|
+// } else
|
|
|
+// {
|
|
|
+// encoderYChannelA = 0;
|
|
|
+// encoderYChannelB = 0;
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
/* USER CODE END Callback 1 */
|
|
|
}
|