tdse-tp2_01-model_integration

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