367 lines
9.3 KiB
C
367 lines
9.3 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file : main.c
|
|
* @brief : Main program body
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
|
* All rights reserved.</center></h2>
|
|
*
|
|
* This software component is licensed by ST under Ultimate Liberty license
|
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at:
|
|
* www.st.com/SLA0044
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
#include "includes.h"
|
|
|
|
const uint8_t CONFIG_BOARD_SELF = CONFIG_BOARD_SINGLE;
|
|
|
|
// 配置外设引脚、时钟等
|
|
static void Modules_Init()
|
|
{
|
|
Vcc_Init();
|
|
Console_Init();
|
|
Config_Init();
|
|
//DAC7311_Init();
|
|
Wakeup_Init();
|
|
//Wakeup_Open();
|
|
//Slave_Init();
|
|
//Sensor_Init();
|
|
//Accelero_Init();
|
|
Sample_Init();
|
|
Battery_Init();
|
|
//DTU_Init();
|
|
Key_Init();
|
|
LCD_Init();
|
|
Watchdog_Init();
|
|
}
|
|
|
|
// 打开外设,配置中断等
|
|
static void Modules_Open()
|
|
{
|
|
Console_Open();
|
|
Config_Open();
|
|
// DAC7311_Open();
|
|
// Slave_Open();
|
|
// Sensor_Open(19200);
|
|
// Accelero_Open();
|
|
Wakeup_Open();
|
|
Sample_Open();
|
|
Battery_Open();
|
|
// DTU_Open();
|
|
Key_Open();
|
|
LCD_MyOpen(); // form.h
|
|
Watchdog_Open();
|
|
}
|
|
|
|
|
|
osThreadId_t defaultTaskHandle;
|
|
osThreadId_t lcdTaskHandle;
|
|
osThreadId_t sampleTaskHandle;
|
|
osThreadId_t matchTaskHandle;
|
|
|
|
/* USER CODE BEGIN PV */
|
|
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
void SystemClock_Config(void);
|
|
void StartDefaultTask(void *argument);
|
|
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
/**
|
|
* @brief The application entry point.
|
|
* @retval int
|
|
*/
|
|
int main(void)
|
|
{
|
|
/* USER CODE BEGIN 1 */
|
|
// 读取启动原因代码
|
|
Fetch_ResetFlags();
|
|
/* USER CODE END 1 */
|
|
|
|
|
|
/* MCU Configuration--------------------------------------------------------*/
|
|
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
HAL_Init();
|
|
|
|
/* USER CODE BEGIN Init */
|
|
|
|
/* USER CODE END Init */
|
|
|
|
/* Configure the system clock */
|
|
SystemClock_Config();
|
|
|
|
/* USER CODE BEGIN SysInit */
|
|
Modules_Init();
|
|
/* USER CODE END SysInit */
|
|
|
|
/* Initialize all configured peripherals */
|
|
/* USER CODE BEGIN 2 */
|
|
Modules_Open();
|
|
printf("\nSYS_RSTSTS = %d\n", SYS_RSTSTS);
|
|
/* USER CODE END 2 */
|
|
|
|
osKernelInitialize();
|
|
|
|
/* USER CODE BEGIN RTOS_MUTEX */
|
|
/* add mutexes, ... */
|
|
/* USER CODE END RTOS_MUTEX */
|
|
|
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
/* add semaphores, ... */
|
|
/* USER CODE END RTOS_SEMAPHORES */
|
|
|
|
/* USER CODE BEGIN RTOS_TIMERS */
|
|
/* start timers, add new ones, ... */
|
|
/* USER CODE END RTOS_TIMERS */
|
|
|
|
/* USER CODE BEGIN RTOS_QUEUES */
|
|
/* add queues, ... */
|
|
/* USER CODE END RTOS_QUEUES */
|
|
|
|
/* Create the thread(s) */
|
|
/* definition and creation of defaultTask */
|
|
const osThreadAttr_t defaultTask_attributes = {
|
|
.name = "defaultTask",
|
|
.priority = (osPriority_t) osPriorityNormal,
|
|
.stack_size = 2048
|
|
};
|
|
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
|
|
|
/* USER CODE BEGIN RTOS_THREADS */
|
|
/* add threads, ... */
|
|
const osThreadAttr_t lcdTask_attributes = {
|
|
.name = "lcdTask",
|
|
.priority = (osPriority_t) osPriorityNormal,
|
|
.stack_size = 1024
|
|
};
|
|
lcdTaskHandle = osThreadNew(Lcd_Task, NULL, &lcdTask_attributes);
|
|
|
|
const osThreadAttr_t sampleTask_attributes = {
|
|
.name = "sampleTask",
|
|
.priority = (osPriority_t) osPriorityNormal,
|
|
.stack_size = 1024
|
|
};
|
|
sampleTaskHandle = osThreadNew(Sample_Task, NULL, &sampleTask_attributes);
|
|
/* USER CODE END RTOS_THREADS */
|
|
|
|
/* Start scheduler */
|
|
osKernelStart();
|
|
|
|
/* We should never get here as control is now taken by the scheduler */
|
|
|
|
/* Infinite loop */
|
|
/* USER CODE BEGIN WHILE */
|
|
while (1)
|
|
{
|
|
/* USER CODE END WHILE */
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
}
|
|
/* USER CODE END 3 */
|
|
}
|
|
|
|
///**
|
|
// * @brief System Clock Configuration
|
|
// * @retval None
|
|
// */
|
|
//void SystemClock_Config(void)
|
|
//{
|
|
// LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
|
|
|
|
// if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_0)
|
|
// {
|
|
// Error_Handler();
|
|
// }
|
|
// LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
|
|
// LL_RCC_HSI_Enable();
|
|
|
|
// /* Wait till HSI is ready */
|
|
// while(LL_RCC_HSI_IsReady() != 1)
|
|
// {
|
|
//
|
|
// }
|
|
// LL_RCC_HSI_SetCalibTrimming(16);
|
|
// LL_RCC_LSI_Enable();
|
|
|
|
// /* Wait till LSI is ready */
|
|
// while(LL_RCC_LSI_IsReady() != 1)
|
|
// {
|
|
//
|
|
// }
|
|
// LL_PWR_EnableBkUpAccess();
|
|
// LL_RCC_ForceBackupDomainReset();
|
|
// LL_RCC_ReleaseBackupDomainReset();
|
|
// LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_LOW);
|
|
// LL_RCC_LSE_Enable();
|
|
|
|
// /* Wait till LSE is ready */
|
|
// while(LL_RCC_LSE_IsReady() != 1)
|
|
// {
|
|
//
|
|
// }
|
|
// LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
|
|
// LL_RCC_EnableRTC();
|
|
// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
|
|
|
|
// /* Wait till System clock is ready */
|
|
// while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
|
|
// {
|
|
//
|
|
// }
|
|
// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
|
|
// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
|
// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
|
|
// LL_SetSystemCoreClock(16000000);
|
|
// LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2);
|
|
// LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1);
|
|
// LL_RCC_SetUSARTClockSource(LL_RCC_USART2_CLKSOURCE_PCLK1);
|
|
// LL_RCC_SetUSARTClockSource(LL_RCC_USART3_CLKSOURCE_PCLK1);
|
|
// LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_SYSCLK);
|
|
//}
|
|
/**
|
|
* @brief System Clock Configuration
|
|
* @retval None
|
|
*/
|
|
void SystemClock_Config(void)
|
|
{
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
|
|
|
/** Configure the main internal regulator output voltage
|
|
*/
|
|
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Initializes the RCC Oscillators according to the specified parameters
|
|
* in the RCC_OscInitTypeDef structure.
|
|
*/
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_MSI;
|
|
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
|
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
|
|
RCC_OscInitStruct.MSICalibrationValue = 0;
|
|
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
// ?? LSI ?? RTC ???
|
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
|
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
|
|
|
|
/** Initializes the CPU, AHB and APB buses clocks
|
|
*/
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
}
|
|
/* USER CODE BEGIN 4 */
|
|
|
|
/* USER CODE END 4 */
|
|
|
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
|
/**
|
|
* @brief Function implementing the defaultTask thread.
|
|
* @param argument: Not used
|
|
* @retval None
|
|
*/
|
|
/* USER CODE END Header_StartDefaultTask */
|
|
void StartDefaultTask(void *argument)
|
|
{
|
|
/* USER CODE BEGIN 5 */
|
|
/* Infinite loop */
|
|
|
|
HT1621_AllOn();
|
|
delay_ms(1000);
|
|
// // 显示主界面
|
|
Form_Start();
|
|
|
|
// 主任务
|
|
DTU_Task(NULL);
|
|
/* USER CODE END 5 */
|
|
}
|
|
|
|
/**
|
|
* @brief Period elapsed callback in non blocking mode
|
|
* @note This function is called when TIM1 interrupt took place, inside
|
|
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
|
* a global variable "uwTick" used as application time base.
|
|
* @param htim : TIM handle
|
|
* @retval None
|
|
*/
|
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
{
|
|
/* USER CODE BEGIN Callback 0 */
|
|
|
|
/* USER CODE END Callback 0 */
|
|
if (htim->Instance == TIM1) {
|
|
HAL_IncTick();
|
|
}
|
|
/* USER CODE BEGIN Callback 1 */
|
|
|
|
/* USER CODE END Callback 1 */
|
|
}
|
|
|
|
/**
|
|
* @brief This function is executed in case of error occurrence.
|
|
* @retval None
|
|
*/
|
|
void Error_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN Error_Handler_Debug */
|
|
/* User can add his own implementation to report the HAL error return state */
|
|
|
|
/* USER CODE END Error_Handler_Debug */
|
|
}
|
|
|
|
#ifdef USE_FULL_ASSERT
|
|
/**
|
|
* @brief Reports the name of the source file and the source line number
|
|
* where the assert_param error has occurred.
|
|
* @param file: pointer to the source file name
|
|
* @param line: assert_param error line source number
|
|
* @retval None
|
|
*/
|
|
void assert_failed(char *file, uint32_t line)
|
|
{
|
|
/* USER CODE BEGIN 6 */
|
|
/* User can add his own implementation to report the file name and line number,
|
|
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
/* USER CODE END 6 */
|
|
}
|
|
#endif /* USE_FULL_ASSERT */
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|