最终版本

This commit is contained in:
2024-11-10 16:25:19 +08:00
commit a103bb171f
348 changed files with 345556 additions and 0 deletions

353
app/app.c Normal file
View File

@@ -0,0 +1,353 @@
#include <string.h>
#include "app.h"
#include "usart.h"
#include "gpio.h"
#include "lorawan_node_driver.h"
#include "hdc1000.h"
#include "sensors_test.h"
#include "ST7789v.h"
#include "XPT2046.h"
#include "opt3001.h"
#include "MPL3115.h"
#include "rtc.h"
#define DEBUG 1
#define DBGPrint \
if (DEBUG) \
debug_printf
extern DEVICE_MODE_T device_mode;
extern DEVICE_MODE_T *Device_Mode_str;
down_list_t *pphead = NULL;
void LoRaWAN_Func_Process(void);
uint8_t joinNetwork = 0;
char receive[20] = "";
void DisplayStatus(void);
void SyncRTCTime(void);
void BackupStrategy(void);
void ParseReceiveString(void);
void LoRaWAN_Init(void);
void print_business_data(down_list_t **list_head);
#define MAX_RECORDS 48 // ??48?????30??????24??
typedef struct {
uint16_t temp;
uint16_t humi;
float pressure;
RTC_TimeTypeDef rtc_time;
uint8_t rain_flag; // ?????1?????0?????
} SensorData;
SensorData records[MAX_RECORDS];
uint8_t record_index = 0;
typedef struct {
uint16_t temp;
uint16_t humi;
float pressure;
int count;
} TempData;
TempData tempDataBuffer = {0};
RTC_TimeTypeDef firstRecordTime;
RTC_DateTypeDef firstRecordDate;
struct sensors_data_t
{
uint16_t temp, humi;
float pressure;
};
//-----------------Users application--------------------------
void LoRaWAN_Func_Process(void)
{
uint16_t temp, humi;
float pressure;
float lux;
RTC_TimeTypeDef curTime;
RTC_DateTypeDef curDate;
static uint8_t last_record_index = 0;
DBGPrint("\n??????\n");
if (!joinNetwork)
{
DBGPrint("???????\n");
joinNetwork = 1;
if (nodeJoinNet(JOIN_TIME_120_SEC) == false)
{
DBGPrint("???????\r\n");
joinNetwork = 0;
}
}
if (joinNetwork)
{
SyncRTCTime();
if (UART_TO_LRM_RECEIVE_FLAG)
{
DBGPrint("??????...\n");
UART_TO_LRM_RECEIVE_FLAG = 0;
memset(receive, '\0', sizeof(receive));
for (int i = 0; i < (LPUsart1_RX.rx_len - ((UART_TO_LRM_RECEIVE_BUFFER[135] >= ' ' && UART_TO_LRM_RECEIVE_BUFFER[135] <= '~') ? 0x0087 : 0x0088)); i++)
{
receive[i] = UART_TO_LRM_RECEIVE_BUFFER[i + ((UART_TO_LRM_RECEIVE_BUFFER[135] >= ' ' && UART_TO_LRM_RECEIVE_BUFFER[135] <= '~') ? 135 : 136)];
}
ParseReceiveString();
}
temp = HDC1000_Read_Temper();
humi = HDC1000_Read_Humidi();
pressure = MPL3115_ReadPressure();
lux = OPT3001_Get_Lux();
// ?????????????
tempDataBuffer.temp += temp;
tempDataBuffer.humi += humi;
tempDataBuffer.pressure += pressure;
tempDataBuffer.count++;
HAL_RTC_GetTime(&hrtc, &curTime, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &curDate, RTC_FORMAT_BIN);
if (tempDataBuffer.count == 1)
{
firstRecordTime = curTime;
firstRecordDate = curDate;
}
if ((curDate.Date * 24 * 60 + curTime.Hours * 60 + curTime.Minutes) -
(firstRecordDate.Date * 24 * 60 + firstRecordTime.Hours * 60 + firstRecordTime.Minutes) >= 30)
{
// ????????
records[record_index].temp = tempDataBuffer.temp / tempDataBuffer.count;
records[record_index].humi = tempDataBuffer.humi / tempDataBuffer.count;
records[record_index].pressure = tempDataBuffer.pressure / tempDataBuffer.count;
records[record_index].rtc_time = curTime;
// ????????
if (record_index > 0)
{
int prev_index = (record_index - 1 + MAX_RECORDS) % MAX_RECORDS;
int16_t temp_diff = records[prev_index].temp - records[record_index].temp;
// ???1??????Records???2???????????90%?????100000Pa
records[record_index].rain_flag = (temp_diff >= 2000 && records[record_index].humi > 90000 && records[record_index].pressure < 100000) ? 1 : 0;
}
else
{
records[record_index].rain_flag = 0;
}
// ??????????
last_record_index = record_index;
record_index = (record_index + 1) % MAX_RECORDS; // ??????
// ?????????
memset(&tempDataBuffer, 0, sizeof(tempDataBuffer));
}
// ????24????????2??????????
uint8_t rain_count = 0;
uint8_t continuous_rain = 0;
for (int i = 0; i < MAX_RECORDS; i++)
{
int index = (record_index - 1 - i + MAX_RECORDS) % MAX_RECORDS;
if (records[index].rain_flag)
{
rain_count++;
if (rain_count >= 4) // 4?????2????30???????
{
continuous_rain = 1;
break;
}
}
else
{
rain_count = 0; // ??????
}
}
char buffer[1024] = "";
if (continuous_rain) // ????2????
{
sprintf(buffer, "T:%d,%d\nH:%d,%d\nP:%.2f\nL:%.2f\nR:1\n", temp / 1000, temp % 1000, humi / 1000, humi % 1000, pressure / 1000, lux);
}
else
{
sprintf(buffer, "T:%d,%d\nH:%d,%d\nP:%.2f\nL:%.2f\nR:0\n", temp / 1000, temp % 1000, humi / 1000, humi % 1000, pressure / 1000, lux);
}
DBGPrint(buffer);
nodeDataCommunicate((uint8_t*)&buffer, strlen(buffer), &pphead);
print_business_data(&pphead);
}
BackupStrategy();
DisplayStatus();
HAL_Delay(1000);
}
void BackupStrategy(void)
{
uint16_t temp, humi;
float pressure;
float lux;
temp = HDC1000_Read_Temper();
humi = HDC1000_Read_Humidi();
pressure = MPL3115_ReadPressure();
lux = OPT3001_Get_Lux();
// TODO: ??????????????????LED????????????????????
HAL_GPIO_WritePin(LedGpio_D7, LedPin_D7, GPIO_PIN_RESET); // ??LED?????????
HAL_GPIO_WritePin(LedGpio_D8, LedPin_D8, GPIO_PIN_RESET); // ??LED?????????
HAL_GPIO_WritePin(LedGpio_D6, LedPin_D6, GPIO_PIN_RESET); // ??LED?????????
if (temp / 1000 < 15)
{
HAL_GPIO_WritePin(LedGpio_D7, LedPin_D7, GPIO_PIN_SET); // ????15??????LED
}
if (humi / 1000 < 40)
{
HAL_GPIO_WritePin(LedGpio_D8, LedPin_D8, GPIO_PIN_SET); // ????40%?????LED
}
if (temp / 1000 > 25 || humi / 1000 > 60)
{
HAL_GPIO_WritePin(LedGpio_D6, LedPin_D6, GPIO_PIN_SET); // ????25??????60%?????LED
}
}
void SyncRTCTime(void)
{
uint8_t tbuff[25] = {0};
uint8_t tm[25] = {0};
RTC_TimeTypeDef Ptime;
RTC_DateTypeDef Pdate;
DBGPrint("??RTC??...\r\n");
nodeCmdConfig("AT+TIMESYNC\r\n");
nodeCmdInqiure("AT+RTC?\r\n", tbuff);
for (int i = 0, j = 0; i < strlen(tbuff); i++)
{
if (tbuff[i] != ' ')
tm[j++] = tbuff[i];
if (j == 12)
break;
}
RTC_TimeTypeDef oldTime;
HAL_RTC_GetTime(&hrtc, &oldTime, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &Pdate, RTC_FORMAT_BIN);
Pdate.Year = (uint8_t)tm[0] * 10 + (uint8_t)tm[1] - 16;
Pdate.Month = (uint8_t)tm[2] * 10 + (uint8_t)tm[3] - 16;
Pdate.Date = (uint8_t)tm[4] * 10 + (uint8_t)tm[5] - 16;
Ptime.Hours = (uint8_t)tm[6] * 10 + (uint8_t)tm[7] - 16;
Ptime.Minutes = (uint8_t)tm[8] * 10 + (uint8_t)tm[9] - 16;
Ptime.Seconds = (uint8_t)tm[10] * 10 + (uint8_t)tm[11] - 16;
// ???????????
if (Pdate.Year == 24 && Pdate.Month <= 12 && Pdate.Date <= 31 && Ptime.Hours <= 23 && Ptime.Minutes <= 59 && Ptime.Seconds <= 59)
{
HAL_RTC_SetTime(&hrtc, &Ptime, RTC_FORMAT_BIN);
HAL_RTC_SetDate(&hrtc, &Pdate, RTC_FORMAT_BIN);
DBGPrint("RTC??????: %d-%d-%d %d:%d:%d\r\n", Pdate.Year, Pdate.Month, Pdate.Date, Ptime.Hours, Ptime.Minutes, Ptime.Seconds);
}
else {
DBGPrint("RTC?????????: %d-%d-%d %d:%d:%d\r\n", Pdate.Year, Pdate.Month, Pdate.Date, Ptime.Hours, Ptime.Minutes, Ptime.Seconds);
}
}
void DisplayStatus(void)
{
RTC_TimeTypeDef time;
RTC_DateTypeDef date;
uint16_t temp, humi;
float pressure;
float lux;
// ???????
temp = HDC1000_Read_Temper();
humi = HDC1000_Read_Humidi();
pressure = MPL3115_ReadPressure();
lux = OPT3001_Get_Lux();
LCD_Fill(0, 0, 239, 36, BLUE);
char tempStr[20];
sprintf(tempStr, "??: %d.%d <20>C", temp / 1000, temp % 1000);
LCD_ShowString(10, 10, tempStr, BLACK);
lpusart1_send_string((uint8_t *)tempStr); // ??????
LCD_Fill(0, 37, 239, 73, BLUE);
char humiStr[20];
sprintf(humiStr, "??: %d.%d %%", humi / 1000, humi % 1000);
LCD_ShowString(10, 47, humiStr, BLACK);
lpusart1_send_string((uint8_t *)humiStr); // ??????
LCD_Fill(0, 74, 239, 110, BLUE);
char pressureStr[20];
sprintf(pressureStr, "??: %.2f Pa", pressure);
LCD_ShowString(10, 84, pressureStr, BLACK);
lpusart1_send_string((uint8_t *)pressureStr); // ??????
LCD_Fill(0, 111, 239, 147, BLUE);
char luxStr[20];
sprintf(luxStr, "Lux: %.2f lx", lux);
LCD_ShowString(10, 121, luxStr, BLACK);
lpusart1_send_string((uint8_t *)luxStr); // ???????????
// LCD_Clear(0xbefe);
// LCD_Clear(0xbefe);
}
void ParseReceiveString(void){
DBGPrint("\nReceived Data: \n%s\n", receive);
}
void LoRaWAN_Init(void){
nodeCmdConfig("AT+CLASS=2\r\n");
nodeCmdConfig("AT+RX2=0,505300000\r\n");
nodeCmdConfig("AT+SAVE\r\n");
nodeCmdConfig("AT+RESET\r\n");
}
void print_business_data(down_list_t **list_head) {
down_list_t *current = *list_head;
const char *target_data = "****CLASSC 1234567890****";
size_t target_length = strlen(target_data); // ????????
DBGPrint("Print Business Data\n");
while (current != NULL) {
// ????????
DBGPrint("Data: %.*s*****************\n", current->down_info.size, current->down_info.business_data);
// ?????????????????
if (current->down_info.size >= target_length &&
memcmp(current->down_info.business_data, target_data, target_length) == 0) {
DBGPrint("Result: VALIDATED\n");
} else {
DBGPrint("Result: INVALID\n");
}
current = current->next;
}
}
void LoRaWAN_Board_Info_Print(void)
{
debug_printf("\r\n\r\n");
PRINT_CODE_VERSION_INFO("%s", CODE_VERSION);
LEDALL_ON;
HAL_Delay(100);
LEDALL_OFF;
}

