main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. ** This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * COPYRIGHT(c) 2018 STMicroelectronics
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* USER CODE END Header */
  40. /* Includes ------------------------------------------------------------------*/
  41. #include "main.h"
  42. /* Private includes ----------------------------------------------------------*/
  43. /* USER CODE BEGIN Includes */
  44. /* USER CODE END Includes */
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* USER CODE BEGIN PTD */
  47. /* USER CODE END PTD */
  48. /* Private define ------------------------------------------------------------*/
  49. /* USER CODE BEGIN PD */
  50. /* USER CODE END PD */
  51. /* Private macro -------------------------------------------------------------*/
  52. /* USER CODE BEGIN PM */
  53. /* USER CODE END PM */
  54. /* Private variables ---------------------------------------------------------*/
  55. ADC_HandleTypeDef hadc;
  56. IWDG_HandleTypeDef hiwdg;
  57. RTC_HandleTypeDef hrtc;
  58. SPI_HandleTypeDef hspi1;
  59. TIM_HandleTypeDef htim2;
  60. TIM_HandleTypeDef htim14;
  61. TIM_HandleTypeDef htim16;
  62. TIM_HandleTypeDef htim17;
  63. USART_HandleTypeDef husart1;
  64. UART_HandleTypeDef huart2;
  65. /* USER CODE BEGIN PV */
  66. /* Private variables ---------------------------------------------------------*/
  67. /* USER CODE END PV */
  68. /* Private function prototypes -----------------------------------------------*/
  69. void SystemClock_Config(void);
  70. static void MX_GPIO_Init(void);
  71. static void MX_USART1_Init(void);
  72. static void MX_USART2_UART_Init(void);
  73. static void MX_SPI1_Init(void);
  74. static void MX_TIM16_Init(void);
  75. static void MX_TIM17_Init(void);
  76. static void MX_TIM14_Init(void);
  77. static void MX_TIM2_Init(void);
  78. static void MX_ADC_Init(void);
  79. static void MX_RTC_Init(void);
  80. static void MX_IWDG_Init(void);
  81. /* USER CODE BEGIN PFP */
  82. /* Private function prototypes -----------------------------------------------*/
  83. /* USER CODE END PFP */
  84. /* Private user code ---------------------------------------------------------*/
  85. /* USER CODE BEGIN 0 */
  86. /* USER CODE END 0 */
  87. /**
  88. * @brief The application entry point.
  89. * @retval int
  90. */
  91. int main(void)
  92. {
  93. /* USER CODE BEGIN 1 */
  94. /* USER CODE END 1 */
  95. /* MCU Configuration--------------------------------------------------------*/
  96. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  97. HAL_Init();
  98. /* USER CODE BEGIN Init */
  99. /* USER CODE END Init */
  100. /* Configure the system clock */
  101. SystemClock_Config();
  102. /* USER CODE BEGIN SysInit */
  103. /* USER CODE END SysInit */
  104. /* Initialize all configured peripherals */
  105. MX_GPIO_Init();
  106. MX_USART1_Init();
  107. MX_USART2_UART_Init();
  108. MX_SPI1_Init();
  109. MX_TIM16_Init();
  110. MX_TIM17_Init();
  111. MX_TIM14_Init();
  112. MX_TIM2_Init();
  113. MX_ADC_Init();
  114. MX_RTC_Init();
  115. MX_IWDG_Init();
  116. /* USER CODE BEGIN 2 */
  117. /* USER CODE END 2 */
  118. /* Infinite loop */
  119. /* USER CODE BEGIN WHILE */
  120. while (1)
  121. {
  122. /* USER CODE END WHILE */
  123. /* USER CODE BEGIN 3 */
  124. }
  125. /* USER CODE END 3 */
  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. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  136. /** Configure LSE Drive Capability
  137. */
  138. HAL_PWR_EnableBkUpAccess();
  139. __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);
  140. /** Initializes the CPU, AHB and APB busses clocks
  141. */
  142. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14
  143. |RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_LSE;
  144. RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  145. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  146. RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
  147. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  148. RCC_OscInitStruct.HSI14CalibrationValue = 16;
  149. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  150. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  151. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  152. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  153. RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  154. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  155. {
  156. Error_Handler();
  157. }
  158. /** Initializes the CPU, AHB and APB busses clocks
  159. */
  160. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  161. |RCC_CLOCKTYPE_PCLK1;
  162. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  163. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  164. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  165. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  166. {
  167. Error_Handler();
  168. }
  169. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2
  170. |RCC_PERIPHCLK_RTC;
  171. PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
  172. PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  173. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  174. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  175. {
  176. Error_Handler();
  177. }
  178. }
  179. /**
  180. * @brief ADC Initialization Function
  181. * @param None
  182. * @retval None
  183. */
  184. static void MX_ADC_Init(void)
  185. {
  186. /* USER CODE BEGIN ADC_Init 0 */
  187. /* USER CODE END ADC_Init 0 */
  188. ADC_ChannelConfTypeDef sConfig = {0};
  189. /* USER CODE BEGIN ADC_Init 1 */
  190. /* USER CODE END ADC_Init 1 */
  191. /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  192. */
  193. hadc.Instance = ADC1;
  194. hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  195. hadc.Init.Resolution = ADC_RESOLUTION_12B;
  196. hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  197. hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  198. hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  199. hadc.Init.LowPowerAutoWait = DISABLE;
  200. hadc.Init.LowPowerAutoPowerOff = DISABLE;
  201. hadc.Init.ContinuousConvMode = DISABLE;
  202. hadc.Init.DiscontinuousConvMode = DISABLE;
  203. hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  204. hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  205. hadc.Init.DMAContinuousRequests = DISABLE;
  206. hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  207. if (HAL_ADC_Init(&hadc) != HAL_OK)
  208. {
  209. Error_Handler();
  210. }
  211. /** Configure for the selected ADC regular channel to be converted.
  212. */
  213. sConfig.Channel = ADC_CHANNEL_0;
  214. sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  215. sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  216. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  217. {
  218. Error_Handler();
  219. }
  220. /* USER CODE BEGIN ADC_Init 2 */
  221. /* USER CODE END ADC_Init 2 */
  222. }
  223. /**
  224. * @brief IWDG Initialization Function
  225. * @param None
  226. * @retval None
  227. */
  228. static void MX_IWDG_Init(void)
  229. {
  230. /* USER CODE BEGIN IWDG_Init 0 */
  231. /* USER CODE END IWDG_Init 0 */
  232. /* USER CODE BEGIN IWDG_Init 1 */
  233. /* USER CODE END IWDG_Init 1 */
  234. hiwdg.Instance = IWDG;
  235. hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
  236. hiwdg.Init.Window = 4095;
  237. hiwdg.Init.Reload = 4095;
  238. if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
  239. {
  240. Error_Handler();
  241. }
  242. /* USER CODE BEGIN IWDG_Init 2 */
  243. /* USER CODE END IWDG_Init 2 */
  244. }
  245. /**
  246. * @brief RTC Initialization Function
  247. * @param None
  248. * @retval None
  249. */
  250. static void MX_RTC_Init(void)
  251. {
  252. /* USER CODE BEGIN RTC_Init 0 */
  253. /* USER CODE END RTC_Init 0 */
  254. /* USER CODE BEGIN RTC_Init 1 */
  255. /* USER CODE END RTC_Init 1 */
  256. /** Initialize RTC Only
  257. */
  258. hrtc.Instance = RTC;
  259. hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  260. hrtc.Init.AsynchPrediv = 127;
  261. hrtc.Init.SynchPrediv = 255;
  262. hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  263. hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  264. hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  265. if (HAL_RTC_Init(&hrtc) != HAL_OK)
  266. {
  267. Error_Handler();
  268. }
  269. /* USER CODE BEGIN RTC_Init 2 */
  270. /* USER CODE END RTC_Init 2 */
  271. }
  272. /**
  273. * @brief SPI1 Initialization Function
  274. * @param None
  275. * @retval None
  276. */
  277. static void MX_SPI1_Init(void)
  278. {
  279. /* USER CODE BEGIN SPI1_Init 0 */
  280. /* USER CODE END SPI1_Init 0 */
  281. /* USER CODE BEGIN SPI1_Init 1 */
  282. /* USER CODE END SPI1_Init 1 */
  283. /* SPI1 parameter configuration*/
  284. hspi1.Instance = SPI1;
  285. hspi1.Init.Mode = SPI_MODE_MASTER;
  286. hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  287. hspi1.Init.DataSize = SPI_DATASIZE_4BIT;
  288. hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  289. hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  290. hspi1.Init.NSS = SPI_NSS_SOFT;
  291. hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
  292. hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  293. hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  294. hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  295. hspi1.Init.CRCPolynomial = 7;
  296. hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  297. hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  298. if (HAL_SPI_Init(&hspi1) != HAL_OK)
  299. {
  300. Error_Handler();
  301. }
  302. /* USER CODE BEGIN SPI1_Init 2 */
  303. /* USER CODE END SPI1_Init 2 */
  304. }
  305. /**
  306. * @brief TIM2 Initialization Function
  307. * @param None
  308. * @retval None
  309. */
  310. static void MX_TIM2_Init(void)
  311. {
  312. /* USER CODE BEGIN TIM2_Init 0 */
  313. /* USER CODE END TIM2_Init 0 */
  314. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  315. TIM_MasterConfigTypeDef sMasterConfig = {0};
  316. TIM_OC_InitTypeDef sConfigOC = {0};
  317. /* USER CODE BEGIN TIM2_Init 1 */
  318. /* USER CODE END TIM2_Init 1 */
  319. htim2.Instance = TIM2;
  320. htim2.Init.Prescaler = 0;
  321. htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  322. htim2.Init.Period = 0;
  323. htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  324. htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  325. if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  326. {
  327. Error_Handler();
  328. }
  329. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  330. if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  331. {
  332. Error_Handler();
  333. }
  334. if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
  335. {
  336. Error_Handler();
  337. }
  338. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  339. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  340. if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  341. {
  342. Error_Handler();
  343. }
  344. sConfigOC.OCMode = TIM_OCMODE_PWM1;
  345. sConfigOC.Pulse = 0;
  346. sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  347. sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  348. if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
  349. {
  350. Error_Handler();
  351. }
  352. /* USER CODE BEGIN TIM2_Init 2 */
  353. /* USER CODE END TIM2_Init 2 */
  354. HAL_TIM_MspPostInit(&htim2);
  355. }
  356. /**
  357. * @brief TIM14 Initialization Function
  358. * @param None
  359. * @retval None
  360. */
  361. static void MX_TIM14_Init(void)
  362. {
  363. /* USER CODE BEGIN TIM14_Init 0 */
  364. /* USER CODE END TIM14_Init 0 */
  365. /* USER CODE BEGIN TIM14_Init 1 */
  366. /* USER CODE END TIM14_Init 1 */
  367. htim14.Instance = TIM14;
  368. htim14.Init.Prescaler = 0;
  369. htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
  370. htim14.Init.Period = 0;
  371. htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  372. htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  373. if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
  374. {
  375. Error_Handler();
  376. }
  377. /* USER CODE BEGIN TIM14_Init 2 */
  378. /* USER CODE END TIM14_Init 2 */
  379. }
  380. /**
  381. * @brief TIM16 Initialization Function
  382. * @param None
  383. * @retval None
  384. */
  385. static void MX_TIM16_Init(void)
  386. {
  387. /* USER CODE BEGIN TIM16_Init 0 */
  388. /* USER CODE END TIM16_Init 0 */
  389. /* USER CODE BEGIN TIM16_Init 1 */
  390. /* USER CODE END TIM16_Init 1 */
  391. htim16.Instance = TIM16;
  392. htim16.Init.Prescaler = 0;
  393. htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
  394. htim16.Init.Period = 0;
  395. htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  396. htim16.Init.RepetitionCounter = 0;
  397. htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  398. if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
  399. {
  400. Error_Handler();
  401. }
  402. /* USER CODE BEGIN TIM16_Init 2 */
  403. /* USER CODE END TIM16_Init 2 */
  404. }
  405. /**
  406. * @brief TIM17 Initialization Function
  407. * @param None
  408. * @retval None
  409. */
  410. static void MX_TIM17_Init(void)
  411. {
  412. /* USER CODE BEGIN TIM17_Init 0 */
  413. /* USER CODE END TIM17_Init 0 */
  414. /* USER CODE BEGIN TIM17_Init 1 */
  415. /* USER CODE END TIM17_Init 1 */
  416. htim17.Instance = TIM17;
  417. htim17.Init.Prescaler = 0;
  418. htim17.Init.CounterMode = TIM_COUNTERMODE_UP;
  419. htim17.Init.Period = 0;
  420. htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  421. htim17.Init.RepetitionCounter = 0;
  422. htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  423. if (HAL_TIM_Base_Init(&htim17) != HAL_OK)
  424. {
  425. Error_Handler();
  426. }
  427. /* USER CODE BEGIN TIM17_Init 2 */
  428. /* USER CODE END TIM17_Init 2 */
  429. }
  430. /**
  431. * @brief USART1 Initialization Function
  432. * @param None
  433. * @retval None
  434. */
  435. static void MX_USART1_Init(void)
  436. {
  437. /* USER CODE BEGIN USART1_Init 0 */
  438. /* USER CODE END USART1_Init 0 */
  439. /* USER CODE BEGIN USART1_Init 1 */
  440. /* USER CODE END USART1_Init 1 */
  441. husart1.Instance = USART1;
  442. husart1.Init.BaudRate = 115200;
  443. husart1.Init.WordLength = USART_WORDLENGTH_8B;
  444. husart1.Init.StopBits = USART_STOPBITS_1;
  445. husart1.Init.Parity = USART_PARITY_NONE;
  446. husart1.Init.Mode = USART_MODE_TX_RX;
  447. husart1.Init.CLKPolarity = USART_POLARITY_LOW;
  448. husart1.Init.CLKPhase = USART_PHASE_1EDGE;
  449. husart1.Init.CLKLastBit = USART_LASTBIT_DISABLE;
  450. if (HAL_USART_Init(&husart1) != HAL_OK)
  451. {
  452. Error_Handler();
  453. }
  454. /* USER CODE BEGIN USART1_Init 2 */
  455. /* USER CODE END USART1_Init 2 */
  456. }
  457. /**
  458. * @brief USART2 Initialization Function
  459. * @param None
  460. * @retval None
  461. */
  462. static void MX_USART2_UART_Init(void)
  463. {
  464. /* USER CODE BEGIN USART2_Init 0 */
  465. /* USER CODE END USART2_Init 0 */
  466. /* USER CODE BEGIN USART2_Init 1 */
  467. /* USER CODE END USART2_Init 1 */
  468. huart2.Instance = USART2;
  469. huart2.Init.BaudRate = 115200;
  470. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  471. huart2.Init.StopBits = UART_STOPBITS_1;
  472. huart2.Init.Parity = UART_PARITY_NONE;
  473. huart2.Init.Mode = UART_MODE_TX_RX;
  474. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  475. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  476. huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  477. huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  478. if (HAL_UART_Init(&huart2) != HAL_OK)
  479. {
  480. Error_Handler();
  481. }
  482. /* USER CODE BEGIN USART2_Init 2 */
  483. /* USER CODE END USART2_Init 2 */
  484. }
  485. /**
  486. * @brief GPIO Initialization Function
  487. * @param None
  488. * @retval None
  489. */
  490. static void MX_GPIO_Init(void)
  491. {
  492. /* GPIO Ports Clock Enable */
  493. __HAL_RCC_GPIOC_CLK_ENABLE();
  494. __HAL_RCC_GPIOA_CLK_ENABLE();
  495. __HAL_RCC_GPIOB_CLK_ENABLE();
  496. }
  497. /* USER CODE BEGIN 4 */
  498. /* USER CODE END 4 */
  499. /**
  500. * @brief This function is executed in case of error occurrence.
  501. * @retval None
  502. */
  503. void Error_Handler(void)
  504. {
  505. /* USER CODE BEGIN Error_Handler_Debug */
  506. /* User can add his own implementation to report the HAL error return state */
  507. while(1)
  508. {
  509. }
  510. /* USER CODE END Error_Handler_Debug */
  511. }
  512. #ifdef USE_FULL_ASSERT
  513. /**
  514. * @brief Reports the name of the source file and the source line number
  515. * where the assert_param error has occurred.
  516. * @param file: pointer to the source file name
  517. * @param line: assert_param error line source number
  518. * @retval None
  519. */
  520. void assert_failed(char *file, uint32_t line)
  521. {
  522. /* USER CODE BEGIN 6 */
  523. /* User can add his own implementation to report the file name and line number,
  524. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  525. /* USER CODE END 6 */
  526. }
  527. #endif /* USE_FULL_ASSERT */
  528. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/