tdse-tp3_02-code_integration

Index Commits Files Refs
Core/Src/main.c (7811B)
   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 /* Application includes. */
  26 #include "logger.h"
  27 #include "app.h"
  28 
  29 /* USER CODE END Includes */
  30 
  31 /* Private typedef -----------------------------------------------------------*/
  32 /* USER CODE BEGIN PTD */
  33 
  34 /* USER CODE END PTD */
  35 
  36 /* Private define ------------------------------------------------------------*/
  37 /* USER CODE BEGIN PD */
  38 
  39 /* USER CODE END PD */
  40 
  41 /* Private macro -------------------------------------------------------------*/
  42 /* USER CODE BEGIN PM */
  43 
  44 /* USER CODE END PM */
  45 
  46 /* Private variables ---------------------------------------------------------*/
  47 UART_HandleTypeDef huart2;
  48 
  49 /* USER CODE BEGIN PV */
  50 
  51 /* USER CODE END PV */
  52 
  53 /* Private function prototypes -----------------------------------------------*/
  54 void SystemClock_Config(void);
  55 static void MX_GPIO_Init(void);
  56 static void MX_USART2_UART_Init(void);
  57 /* USER CODE BEGIN PFP */
  58 
  59 /* USER CODE END PFP */
  60 
  61 /* Private user code ---------------------------------------------------------*/
  62 /* USER CODE BEGIN 0 */
  63 #if (1 == LOGGER_CONFIG_USE_SEMIHOSTING)
  64 
  65 extern void initialise_monitor_handles(void);
  66 
  67 #endif
  68 
  69 /* USER CODE END 0 */
  70 
  71 /**
  72   * @brief  The application entry point.
  73   * @retval int
  74   */
  75 int main(void)
  76 {
  77 
  78   /* USER CODE BEGIN 1 */
  79   #if (1 == LOGGER_CONFIG_USE_SEMIHOSTING)
  80 
  81   initialise_monitor_handles();
  82 
  83   #endif
  84 
  85   /* USER CODE END 1 */
  86 
  87   /* MCU Configuration--------------------------------------------------------*/
  88 
  89   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  90   HAL_Init();
  91 
  92   /* USER CODE BEGIN Init */
  93 
  94   /* USER CODE END Init */
  95 
  96   /* Configure the system clock */
  97   SystemClock_Config();
  98 
  99   /* USER CODE BEGIN SysInit */
 100 
 101   /* USER CODE END SysInit */
 102 
 103   /* Initialize all configured peripherals */
 104   MX_GPIO_Init();
 105   MX_USART2_UART_Init();
 106   /* USER CODE BEGIN 2 */
 107 
 108   /* Application Init */
 109   app_init();
 110 
 111   /* USER CODE END 2 */
 112 
 113   /* Infinite loop */
 114   /* USER CODE BEGIN WHILE */
 115   while (1)
 116   {
 117     /* USER CODE END WHILE */
 118 
 119     /* USER CODE BEGIN 3 */
 120 
 121     /* Application Update */
 122     app_update();
 123   }
 124   /* USER CODE END 3 */
 125 }
 126 
 127 /**
 128   * @brief System Clock Configuration
 129   * @retval None
 130   */
 131 void SystemClock_Config(void)
 132 {
 133   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 134   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 135 
 136   /** Initializes the RCC Oscillators according to the specified parameters
 137   * in the RCC_OscInitTypeDef structure.
 138   */
 139   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 140   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 141   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 142   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 143   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
 144   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
 145   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 146   {
 147     Error_Handler();
 148   }
 149 
 150   /** Initializes the CPU, AHB and APB buses clocks
 151   */
 152   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 153                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
 154   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 155   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 156   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
 157   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 158 
 159   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
 160   {
 161     Error_Handler();
 162   }
 163 }
 164 
 165 /**
 166   * @brief USART2 Initialization Function
 167   * @param None
 168   * @retval None
 169   */
 170 static void MX_USART2_UART_Init(void)
 171 {
 172 
 173   /* USER CODE BEGIN USART2_Init 0 */
 174 
 175   /* USER CODE END USART2_Init 0 */
 176 
 177   /* USER CODE BEGIN USART2_Init 1 */
 178 
 179   /* USER CODE END USART2_Init 1 */
 180   huart2.Instance = USART2;
 181   huart2.Init.BaudRate = 115200;
 182   huart2.Init.WordLength = UART_WORDLENGTH_8B;
 183   huart2.Init.StopBits = UART_STOPBITS_1;
 184   huart2.Init.Parity = UART_PARITY_NONE;
 185   huart2.Init.Mode = UART_MODE_TX_RX;
 186   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 187   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
 188   if (HAL_UART_Init(&huart2) != HAL_OK)
 189   {
 190     Error_Handler();
 191   }
 192   /* USER CODE BEGIN USART2_Init 2 */
 193 
 194   /* USER CODE END USART2_Init 2 */
 195 
 196 }
 197 
 198 /**
 199   * @brief GPIO Initialization Function
 200   * @param None
 201   * @retval None
 202   */
 203 static void MX_GPIO_Init(void)
 204 {
 205   GPIO_InitTypeDef GPIO_InitStruct = {0};
 206 /* USER CODE BEGIN MX_GPIO_Init_1 */
 207 /* USER CODE END MX_GPIO_Init_1 */
 208 
 209   /* GPIO Ports Clock Enable */
 210   __HAL_RCC_GPIOC_CLK_ENABLE();
 211   __HAL_RCC_GPIOD_CLK_ENABLE();
 212   __HAL_RCC_GPIOA_CLK_ENABLE();
 213   __HAL_RCC_GPIOB_CLK_ENABLE();
 214 
 215   /*Configure GPIO pin Output Level */
 216   HAL_GPIO_WritePin(GPIOA, LD2_Pin|D7_Pin|D8_Pin, GPIO_PIN_RESET);
 217 
 218   /*Configure GPIO pin Output Level */
 219   HAL_GPIO_WritePin(GPIOB, D6_Pin|D5_Pin|D4_Pin, GPIO_PIN_RESET);
 220 
 221   /*Configure GPIO pin Output Level */
 222   HAL_GPIO_WritePin(D9_GPIO_Port, D9_Pin, GPIO_PIN_RESET);
 223 
 224   /*Configure GPIO pin : B1_Pin */
 225   GPIO_InitStruct.Pin = B1_Pin;
 226   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
 227   GPIO_InitStruct.Pull = GPIO_NOPULL;
 228   HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
 229 
 230   /*Configure GPIO pins : LD2_Pin D7_Pin D8_Pin */
 231   GPIO_InitStruct.Pin = LD2_Pin|D7_Pin|D8_Pin;
 232   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 233   GPIO_InitStruct.Pull = GPIO_NOPULL;
 234   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 235   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 236 
 237   /*Configure GPIO pins : D6_Pin D5_Pin D4_Pin */
 238   GPIO_InitStruct.Pin = D6_Pin|D5_Pin|D4_Pin;
 239   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 240   GPIO_InitStruct.Pull = GPIO_NOPULL;
 241   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 242   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 243 
 244   /*Configure GPIO pin : D9_Pin */
 245   GPIO_InitStruct.Pin = D9_Pin;
 246   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 247   GPIO_InitStruct.Pull = GPIO_NOPULL;
 248   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 249   HAL_GPIO_Init(D9_GPIO_Port, &GPIO_InitStruct);
 250 
 251   /* EXTI interrupt init*/
 252   HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
 253   HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
 254 
 255 /* USER CODE BEGIN MX_GPIO_Init_2 */
 256 /* USER CODE END MX_GPIO_Init_2 */
 257 }
 258 
 259 /* USER CODE BEGIN 4 */
 260 
 261 /* USER CODE END 4 */
 262 
 263 /**
 264   * @brief  This function is executed in case of error occurrence.
 265   * @retval None
 266   */
 267 void Error_Handler(void)
 268 {
 269   /* USER CODE BEGIN Error_Handler_Debug */
 270   /* User can add his own implementation to report the HAL error return state */
 271   __disable_irq();
 272   while (1)
 273   {
 274   }
 275   /* USER CODE END Error_Handler_Debug */
 276 }
 277 
 278 #ifdef  USE_FULL_ASSERT
 279 /**
 280   * @brief  Reports the name of the source file and the source line number
 281   *         where the assert_param error has occurred.
 282   * @param  file: pointer to the source file name
 283   * @param  line: assert_param error line source number
 284   * @retval None
 285   */
 286 void assert_failed(uint8_t *file, uint32_t line)
 287 {
 288   /* USER CODE BEGIN 6 */
 289   /* User can add his own implementation to report the file name and line number,
 290      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 291   /* USER CODE END 6 */
 292 }
 293 #endif /* USE_FULL_ASSERT */