238
app/main.c Normal file
View File

@@ -0,0 +1,238 @@
/**
* @mainpage <09><><EFBFBD><EFBFBD>
* @author Lierda-WSN-LoRaWAN-TEAM
* @version V1.0.3
* @date 2020-08-30
*
* LoRaWAN_TRAIN <20>ǻ<EFBFBD><C7BB><EFBFBD>LoRaWANЭ<4E><D0AD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA3AC>ʵ<EFBFBD><CAB5><EFBFBD>ն<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>LoRaWAN<41><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>á<EFBFBD><C3A1><EFBFBD>Ҫ<EFBFBD>ļ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>
* - 1. ICAģ<41><EFBFBD><E9B9A4>ģʽ<C4A3><EFBFBD><EBB9A4>״̬<D7B4><CCAC><EFBFBD>ƽӿ<C6BD>
* - <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>л<EFBFBD>
* - ָ<><D6B8><EFBFBD><EFBFBD>͸<EFBFBD><CDB8>ģʽ<C4A3><CABD><EFBFBD>л<EFBFBD>
* - 2. ATָ<54><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ýӿ<C3BD>
* - 3. <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
* - 4. <20><><EFBFBD>ݷ<EFBFBD><DDB7>ͽӿ<CDBD>
* - 5. <20><><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD>ͽӿڣ<D3BF><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>ն˵IJ<CBB5><C4B2>ְ<EFBFBD>Э<EFBFBD>
*
* @section application_arch 01 ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>
*
* LoRaWAN ICA Node Driver<65><72><EFBFBD><EFBFBD>ʹ<EFBFBD>÷<EFBFBD>ʽ<EFBFBD><CABD>
* @image html LoRaWAN_ICA-Module-driver.png "Figure 1: Uart driver of ICA Node
*
* @section LoRaWAN_ICA_Node_Driver API
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD> @ref ICA-Driver
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32l4xx_hal.h"
#include "stm32l4xx_it.h"
#include "lorawan_node_driver.h"
#include "usart.h"
#include "dma.h"
#include "rtc.h"
#include "app.h"
#include "gpio.h"
#include "tim.h"
#include "i2c.h"
#include "hdc1000.h"
#include "opt3001.h"
#include "MPL3115.h"
#include "mma8451.h"
#include "ST7789v.h"
#include "XPT2046.h"
#include "math.h"
/* USER CODE BEGIN 0 */
char dateStr[16]; // <20><><EFBFBD>ڴ洢<DAB4><E6B4A2>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
char timeStr[16];
char DEVEUI[32] = "0";
char APPEUI[32] = "0";
char APPKEY[64] = "0";
int positions1[] = {3, 4, 5, 6, 7, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23, 24, 26, 27, 29, 30, 32, 33};
int positions2[] = {43, 44, 45, 46, 47, 48, 49, 51, 52, 54, 55, 57, 58, 60, 61, 63, 64, 66, 67, 69, 70, 72, 73};
int positions3[] = {83, 84, 85, 86, 87, 88, 89, 91, 92, 94, 95, 97, 98, 100, 101, 103, 104, 106, 107, 109, 110, 112, 113, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 130, 131, 133, 134, 136, 137};
char buffer1[] = "AT+DEVEUI?\r\nAT+APPEUI?\r\nAT+APPKEY?\r\n";
char buffer2[] = "AT+DEVEUI=0095690000027B34,D391010220102816,1\r\n";
char buffer3[] = "AT+APPEUI=C7E70A4A90F9B346\r\n";
char buffer4[] = "AT+APPKEY=927AD9A98925A5527E4EF71C5FB99CE0,0\r\n";
uint8_t i = 0;
char parameter[] = {0};
u16 pos_temp; // <20><><EFBFBD><EFBFBD><EABBBA>ֵ
u16 pos_temp1; // <20><><EFBFBD><EFBFBD><EABBBA>ֵ
extern Pen_Holder Pen_Point; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>
/* USER CODE END 0 */
/**
* @brief The application entry point.
*
* @retval None
*/
int main(void)
{
HAL_Init();
/** ϵͳʱ<CDB3><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
SystemClock_Config();
/** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
MX_GPIO_Init();
MX_DMA_Init();
MX_RTC_Init();
/** <20><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC> */
MX_LPUART1_Init(9600); // MCU<43><55>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MX_USART2_Init(115200); // MCU<43><55>PC<50><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MX_I2C1_Init();
HAL_Delay(20);
LPUART1_Clear_IT(); // <20><><EFBFBD><EFBFBD><EFBFBD>жϲ<D0B6><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
USART2_Clear_IT(); // <20><><EFBFBD><EFBFBD><EFBFBD>жϲ<D0B6><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
/** <20><>ʪ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD> */
HDC1000_Init();
/** <20><>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
OPT3001_Init();
/** <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
MPL3115_Init(MODE_BAROMETER);
/** <20><><EFBFBD>ٶȴ<D9B6><C8B4><EFBFBD><EFBFBD><EFBFBD> */
MMA8451_Init();
/** Һ<><D2BA> */
LCD_Init();
/** <20><>λģ<CEBB><C4A3> */
HAL_Delay(500); // ģ<><C4A3><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1>
Node_Hard_Reset();
LoRaWAN_Board_Info_Print();
LoRaWAN_Init();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
LoRaWAN_Func_Process();
}
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
/* PWR CLOCK ENABLE*/
__PWR_CLK_ENABLE();
/**Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI;
// RCC_OscInitStruct.LSEState = RCC_LSE_ON ;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 10;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; // PLLCLK = HSI*N/M/R = 80MHz
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/**Initializes the CPU, AHB and APB busses clocks */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // select the PLL as the system clock source
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // AHB prescaler
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; // APB1 prescaler
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // APB2 prescaler
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_RTC;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_HSI;
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/**Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); // 1ms <20>ж<EFBFBD>һ<EFBFBD><D2BB>
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @param file: The file name as string.
* @param line: The line in file as a number.
* @retval None
*/
void _Error_Handler(char *file, int line)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
while (1)
{
}
/* 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(uint8_t *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****/

BIN
app/mainpage.h Normal file

Binary file not shown.