| 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 "iwdg.h"
|
|---|
| 24 | #include "tim.h"
|
|---|
| 25 | #include "usart.h"
|
|---|
| 26 | #include "gpio.h"
|
|---|
| 27 |
|
|---|
| 28 | /* Private includes ----------------------------------------------------------*/
|
|---|
| 29 | /* USER CODE BEGIN Includes */
|
|---|
| 30 |
|
|---|
| 31 | /* USER CODE END Includes */
|
|---|
| 32 |
|
|---|
| 33 | /* Private typedef -----------------------------------------------------------*/
|
|---|
| 34 | /* USER CODE BEGIN PTD */
|
|---|
| 35 |
|
|---|
| 36 | /* USER CODE END PTD */
|
|---|
| 37 |
|
|---|
| 38 | /* Private define ------------------------------------------------------------*/
|
|---|
| 39 | /* USER CODE BEGIN PD */
|
|---|
| 40 |
|
|---|
| 41 | /* USER CODE END PD */
|
|---|
| 42 |
|
|---|
| 43 | /* Private macro -------------------------------------------------------------*/
|
|---|
| 44 | /* USER CODE BEGIN PM */
|
|---|
| 45 |
|
|---|
| 46 | /* USER CODE END PM */
|
|---|
| 47 |
|
|---|
| 48 | /* Private variables ---------------------------------------------------------*/
|
|---|
| 49 |
|
|---|
| 50 | /* USER CODE BEGIN PV */
|
|---|
| 51 |
|
|---|
| 52 | /* USER CODE END PV */
|
|---|
| 53 |
|
|---|
| 54 | /* Private function prototypes -----------------------------------------------*/
|
|---|
| 55 | void SystemClock_Config(void);
|
|---|
| 56 | /* USER CODE BEGIN PFP */
|
|---|
| 57 |
|
|---|
| 58 | /* USER CODE END PFP */
|
|---|
| 59 |
|
|---|
| 60 | /* Private user code ---------------------------------------------------------*/
|
|---|
| 61 | /* USER CODE BEGIN 0 */
|
|---|
| 62 |
|
|---|
| 63 | /* USER CODE END 0 */
|
|---|
| 64 |
|
|---|
| 65 | /**
|
|---|
| 66 | * @brief The application entry point.
|
|---|
| 67 | * @retval int
|
|---|
| 68 | */
|
|---|
| 69 | int main(void)
|
|---|
| 70 | {
|
|---|
| 71 |
|
|---|
| 72 | /* USER CODE BEGIN 1 */
|
|---|
| 73 |
|
|---|
| 74 | /* USER CODE END 1 */
|
|---|
| 75 |
|
|---|
| 76 | /* MCU Configuration--------------------------------------------------------*/
|
|---|
| 77 |
|
|---|
| 78 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|---|
| 79 | HAL_Init();
|
|---|
| 80 |
|
|---|
| 81 | /* USER CODE BEGIN Init */
|
|---|
| 82 |
|
|---|
| 83 | /* USER CODE END Init */
|
|---|
| 84 |
|
|---|
| 85 | /* Configure the system clock */
|
|---|
| 86 | SystemClock_Config();
|
|---|
| 87 |
|
|---|
| 88 | /* USER CODE BEGIN SysInit */
|
|---|
| 89 |
|
|---|
| 90 | /* USER CODE END SysInit */
|
|---|
| 91 |
|
|---|
| 92 | /* Initialize all configured peripherals */
|
|---|
| 93 | MX_GPIO_Init();
|
|---|
| 94 | MX_DMA_Init();
|
|---|
| 95 | MX_ADC1_Init();
|
|---|
| 96 | MX_TIM17_Init();
|
|---|
| 97 | MX_USART1_UART_Init();
|
|---|
| 98 | MX_TIM16_Init();
|
|---|
| 99 | MX_IWDG_Init();
|
|---|
| 100 | /* USER CODE BEGIN 2 */
|
|---|
| 101 |
|
|---|
| 102 | /* USER CODE END 2 */
|
|---|
| 103 |
|
|---|
| 104 | /* Infinite loop */
|
|---|
| 105 | /* USER CODE BEGIN WHILE */
|
|---|
| 106 | while (1)
|
|---|
| 107 | {
|
|---|
| 108 | /* USER CODE END WHILE */
|
|---|
| 109 |
|
|---|
| 110 | /* USER CODE BEGIN 3 */
|
|---|
| 111 | }
|
|---|
| 112 | /* USER CODE END 3 */
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | /**
|
|---|
| 116 | * @brief System Clock Configuration
|
|---|
| 117 | * @retval None
|
|---|
| 118 | */
|
|---|
| 119 | void SystemClock_Config(void)
|
|---|
| 120 | {
|
|---|
| 121 | RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|---|
| 122 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|---|
| 123 |
|
|---|
| 124 | __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_0);
|
|---|
| 125 |
|
|---|
| 126 | /** Initializes the RCC Oscillators according to the specified parameters
|
|---|
| 127 | * in the RCC_OscInitTypeDef structure.
|
|---|
| 128 | */
|
|---|
| 129 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
|
|---|
| 130 | RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|---|
| 131 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV4;
|
|---|
| 132 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|---|
| 133 | RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
|---|
| 134 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|---|
| 135 | {
|
|---|
| 136 | Error_Handler();
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | /** Initializes the CPU, AHB and APB buses clocks
|
|---|
| 140 | */
|
|---|
| 141 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|---|
| 142 | |RCC_CLOCKTYPE_PCLK1;
|
|---|
| 143 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
|---|
| 144 | RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
|---|
| 145 | RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
|
|---|
| 146 | RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
|
|---|
| 147 |
|
|---|
| 148 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
|---|
| 149 | {
|
|---|
| 150 | Error_Handler();
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /* USER CODE BEGIN 4 */
|
|---|
| 155 |
|
|---|
| 156 | /* USER CODE END 4 */
|
|---|
| 157 |
|
|---|
| 158 | /**
|
|---|
| 159 | * @brief This function is executed in case of error occurrence.
|
|---|
| 160 | * @retval None
|
|---|
| 161 | */
|
|---|
| 162 | void Error_Handler(void)
|
|---|
| 163 | {
|
|---|
| 164 | /* USER CODE BEGIN Error_Handler_Debug */
|
|---|
| 165 | /* User can add his own implementation to report the HAL error return state */
|
|---|
| 166 | __disable_irq();
|
|---|
| 167 | while (1)
|
|---|
| 168 | {
|
|---|
| 169 | }
|
|---|
| 170 | /* USER CODE END Error_Handler_Debug */
|
|---|
| 171 | }
|
|---|
| 172 | #ifdef USE_FULL_ASSERT
|
|---|
| 173 | /**
|
|---|
| 174 | * @brief Reports the name of the source file and the source line number
|
|---|
| 175 | * where the assert_param error has occurred.
|
|---|
| 176 | * @param file: pointer to the source file name
|
|---|
| 177 | * @param line: assert_param error line source number
|
|---|
| 178 | * @retval None
|
|---|
| 179 | */
|
|---|
| 180 | void assert_failed(uint8_t *file, uint32_t line)
|
|---|
| 181 | {
|
|---|
| 182 | /* USER CODE BEGIN 6 */
|
|---|
| 183 | /* User can add his own implementation to report the file name and line number,
|
|---|
| 184 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|---|
| 185 | /* USER CODE END 6 */
|
|---|
| 186 | }
|
|---|
| 187 | #endif /* USE_FULL_ASSERT */
|
|---|