137 lines
4.3 KiB
C
137 lines
4.3 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file gpio.c
|
|
* @brief This file provides code for the configuration
|
|
* of all used GPIO pins.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2025 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "gpio.h"
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
#include "usart.h"
|
|
/* USER CODE END 0 */
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
/* Configure GPIO */
|
|
/*----------------------------------------------------------------------------*/
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
/** Configure pins
|
|
PC15-OSC32_OUT ------> RCC_OSC32_OUT
|
|
PC14-OSC32_IN ------> RCC_OSC32_IN
|
|
PA14 (JTCK/SWCLK) ------> DEBUG_JTCK-SWCLK
|
|
PA13 (JTMS/SWDIO) ------> DEBUG_JTMS-SWDIO
|
|
OSC_OUT ------> RCC_OSC_OUT
|
|
OSC_IN ------> RCC_OSC_IN
|
|
*/
|
|
void MX_GPIO_Init(void)
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
/* GPIO Ports Clock Enable */
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOB, STATUS_LED_Pin|LTE_EN_Pin|LTE_RST_Pin|LTE_PWRKEY_Pin, GPIO_PIN_RESET);
|
|
|
|
/*Configure GPIO pins : STATUS_LED_Pin LTE_EN_Pin LTE_RST_Pin LTE_PWRKEY_Pin */
|
|
GPIO_InitStruct.Pin = STATUS_LED_Pin|LTE_EN_Pin|LTE_RST_Pin|LTE_PWRKEY_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);
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
void LEDStatus_Active(void)
|
|
{
|
|
HAL_GPIO_WritePin(STATUS_LED_GPIO_Port, STATUS_LED_Pin, GPIO_PIN_SET);
|
|
}
|
|
|
|
void LEDStatus_Inactive(void)
|
|
{
|
|
HAL_GPIO_WritePin(STATUS_LED_GPIO_Port, STATUS_LED_Pin, GPIO_PIN_RESET);
|
|
}
|
|
|
|
/**
|
|
* @brief Powers up the LTE module (Quectel EG91) using GPIO toggling.
|
|
*
|
|
* This function simulates pressing the PWRKEY and enables the level translator.
|
|
* A wait period is included to allow UART stabilization.
|
|
*/
|
|
void LTE_HardwarePowerUp(void)
|
|
{
|
|
HAL_GPIO_WritePin(LTE_EN_GPIO_Port, LTE_EN_Pin, GPIO_PIN_SET);
|
|
|
|
APP_LOG_MSG(" --- QUECTEL EG91 Power Up ---\r\n");
|
|
|
|
/* Power up the LTE Module Using Power Key */
|
|
HAL_GPIO_WritePin(LTE_PWRKEY_GPIO_Port, LTE_PWRKEY_Pin, GPIO_PIN_RESET);
|
|
HAL_GPIO_WritePin(LTE_RST_GPIO_Port, LTE_RST_Pin, GPIO_PIN_RESET);
|
|
HAL_Delay(100);
|
|
HAL_GPIO_WritePin(LTE_RST_GPIO_Port, LTE_RST_Pin, GPIO_PIN_SET);
|
|
HAL_GPIO_WritePin(LTE_PWRKEY_GPIO_Port, LTE_PWRKEY_Pin, GPIO_PIN_SET);
|
|
HAL_Delay(200);
|
|
HAL_GPIO_WritePin(LTE_RST_GPIO_Port, LTE_RST_Pin, GPIO_PIN_RESET);
|
|
HAL_Delay(350);
|
|
HAL_GPIO_WritePin(LTE_PWRKEY_GPIO_Port, LTE_PWRKEY_Pin, GPIO_PIN_RESET);
|
|
|
|
HAL_Delay(100);
|
|
|
|
for (uint8_t wait = 0; wait < 12; wait++) {
|
|
LEDStatus_Active();
|
|
HAL_Delay(500);
|
|
LEDStatus_Inactive();
|
|
HAL_Delay(500);
|
|
// APP_LOG_MSG(".");
|
|
}
|
|
// APP_LOG_MSG(" Done\r\n");
|
|
}
|
|
|
|
/**
|
|
* @brief Powers down the LTE module (Quectel EG91) via GPIO toggling.
|
|
*
|
|
* This simulates a long-press of the PWRKEY, then waits 30 seconds to allow the module to shut down safely.
|
|
*/
|
|
void LTE_HardwarePowerDown(void)
|
|
{
|
|
APP_LOG_MSG(" --- QUECTEL EG91 Shut Down --- \r\n");
|
|
|
|
HAL_GPIO_WritePin(LTE_PWRKEY_GPIO_Port, LTE_PWRKEY_Pin, GPIO_PIN_RESET);
|
|
HAL_Delay(100);
|
|
HAL_GPIO_WritePin(LTE_PWRKEY_GPIO_Port, LTE_PWRKEY_Pin, GPIO_PIN_SET);
|
|
HAL_Delay(700);
|
|
HAL_GPIO_WritePin(LTE_PWRKEY_GPIO_Port, LTE_PWRKEY_Pin, GPIO_PIN_RESET);
|
|
|
|
LEDStatus_Active();
|
|
// APP_LOG_MSG("Shutting off ");
|
|
for (uint8_t wait = 0; wait < 30; wait++)
|
|
{
|
|
// APP_LOG_MSG(".");
|
|
HAL_Delay(1000);
|
|
}
|
|
// APP_LOG_MSG(" Done\r\n");
|
|
LEDStatus_Inactive();
|
|
}
|
|
/* USER CODE END 2 */
|