From 73e638b44bd872bec1c4adc7187f8240c09cd05b Mon Sep 17 00:00:00 2001 From: Jan Thomas <jan.thomas.118@gmail.com> Date: Wed, 29 Jun 2022 16:41:25 +0200 Subject: [PATCH] =?UTF-8?q?Gruppenarbeit:=20=C3=84nderungen=20Display=20Co?= =?UTF-8?q?de?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../F413_Abschluss_Bildschirm/Core/Src/main.c | 591 ++++++++---------- 1 file changed, 269 insertions(+), 322 deletions(-) diff --git a/slave/F413_Abschluss_Bildschirm/Core/Src/main.c b/slave/F413_Abschluss_Bildschirm/Core/Src/main.c index 7ebbf2b..632e5cd 100644 --- a/slave/F413_Abschluss_Bildschirm/Core/Src/main.c +++ b/slave/F413_Abschluss_Bildschirm/Core/Src/main.c @@ -40,7 +40,7 @@ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ - SPI_HandleTypeDef hspi1; +SPI_HandleTypeDef hspi1; SPI_HandleTypeDef hspi4; UART_HandleTypeDef huart3; @@ -65,14 +65,49 @@ static void MX_SPI4_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ struct measurement { - float temp1; - float temp2; - float temp3; - float hum1; - float hum2; - float pressure; - uint8_t rain; - }; + float temp1; + float temp2; + float temp3; + float hum1; + float hum2; + float pressure; + uint8_t rain; +} measurement; + +void print_to_Display() +{ + // initialize buffers + char buffer_temp_1[50]; + char buffer_temp_2[50]; + char buffer_temp_3[50]; + char buffer_hum_1[50]; + char buffer_hum_2[50]; + char buffer_pressure[50]; + char buffer_rain[50]; + + // Set Rotation to horizontal + ST7735_SetRotation(1); + + // cast floats to string + sprintf(buffer_temp_1, "temp1: %.2f", measurement.temp1); + sprintf(buffer_temp_2, "temp2: %.2f", measurement.temp2); + sprintf(buffer_temp_3, "temp3: %.2f", measurement.temp3); + sprintf(buffer_hum_1, "hum1: %.2f", measurement.hum1); + sprintf(buffer_hum_2, "hum2: %.2f", measurement.hum2); + sprintf(buffer_pressure, "pressure: %.2f", measurement.pressure); + sprintf(buffer_rain, "rain: %s", measurement.rain ? "true" : "false"); + + // writre strings to Display + + ST7735_WriteString(0, 0, buffer_temp_1, Font_7x10, CYAN, BLACK); + ST7735_WriteString(0, 13, buffer_temp_2, Font_7x10, CYAN, BLACK); + ST7735_WriteString(0, 26, buffer_temp_3, Font_7x10, CYAN, BLACK); + ST7735_WriteString(0, 39, buffer_hum_1, Font_7x10, CYAN, BLACK); + ST7735_WriteString(0, 52, buffer_hum_2, Font_7x10, CYAN, BLACK); + ST7735_WriteString(0, 65, buffer_pressure, Font_7x10, CYAN, BLACK); + ST7735_WriteString(0, 78, buffer_rain, Font_7x10, CYAN, BLACK); + +}; /* USER CODE END 0 */ /** @@ -81,132 +116,51 @@ struct measurement { */ int main(void) { - /* USER CODE BEGIN 1 */ - - - /* 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 */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_USART3_UART_Init(); - MX_USB_OTG_FS_PCD_Init(); - MX_SPI1_Init(); - MX_SPI4_Init(); - /* USER CODE BEGIN 2 */ - - void print_to_Display(struct measurement measurement){ - // initialize buffers - char buffer_temp_1[50]; - char buffer_temp_2[50]; - char buffer_temp_3[50]; - char buffer_hum_1[50]; - char buffer_hum_2[50]; - char buffer_pressure[50]; - char buffer_rain[50]; - - // initialize default Screen - ST7735_Init(0); - fillScreen(BLACK); + /* USER CODE BEGIN 1 */ - // Set Rotation to horizontal - ST7735_SetRotation(1); - // cast floats to string - sprintf(buffer_temp_1, "temp1: %.2f", measurement.temp1); - sprintf(buffer_temp_2, "temp2: %.2f", measurement.temp2); - sprintf(buffer_temp_3, "temp3: %.2f", measurement.temp3); - sprintf(buffer_hum_1, "hum1: %.2f", measurement.hum1); - sprintf(buffer_hum_2, "hum2: %.2f", measurement.hum2); - sprintf(buffer_pressure, "pressure: %.2f", measurement.pressure); - sprintf(buffer_rain, "rain: %.2f", measurement.rain); + /* USER CODE END 1 */ - // writre strings to Display + /* MCU Configuration--------------------------------------------------------*/ - ST7735_WriteString(0, 0, buffer_temp_1, Font_7x10, CYAN, BLACK); - ST7735_WriteString(0, 13, buffer_temp_2, Font_7x10, CYAN, BLACK); - ST7735_WriteString(0, 26, buffer_temp_3, Font_7x10, CYAN, BLACK); - ST7735_WriteString(0, 39, buffer_hum_1, Font_7x10, CYAN, BLACK); - ST7735_WriteString(0, 52, buffer_hum_2, Font_7x10, CYAN, BLACK); - ST7735_WriteString(0, 65, buffer_pressure, Font_7x10, CYAN, BLACK); - ST7735_WriteString(0, 78, buffer_rain, Font_7x10, CYAN, BLACK); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - }; + /* USER CODE BEGIN Init */ - // instanz des structs anlegen + /* USER CODE END Init */ - struct measurement m; - m.temp1 = 12.22; - m.temp2 = 22.34; - m.temp3 = 33.45; - m.hum1 = 53.9; - m.hum2 = 49.4; - m.pressure = 34.98; - m.rain = 1; + /* Configure the system clock */ + SystemClock_Config(); - print_to_Display(m); + /* USER CODE BEGIN SysInit */ + /* USER CODE END SysInit */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_USART3_UART_Init(); + MX_USB_OTG_FS_PCD_Init(); + MX_SPI1_Init(); + MX_SPI4_Init(); + /* USER CODE BEGIN 2 */ + // initialize default Screen + ST7735_Init(0); + fillScreen(BLACK); + /* USER CODE END 2 */ - // print_to_Display(measurement); + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while (1) { + HAL_SPI_Receive(&hspi1, &measurement, sizeof(measurement), HAL_MAX_DELAY); + print_to_Display(); + /* USER CODE END WHILE */ - -/* - while(1){ - fillScreen(BLACK); - HAL_Delay(2000); - ST7735_SetRotation(0); - ST7735_WriteString(30, 0, "Lange Nacht", Font_7x10, CYAN, BLACK); - - HAL_Delay(1000); - ST7735_SetRotation(1); - ST7735_WriteString(10, 0, "der Wissenschaften!", Font_7x10, CYAN, BLACK); - - HAL_Delay(2300); - ST7735_SetRotation(2); - ST7735_WriteString(20, 0, "TH-Nuernberg ", Font_7x10, CYAN, BLACK); - ST7735_SetRotation(3); - HAL_Delay(1000); - ST7735_WriteString(31, 0, " Informatik", Font_7x10, CYAN, BLACK); - HAL_Delay(2300); - - fillScreen(GREEN); - HAL_Delay(100); - fillScreen(MAGENTA); - HAL_Delay(100); - fillScreen(YELLOW); - HAL_Delay(100); - } -*/ - - /* USER CODE END 2 */ - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ - } - /* USER CODE END 3 */ + /* USER CODE BEGIN 3 */ + } + /* USER CODE END 3 */ } /** @@ -215,44 +169,42 @@ int main(void) */ void SystemClock_Config(void) { - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - - /** Configure the main internal regulator output voltage - */ - __HAL_RCC_PWR_CLK_ENABLE(); - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 8; - RCC_OscInitStruct.PLL.PLLN = 384; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; - RCC_OscInitStruct.PLL.PLLQ = 8; - RCC_OscInitStruct.PLL.PLLR = 2; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != 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_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) - { - Error_Handler(); - } + RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; + RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; + + /** Configure the main internal regulator output voltage + */ + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 8; + RCC_OscInitStruct.PLL.PLLN = 384; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; + RCC_OscInitStruct.PLL.PLLQ = 8; + RCC_OscInitStruct.PLL.PLLR = 2; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!=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_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3)!=HAL_OK) { + Error_Handler(); + } } /** @@ -263,32 +215,31 @@ void SystemClock_Config(void) static void MX_SPI1_Init(void) { - /* USER CODE BEGIN SPI1_Init 0 */ - - /* USER CODE END SPI1_Init 0 */ - - /* USER CODE BEGIN SPI1_Init 1 */ - - /* USER CODE END SPI1_Init 1 */ - /* SPI1 parameter configuration*/ - hspi1.Instance = SPI1; - hspi1.Init.Mode = SPI_MODE_SLAVE; - hspi1.Init.Direction = SPI_DIRECTION_2LINES_RXONLY; - hspi1.Init.DataSize = SPI_DATASIZE_8BIT; - hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi1.Init.NSS = SPI_NSS_SOFT; - hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi1.Init.TIMode = SPI_TIMODE_DISABLE; - hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - hspi1.Init.CRCPolynomial = 10; - if (HAL_SPI_Init(&hspi1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN SPI1_Init 2 */ - - /* USER CODE END SPI1_Init 2 */ + /* USER CODE BEGIN SPI1_Init 0 */ + + /* USER CODE END SPI1_Init 0 */ + + /* USER CODE BEGIN SPI1_Init 1 */ + + /* USER CODE END SPI1_Init 1 */ + /* SPI1 parameter configuration*/ + hspi1.Instance = SPI1; + hspi1.Init.Mode = SPI_MODE_SLAVE; + hspi1.Init.Direction = SPI_DIRECTION_2LINES_RXONLY; + hspi1.Init.DataSize = SPI_DATASIZE_8BIT; + hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi1.Init.NSS = SPI_NSS_SOFT; + hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi1.Init.TIMode = SPI_TIMODE_DISABLE; + hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi1.Init.CRCPolynomial = 10; + if (HAL_SPI_Init(&hspi1)!=HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN SPI1_Init 2 */ + + /* USER CODE END SPI1_Init 2 */ } @@ -300,33 +251,32 @@ static void MX_SPI1_Init(void) static void MX_SPI4_Init(void) { - /* USER CODE BEGIN SPI4_Init 0 */ - - /* USER CODE END SPI4_Init 0 */ - - /* USER CODE BEGIN SPI4_Init 1 */ - - /* USER CODE END SPI4_Init 1 */ - /* SPI4 parameter configuration*/ - hspi4.Instance = SPI4; - hspi4.Init.Mode = SPI_MODE_MASTER; - hspi4.Init.Direction = SPI_DIRECTION_1LINE; - hspi4.Init.DataSize = SPI_DATASIZE_8BIT; - hspi4.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi4.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi4.Init.NSS = SPI_NSS_SOFT; - hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; - hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi4.Init.TIMode = SPI_TIMODE_DISABLE; - hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - hspi4.Init.CRCPolynomial = 10; - if (HAL_SPI_Init(&hspi4) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN SPI4_Init 2 */ - - /* USER CODE END SPI4_Init 2 */ + /* USER CODE BEGIN SPI4_Init 0 */ + + /* USER CODE END SPI4_Init 0 */ + + /* USER CODE BEGIN SPI4_Init 1 */ + + /* USER CODE END SPI4_Init 1 */ + /* SPI4 parameter configuration*/ + hspi4.Instance = SPI4; + hspi4.Init.Mode = SPI_MODE_MASTER; + hspi4.Init.Direction = SPI_DIRECTION_1LINE; + hspi4.Init.DataSize = SPI_DATASIZE_8BIT; + hspi4.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi4.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi4.Init.NSS = SPI_NSS_SOFT; + hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; + hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi4.Init.TIMode = SPI_TIMODE_DISABLE; + hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi4.Init.CRCPolynomial = 10; + if (HAL_SPI_Init(&hspi4)!=HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN SPI4_Init 2 */ + + /* USER CODE END SPI4_Init 2 */ } @@ -338,28 +288,27 @@ static void MX_SPI4_Init(void) static void MX_USART3_UART_Init(void) { - /* USER CODE BEGIN USART3_Init 0 */ + /* USER CODE BEGIN USART3_Init 0 */ - /* USER CODE END USART3_Init 0 */ + /* USER CODE END USART3_Init 0 */ - /* USER CODE BEGIN USART3_Init 1 */ + /* USER CODE BEGIN USART3_Init 1 */ - /* USER CODE END USART3_Init 1 */ - huart3.Instance = USART3; - huart3.Init.BaudRate = 115200; - huart3.Init.WordLength = UART_WORDLENGTH_8B; - huart3.Init.StopBits = UART_STOPBITS_1; - huart3.Init.Parity = UART_PARITY_NONE; - huart3.Init.Mode = UART_MODE_TX_RX; - huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart3.Init.OverSampling = UART_OVERSAMPLING_16; - if (HAL_UART_Init(&huart3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USART3_Init 2 */ + /* USER CODE END USART3_Init 1 */ + huart3.Instance = USART3; + huart3.Init.BaudRate = 115200; + huart3.Init.WordLength = UART_WORDLENGTH_8B; + huart3.Init.StopBits = UART_STOPBITS_1; + huart3.Init.Parity = UART_PARITY_NONE; + huart3.Init.Mode = UART_MODE_TX_RX; + huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart3.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart3)!=HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN USART3_Init 2 */ - /* USER CODE END USART3_Init 2 */ + /* USER CODE END USART3_Init 2 */ } @@ -371,31 +320,30 @@ static void MX_USART3_UART_Init(void) static void MX_USB_OTG_FS_PCD_Init(void) { - /* USER CODE BEGIN USB_OTG_FS_Init 0 */ + /* USER CODE BEGIN USB_OTG_FS_Init 0 */ - /* USER CODE END USB_OTG_FS_Init 0 */ + /* USER CODE END USB_OTG_FS_Init 0 */ - /* USER CODE BEGIN USB_OTG_FS_Init 1 */ + /* USER CODE BEGIN USB_OTG_FS_Init 1 */ - /* USER CODE END USB_OTG_FS_Init 1 */ - hpcd_USB_OTG_FS.Instance = USB_OTG_FS; - hpcd_USB_OTG_FS.Init.dev_endpoints = 6; - hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_OTG_FS.Init.dma_enable = DISABLE; - hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_OTG_FS.Init.Sof_enable = ENABLE; - hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE; - hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE; - hpcd_USB_OTG_FS.Init.battery_charging_enable = ENABLE; - hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE; - hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE; - if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USB_OTG_FS_Init 2 */ + /* USER CODE END USB_OTG_FS_Init 1 */ + hpcd_USB_OTG_FS.Instance = USB_OTG_FS; + hpcd_USB_OTG_FS.Init.dev_endpoints = 6; + hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_OTG_FS.Init.dma_enable = DISABLE; + hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED; + hpcd_USB_OTG_FS.Init.Sof_enable = ENABLE; + hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE; + hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE; + hpcd_USB_OTG_FS.Init.battery_charging_enable = ENABLE; + hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE; + hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_OTG_FS)!=HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN USB_OTG_FS_Init 2 */ - /* USER CODE END USB_OTG_FS_Init 2 */ + /* USER CODE END USB_OTG_FS_Init 2 */ } @@ -406,68 +354,68 @@ static void MX_USB_OTG_FS_PCD_Init(void) */ static void MX_GPIO_Init(void) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - __HAL_RCC_GPIOG_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, Display_Reset_Pin|Display_DC_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, LD1_Pin|LD3_Pin|LD2_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(USB_PowerSwitchOn_GPIO_Port, USB_PowerSwitchOn_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin : USER_Btn_Pin */ - GPIO_InitStruct.Pin = USER_Btn_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(USER_Btn_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : Display_Reset_Pin Display_DC_Pin */ - GPIO_InitStruct.Pin = Display_Reset_Pin|Display_DC_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pin : CS_Pin */ - GPIO_InitStruct.Pin = CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(CS_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : LD1_Pin LD3_Pin LD2_Pin */ - GPIO_InitStruct.Pin = LD1_Pin|LD3_Pin|LD2_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pin : USB_PowerSwitchOn_Pin */ - GPIO_InitStruct.Pin = USB_PowerSwitchOn_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(USB_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : USB_OverCurrent_Pin */ - GPIO_InitStruct.Pin = USB_OverCurrent_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(USB_OverCurrent_GPIO_Port, &GPIO_InitStruct); + GPIO_InitTypeDef GPIO_InitStruct = { 0 }; + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOH_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + __HAL_RCC_GPIOG_CLK_ENABLE(); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOC, Display_Reset_Pin | Display_DC_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, LD1_Pin | LD3_Pin | LD2_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(USB_PowerSwitchOn_GPIO_Port, USB_PowerSwitchOn_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin : USER_Btn_Pin */ + GPIO_InitStruct.Pin = USER_Btn_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(USER_Btn_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : Display_Reset_Pin Display_DC_Pin */ + GPIO_InitStruct.Pin = Display_Reset_Pin | Display_DC_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pin : CS_Pin */ + GPIO_InitStruct.Pin = CS_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(CS_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : LD1_Pin LD3_Pin LD2_Pin */ + GPIO_InitStruct.Pin = LD1_Pin | LD3_Pin | LD2_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /*Configure GPIO pin : USB_PowerSwitchOn_Pin */ + GPIO_InitStruct.Pin = USB_PowerSwitchOn_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(USB_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : USB_OverCurrent_Pin */ + GPIO_InitStruct.Pin = USB_OverCurrent_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(USB_OverCurrent_GPIO_Port, &GPIO_InitStruct); } @@ -481,13 +429,12 @@ static void MX_GPIO_Init(void) */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ - __disable_irq(); - while (1) - { - } - /* USER CODE END Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while (1) { + } + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT @@ -502,7 +449,7 @@ 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, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } -#endif /* USE_FULL_ASSERT */ +#endif /* USE_FULL_ASSERT */ \ No newline at end of file -- GitLab