| 1 | /* USER CODE BEGIN Header */
|
|---|
| 2 | /**
|
|---|
| 3 | ******************************************************************************
|
|---|
| 4 | * @file : main.c
|
|---|
| 5 | * @brief : Main program body
|
|---|
| 6 | ******************************************************************************
|
|---|
| 7 | * @attention
|
|---|
| 8 | *
|
|---|
| 9 | * Copyright (c) 2025 STMicroelectronics.
|
|---|
| 10 | * All rights reserved.
|
|---|
| 11 | *
|
|---|
| 12 | * This software is licensed under terms that can be found in the LICENSE file
|
|---|
| 13 | * in the root directory of this software component.
|
|---|
| 14 | * If no LICENSE file comes with this software, it is provided AS-IS.
|
|---|
| 15 | *
|
|---|
| 16 | ******************************************************************************
|
|---|
| 17 | */
|
|---|
| 18 | /* USER CODE END Header */
|
|---|
| 19 | /* Includes ------------------------------------------------------------------*/
|
|---|
| 20 | #include "main.h"
|
|---|
| 21 |
|
|---|
| 22 | /* Private includes ----------------------------------------------------------*/
|
|---|
| 23 | /* USER CODE BEGIN Includes */
|
|---|
| 24 |
|
|---|
| 25 | /* USER CODE END Includes */
|
|---|
| 26 |
|
|---|
| 27 | /* Private typedef -----------------------------------------------------------*/
|
|---|
| 28 | /* USER CODE BEGIN PTD */
|
|---|
| 29 |
|
|---|
| 30 | /* USER CODE END PTD */
|
|---|
| 31 |
|
|---|
| 32 | /* Private define ------------------------------------------------------------*/
|
|---|
| 33 | /* USER CODE BEGIN PD */
|
|---|
| 34 |
|
|---|
| 35 | /* USER CODE END PD */
|
|---|
| 36 |
|
|---|
| 37 | /* Private macro -------------------------------------------------------------*/
|
|---|
| 38 | /* USER CODE BEGIN PM */
|
|---|
| 39 |
|
|---|
| 40 | /* USER CODE END PM */
|
|---|
| 41 |
|
|---|
| 42 | /* Private variables ---------------------------------------------------------*/
|
|---|
| 43 |
|
|---|
| 44 | /* USER CODE BEGIN PV */
|
|---|
| 45 |
|
|---|
| 46 | /* USER CODE END PV */
|
|---|
| 47 |
|
|---|
| 48 | /* Private function prototypes -----------------------------------------------*/
|
|---|
| 49 | void SystemClock_Config(void);
|
|---|
| 50 | static void MX_GPIO_Init(void);
|
|---|
| 51 | /* USER CODE BEGIN PFP */
|
|---|
| 52 |
|
|---|
| 53 | /* USER CODE END PFP */
|
|---|
| 54 |
|
|---|
| 55 | /* Private user code ---------------------------------------------------------*/
|
|---|
| 56 | /* USER CODE BEGIN 0 */
|
|---|
| 57 |
|
|---|
| 58 | /* USER CODE END 0 */
|
|---|
| 59 |
|
|---|
| 60 | /**
|
|---|
| 61 | * @brief The application entry point.
|
|---|
| 62 | * @retval int
|
|---|
| 63 | */
|
|---|
| 64 | int main(void)
|
|---|
| 65 | {
|
|---|
| 66 |
|
|---|
| 67 | /* USER CODE BEGIN 1 */
|
|---|
| 68 |
|
|---|
| 69 | /* USER CODE END 1 */
|
|---|
| 70 |
|
|---|
| 71 | /* MCU Configuration--------------------------------------------------------*/
|
|---|
| 72 |
|
|---|
| 73 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|---|
| 74 | HAL_Init();
|
|---|
| 75 |
|
|---|
| 76 | /* USER CODE BEGIN Init */
|
|---|
| 77 |
|
|---|
| 78 | /* USER CODE END Init */
|
|---|
| 79 |
|
|---|
| 80 | /* Configure the system clock */
|
|---|
| 81 | SystemClock_Config();
|
|---|
| 82 |
|
|---|
| 83 | /* USER CODE BEGIN SysInit */
|
|---|
| 84 |
|
|---|
| 85 | /* USER CODE END SysInit */
|
|---|
| 86 |
|
|---|
| 87 | /* Initialize all configured peripherals */
|
|---|
| 88 | MX_GPIO_Init();
|
|---|
| 89 | /* USER CODE BEGIN 2 */
|
|---|
| 90 |
|
|---|
| 91 | /* USER CODE END 2 */
|
|---|
| 92 |
|
|---|
| 93 | /* Infinite loop */
|
|---|
| 94 | /* USER CODE BEGIN WHILE */
|
|---|
| 95 | while (1)
|
|---|
| 96 | {
|
|---|
| 97 | /* USER CODE END WHILE */
|
|---|
| 98 |
|
|---|
| 99 | /* USER CODE BEGIN 3 */
|
|---|
| 100 | }
|
|---|
| 101 | /* USER CODE END 3 */
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | /**
|
|---|
| 105 | * @brief System Clock Configuration
|
|---|
| 106 | * @retval None
|
|---|
| 107 | */
|
|---|
| 108 | void SystemClock_Config(void)
|
|---|
| 109 | {
|
|---|
| 110 | RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|---|
| 111 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|---|
| 112 |
|
|---|
| 113 | __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_0);
|
|---|
| 114 |
|
|---|
| 115 | /** Initializes the RCC Oscillators according to the specified parameters
|
|---|
| 116 | * in the RCC_OscInitTypeDef structure.
|
|---|
| 117 | */
|
|---|
| 118 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
|---|
| 119 | RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|---|
| 120 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV4;
|
|---|
| 121 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|---|
| 122 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|---|
| 123 | {
|
|---|
| 124 | Error_Handler();
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /** Initializes the CPU, AHB and APB buses clocks
|
|---|
| 128 | */
|
|---|
| 129 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|---|
| 130 | |RCC_CLOCKTYPE_PCLK1;
|
|---|
| 131 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
|---|
| 132 | RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
|---|
| 133 | RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
|
|---|
| 134 | RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
|
|---|
| 135 |
|
|---|
| 136 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
|---|
| 137 | {
|
|---|
| 138 | Error_Handler();
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | /**
|
|---|
| 143 | * @brief GPIO Initialization Function
|
|---|
| 144 | * @param None
|
|---|
| 145 | * @retval None
|
|---|
| 146 | */
|
|---|
| 147 | static void MX_GPIO_Init(void)
|
|---|
| 148 | {
|
|---|
| 149 | GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|---|
| 150 | /* USER CODE BEGIN MX_GPIO_Init_1 */
|
|---|
| 151 | /* USER CODE END MX_GPIO_Init_1 */
|
|---|
| 152 |
|
|---|
| 153 | /* GPIO Ports Clock Enable */
|
|---|
| 154 | __HAL_RCC_GPIOB_CLK_ENABLE();
|
|---|
| 155 | __HAL_RCC_GPIOC_CLK_ENABLE();
|
|---|
| 156 | __HAL_RCC_GPIOA_CLK_ENABLE();
|
|---|
| 157 |
|
|---|
| 158 | /*Configure GPIO pin Output Level */
|
|---|
| 159 | HAL_GPIO_WritePin(GPIOA, GPIO_OUTPUT_LED_ON_Pin|GPIO_OUTPUT_LED_ERROR_Pin|GPIO_OUTPUT_RELAIS_SET_Pin|GPIO_OUTPUT_RELAIS_RESET_Pin
|
|---|
| 160 | |GPIO_OUTPUT_BUZZER_Pin, GPIO_PIN_RESET);
|
|---|
| 161 |
|
|---|
| 162 | /*Configure GPIO pins : GPIO_INPUT_MODE_B3_Pin GPIO_INPUT_MODE_B2_Pin */
|
|---|
| 163 | GPIO_InitStruct.Pin = GPIO_INPUT_MODE_B3_Pin|GPIO_INPUT_MODE_B2_Pin;
|
|---|
| 164 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|---|
| 165 | GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|---|
| 166 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|---|
| 167 |
|
|---|
| 168 | /*Configure GPIO pins : GPIO_INPUT_MODE_B1_Pin GPIO_INPUT_MODE_B0_Pin */
|
|---|
| 169 | GPIO_InitStruct.Pin = GPIO_INPUT_MODE_B1_Pin|GPIO_INPUT_MODE_B0_Pin;
|
|---|
| 170 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|---|
| 171 | GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|---|
| 172 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|---|
| 173 |
|
|---|
| 174 | /*Configure GPIO pins : GPIO_INPUT_LVP_Pin GPIO_INPUT_OVP_Pin */
|
|---|
| 175 | GPIO_InitStruct.Pin = GPIO_INPUT_LVP_Pin|GPIO_INPUT_OVP_Pin;
|
|---|
| 176 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|---|
| 177 | GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
|---|
| 178 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|---|
| 179 |
|
|---|
| 180 | /*Configure GPIO pins : GPIO_INPUT_BTN_ON_Pin GPIO_INPUT_BTN_OFF_Pin GPIO_INPUT_FAULT_Pin GPIO_INPUT_BMS_Pin */
|
|---|
| 181 | GPIO_InitStruct.Pin = GPIO_INPUT_BTN_ON_Pin|GPIO_INPUT_BTN_OFF_Pin|GPIO_INPUT_FAULT_Pin|GPIO_INPUT_BMS_Pin;
|
|---|
| 182 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|---|
| 183 | GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|---|
| 184 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|---|
| 185 |
|
|---|
| 186 | /*Configure GPIO pins : GPIO_OUTPUT_LED_ON_Pin GPIO_OUTPUT_LED_ERROR_Pin GPIO_OUTPUT_RELAIS_SET_Pin GPIO_OUTPUT_RELAIS_RESET_Pin
|
|---|
| 187 | GPIO_OUTPUT_BUZZER_Pin */
|
|---|
| 188 | GPIO_InitStruct.Pin = GPIO_OUTPUT_LED_ON_Pin|GPIO_OUTPUT_LED_ERROR_Pin|GPIO_OUTPUT_RELAIS_SET_Pin|GPIO_OUTPUT_RELAIS_RESET_Pin
|
|---|
| 189 | |GPIO_OUTPUT_BUZZER_Pin;
|
|---|
| 190 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|---|
| 191 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|---|
| 192 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|---|
| 193 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|---|
| 194 |
|
|---|
| 195 | /* USER CODE BEGIN MX_GPIO_Init_2 */
|
|---|
| 196 | /* USER CODE END MX_GPIO_Init_2 */
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | /* USER CODE BEGIN 4 */
|
|---|
| 200 |
|
|---|
| 201 | /* USER CODE END 4 */
|
|---|
| 202 |
|
|---|
| 203 | /**
|
|---|
| 204 | * @brief This function is executed in case of error occurrence.
|
|---|
| 205 | * @retval None
|
|---|
| 206 | */
|
|---|
| 207 | void Error_Handler(void)
|
|---|
| 208 | {
|
|---|
| 209 | /* USER CODE BEGIN Error_Handler_Debug */
|
|---|
| 210 | /* User can add his own implementation to report the HAL error return state */
|
|---|
| 211 | __disable_irq();
|
|---|
| 212 | while (1)
|
|---|
| 213 | {
|
|---|
| 214 | }
|
|---|
| 215 | /* USER CODE END Error_Handler_Debug */
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | #ifdef USE_FULL_ASSERT
|
|---|
| 219 | /**
|
|---|
| 220 | * @brief Reports the name of the source file and the source line number
|
|---|
| 221 | * where the assert_param error has occurred.
|
|---|
| 222 | * @param file: pointer to the source file name
|
|---|
| 223 | * @param line: assert_param error line source number
|
|---|
| 224 | * @retval None
|
|---|
| 225 | */
|
|---|
| 226 | void assert_failed(uint8_t *file, uint32_t line)
|
|---|
| 227 | {
|
|---|
| 228 | /* USER CODE BEGIN 6 */
|
|---|
| 229 | /* User can add his own implementation to report the file name and line number,
|
|---|
| 230 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|---|
| 231 | /* USER CODE END 6 */
|
|---|
| 232 | }
|
|---|
| 233 | #endif /* USE_FULL_ASSERT */
|
|---|