[17] | 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 | #include "adc.h" |
---|
| 22 | #include "dma.h" |
---|
| 23 | #include "tim.h" |
---|
| 24 | #include "usart.h" |
---|
| 25 | #include "gpio.h" |
---|
| 26 | |
---|
| 27 | /* Private includes ----------------------------------------------------------*/ |
---|
| 28 | /* USER CODE BEGIN Includes */ |
---|
| 29 | #include <stdio.h> |
---|
| 30 | #include "button.h" |
---|
| 31 | #include "buzzer.h" |
---|
| 32 | #include "relais.h" |
---|
| 33 | #include "leds.h" |
---|
| 34 | #include "chip_temperature.h" |
---|
| 35 | #include "modeswitch.h" |
---|
| 36 | #include "mode_mainswitch.h" |
---|
| 37 | #include "mode_secondaryprotection.h" |
---|
| 38 | #include "mode_secondaryprotection_plus.h" |
---|
| 39 | #include "mode_lvp.h" |
---|
| 40 | #include "mode_ovp.h" |
---|
| 41 | #include "mode_lvp_ovp.h" |
---|
| 42 | #include "voltage_meas.h" |
---|
| 43 | /* USER CODE END Includes */ |
---|
| 44 | |
---|
| 45 | /* Private typedef -----------------------------------------------------------*/ |
---|
| 46 | /* USER CODE BEGIN PTD */ |
---|
| 47 | |
---|
| 48 | /* USER CODE END PTD */ |
---|
| 49 | |
---|
| 50 | /* Private define ------------------------------------------------------------*/ |
---|
| 51 | /* USER CODE BEGIN PD */ |
---|
| 52 | int oldTimeMSTick; |
---|
| 53 | int oldTimeSeconds; |
---|
| 54 | int msCounter; |
---|
| 55 | /* USER CODE END PD */ |
---|
| 56 | |
---|
| 57 | /* Private macro -------------------------------------------------------------*/ |
---|
| 58 | /* USER CODE BEGIN PM */ |
---|
| 59 | |
---|
| 60 | /* USER CODE END PM */ |
---|
| 61 | |
---|
| 62 | /* Private variables ---------------------------------------------------------*/ |
---|
| 63 | |
---|
| 64 | /* USER CODE BEGIN PV */ |
---|
| 65 | static volatile uint32_t adcData[5]; |
---|
| 66 | /* USER CODE END PV */ |
---|
| 67 | |
---|
| 68 | /* Private function prototypes -----------------------------------------------*/ |
---|
| 69 | void SystemClock_Config(void); |
---|
| 70 | /* USER CODE BEGIN PFP */ |
---|
| 71 | |
---|
| 72 | /* USER CODE END PFP */ |
---|
| 73 | |
---|
| 74 | /* Private user code ---------------------------------------------------------*/ |
---|
| 75 | /* USER CODE BEGIN 0 */ |
---|
| 76 | |
---|
| 77 | /* USER CODE END 0 */ |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | * @brief The application entry point. |
---|
| 81 | * @retval int |
---|
| 82 | */ |
---|
| 83 | int main(void) |
---|
| 84 | { |
---|
| 85 | |
---|
| 86 | /* USER CODE BEGIN 1 */ |
---|
| 87 | |
---|
| 88 | /* USER CODE END 1 */ |
---|
| 89 | |
---|
| 90 | /* MCU Configuration--------------------------------------------------------*/ |
---|
| 91 | |
---|
| 92 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
---|
| 93 | HAL_Init(); |
---|
| 94 | |
---|
| 95 | /* USER CODE BEGIN Init */ |
---|
| 96 | |
---|
| 97 | /* USER CODE END Init */ |
---|
| 98 | |
---|
| 99 | /* Configure the system clock */ |
---|
| 100 | SystemClock_Config(); |
---|
| 101 | |
---|
| 102 | /* USER CODE BEGIN SysInit */ |
---|
| 103 | |
---|
| 104 | /* USER CODE END SysInit */ |
---|
| 105 | |
---|
| 106 | /* Initialize all configured peripherals */ |
---|
| 107 | MX_GPIO_Init(); |
---|
| 108 | MX_DMA_Init(); |
---|
| 109 | MX_ADC1_Init(); |
---|
| 110 | MX_TIM16_Init(); |
---|
| 111 | MX_TIM17_Init(); |
---|
| 112 | // MX_USART1_UART_Init(); |
---|
| 113 | /* USER CODE BEGIN 2 */ |
---|
| 114 | printf("debug io test...ok\r\n"); |
---|
| 115 | HAL_GPIO_WritePin(GPIO_OUTPUT_BUZZER_GPIO_Port, GPIO_OUTPUT_BUZZER_Pin, GPIO_PIN_SET); |
---|
| 116 | HAL_GPIO_WritePin(GPIO_OUTPUT_LED_ERROR_GPIO_Port, GPIO_OUTPUT_LED_ERROR_Pin, GPIO_PIN_SET); |
---|
| 117 | HAL_GPIO_WritePin(GPIO_OUTPUT_LED_ON_GPIO_Port, GPIO_OUTPUT_LED_ON_Pin, GPIO_PIN_SET); |
---|
| 118 | HAL_Delay(1000); |
---|
| 119 | HAL_GPIO_WritePin(GPIO_OUTPUT_BUZZER_GPIO_Port, GPIO_OUTPUT_BUZZER_Pin, GPIO_PIN_RESET); |
---|
| 120 | HAL_GPIO_WritePin(GPIO_OUTPUT_LED_ERROR_GPIO_Port, GPIO_OUTPUT_LED_ERROR_Pin, GPIO_PIN_RESET); |
---|
| 121 | HAL_GPIO_WritePin(GPIO_OUTPUT_LED_ON_GPIO_Port, GPIO_OUTPUT_LED_ON_Pin, GPIO_PIN_RESET); |
---|
| 122 | |
---|
| 123 | //--- RELAIS ZURÜCKSETZEN, damit es definitiv aus ist --- |
---|
| 124 | //Sicherstellen das nicht noch die Set Spule aktiv geschaltet ist |
---|
| 125 | HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_SET_GPIO_Port, GPIO_OUTPUT_RELAIS_SET_Pin, GPIO_PIN_RESET); |
---|
| 126 | |
---|
| 127 | //Puls starten |
---|
| 128 | HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_RESET_GPIO_Port, GPIO_OUTPUT_RELAIS_RESET_Pin, GPIO_PIN_SET); |
---|
| 129 | HAL_Delay(50); |
---|
| 130 | HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_RESET_GPIO_Port, GPIO_OUTPUT_RELAIS_RESET_Pin, GPIO_PIN_RESET); |
---|
| 131 | //--- RELAIS ZURÜCKSETZEN ENDE ---- |
---|
| 132 | |
---|
| 133 | MODESWITCH_ReadMode(); |
---|
| 134 | |
---|
| 135 | CHIP_TEMPERATURE_Calibration(/*&sys_data*/); |
---|
| 136 | HAL_ADCEx_Calibration_Start(&hadc1); |
---|
| 137 | HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adcData, 5); |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | /* USER CODE END 2 */ |
---|
| 141 | |
---|
| 142 | /* Infinite loop */ |
---|
| 143 | /* USER CODE BEGIN WHILE */ |
---|
| 144 | while (1) |
---|
| 145 | { |
---|
| 146 | /* USER CODE END WHILE */ |
---|
| 147 | |
---|
| 148 | /* USER CODE BEGIN 3 */ |
---|
| 149 | if (oldTimeMSTick != HAL_GetTick()) |
---|
| 150 | { |
---|
| 151 | BUTTON_Exec(); |
---|
| 152 | BUZZER_Exec(); |
---|
| 153 | RELAIS_Exec(); |
---|
| 154 | LEDS_Exec(); |
---|
| 155 | VOLTAGE_MEAS_Exec(adcData[1],adcData[2]); |
---|
| 156 | oldTimeMSTick = HAL_GetTick(); |
---|
| 157 | msCounter++; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | //Sekunden tick |
---|
| 162 | if (msCounter >= 999) |
---|
| 163 | { |
---|
| 164 | msCounter = 0; |
---|
| 165 | CHIP_TEMPERATURE_Exec( adcData[4]); |
---|
| 166 | |
---|
[19] | 167 | static unsigned pwm = 100U; |
---|
| 168 | |
---|
| 169 | SetFANSpeed(pwm); |
---|
| 170 | |
---|
| 171 | pwm++; |
---|
| 172 | if (pwm > 300U) pwm = 300U; // 30.0% |
---|
[17] | 173 | } |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | switch (MODESWITCH_GetMode()) |
---|
| 178 | { |
---|
| 179 | case MODE_MAINSWITCH: |
---|
| 180 | MODE_MAINSWITCH_Exec(); |
---|
| 181 | break; |
---|
| 182 | |
---|
| 183 | case MODE_MAINSWITCH_SECONDARYPROTECTION: |
---|
| 184 | MODE_SECONDARYPROTECTION_Exec(); |
---|
| 185 | break; |
---|
| 186 | |
---|
| 187 | case MODE_MAINSWITCH_SECONDARYPROTECTION_PLUS: |
---|
| 188 | MODE_SECONDARYPROTECTION_PLUS_Exec(); |
---|
| 189 | break; |
---|
| 190 | |
---|
| 191 | case MODE_MAINSWITCH_LVP_OVP: |
---|
| 192 | MODE_LVP_OVP_Exec(); |
---|
| 193 | break; |
---|
| 194 | |
---|
| 195 | //case MODE_MAINSWITCH_LVP: |
---|
| 196 | // MODE_LVP_Exec(); |
---|
| 197 | //break; |
---|
| 198 | |
---|
| 199 | //case MODE_MAINSWITCH_OVP: |
---|
| 200 | // MODE_OVP_Exec(); |
---|
| 201 | //break; |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | default: |
---|
| 207 | printf("mode not yet implemented\n"); |
---|
| 208 | |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | /* USER CODE END 3 */ |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | /** |
---|
| 216 | * @brief System Clock Configuration |
---|
| 217 | * @retval None |
---|
| 218 | */ |
---|
| 219 | void SystemClock_Config(void) |
---|
| 220 | { |
---|
| 221 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
---|
| 222 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
---|
| 223 | |
---|
| 224 | __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_0); |
---|
| 225 | |
---|
| 226 | /** Initializes the RCC Oscillators according to the specified parameters |
---|
| 227 | * in the RCC_OscInitTypeDef structure. |
---|
| 228 | */ |
---|
| 229 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
---|
| 230 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
---|
| 231 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV4; |
---|
| 232 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
---|
| 233 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
---|
| 234 | { |
---|
| 235 | Error_Handler(); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | /** Initializes the CPU, AHB and APB buses clocks |
---|
| 239 | */ |
---|
| 240 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
---|
| 241 | |RCC_CLOCKTYPE_PCLK1; |
---|
| 242 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; |
---|
| 243 | RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; |
---|
| 244 | RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1; |
---|
| 245 | RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1; |
---|
| 246 | |
---|
| 247 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) |
---|
| 248 | { |
---|
| 249 | Error_Handler(); |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | /* USER CODE BEGIN 4 */ |
---|
| 254 | |
---|
| 255 | /* USER CODE END 4 */ |
---|
| 256 | |
---|
| 257 | /** |
---|
| 258 | * @brief This function is executed in case of error occurrence. |
---|
| 259 | * @retval None |
---|
| 260 | */ |
---|
| 261 | void Error_Handler(void) |
---|
| 262 | { |
---|
| 263 | /* USER CODE BEGIN Error_Handler_Debug */ |
---|
| 264 | /* User can add his own implementation to report the HAL error return state */ |
---|
| 265 | __disable_irq(); |
---|
| 266 | while (1) |
---|
| 267 | { |
---|
| 268 | } |
---|
| 269 | /* USER CODE END Error_Handler_Debug */ |
---|
| 270 | } |
---|
| 271 | #ifdef USE_FULL_ASSERT |
---|
| 272 | /** |
---|
| 273 | * @brief Reports the name of the source file and the source line number |
---|
| 274 | * where the assert_param error has occurred. |
---|
| 275 | * @param file: pointer to the source file name |
---|
| 276 | * @param line: assert_param error line source number |
---|
| 277 | * @retval None |
---|
| 278 | */ |
---|
| 279 | void assert_failed(uint8_t *file, uint32_t line) |
---|
| 280 | { |
---|
| 281 | /* USER CODE BEGIN 6 */ |
---|
| 282 | /* User can add his own implementation to report the file name and line number, |
---|
| 283 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
---|
| 284 | /* USER CODE END 6 */ |
---|
| 285 | } |
---|
| 286 | #endif /* USE_FULL_ASSERT */ |
---|